5 Commits

Author SHA1 Message Date
d1dc57f15a convert rollout to deployment
Some checks failed
Gitea Actions Demo / lint (push) Failing after 23m56s
Gitea Actions Demo / test (push) Has been cancelled
Gitea Actions Demo / release-image (push) Has been cancelled
2025-02-06 23:24:36 -06:00
631c2bdcf3 add metadata.name to Kustomization
Some checks failed
Gitea Actions Demo / lint (push) Successful in 3m11s
Gitea Actions Demo / test (push) Successful in 2m16s
Gitea Actions Demo / release-image (push) Failing after 12m6s
2025-01-28 01:19:02 -06:00
059ed64805 Use the new json() helper
All checks were successful
Gitea Actions Demo / lint (push) Successful in 1m26s
Gitea Actions Demo / test (push) Successful in 1m19s
Gitea Actions Demo / release-image (push) Successful in 1m6s
2024-09-04 17:07:52 -05:00
6f4b7335f8 Add HTTP basic authentication endpoint
All checks were successful
Gitea Actions Demo / lint (push) Successful in 1m32s
Gitea Actions Demo / test (push) Successful in 1m18s
Gitea Actions Demo / release-image (push) Successful in 1m7s
2024-09-04 15:24:12 -05:00
9f222725d1 Add json() helper 2024-09-04 15:23:53 -05:00
4 changed files with 58 additions and 23 deletions

61
app.rb
View File

@ -1,6 +1,5 @@
require "bundler/setup" require "bundler/setup"
require "sinatra" require "sinatra"
require "sinatra/json"
require "sinatra/cookies" require "sinatra/cookies"
require "sinatra/multi_route" require "sinatra/multi_route"
require "time" require "time"
@ -209,23 +208,50 @@ before do
request.session_options[:skip] = !request.path_info.start_with?("/session") request.session_options[:skip] = !request.path_info.start_with?("/session")
end end
helpers do
def json(obj, opts: nil, pretty: false)
if pretty
JSON.pretty_generate obj, opts:
else
JSON.generate(obj, opts:)
end
end
def protected! hidden = false
return if authorized?
if hidden
halt 404, "Not Found"
else
headers["WWW-Authenticate"] = 'Basic realm="Restricted Area"'
halt 401, "Unauthorized"
end
end
def authorized?
@auth ||= Rack::Auth::Basic::Request.new(request.env)
@auth.provided? and
@auth.basic? and
@auth.credentials and
@auth.credentials == ["qwer", "asdf"]
end
end
get "/" do get "/" do
"hello there!\n" "hello there!\n"
end end
get "/env", provides: "json" do get "/env", provides: "json" do
content_type :json pretty = params.key? :pretty
return JSON.pretty_generate ENV.sort.to_h if params.key? "pretty" json ENV.sort.to_h, pretty:
JSON.generate ENV.sort.to_h
end end
get "/headers", provides: "json" do get "/headers", provides: "json" do
pretty = params.key? :pretty
h = req_headers h = req_headers
return JSON.pretty_generate h if params.key? "pretty"
JSON.generate h json h, pretty:
end end
get "/livez" do get "/livez" do
@ -239,6 +265,7 @@ end
get "/livez/uptime" do get "/livez/uptime" do
tt = TickTock.new tt = TickTock.new
x = {started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i)} x = {started_at: tt.started_at, seconds: tt.uptime.to_i, human: human_time(tt.uptime.to_i)}
json x json x
end end
@ -301,7 +328,9 @@ post "/halt" do
end end
get "/pid" do get "/pid" do
JSON.generate({puma: master_pid, pid: Process.pid}) pretty = params.key? :pretty
json({puma: master_pid, pid: Process.pid}, pretty:)
end end
get "/token" do get "/token" do
@ -310,23 +339,27 @@ get "/token" do
expires_at = Time.at(exp).to_datetime expires_at = Time.at(exp).to_datetime
token = JWT.encode payload, JWT_SECRET, "HS256" token = JWT.encode payload, JWT_SECRET, "HS256"
x = {token: token, expires_at: expires_at} x = {token: token, expires_at: expires_at}
json x json x
end end
get "/token/validate" do get "/token/validate" do
token = req_headers["authorization"].split[1] token = req_headers["authorization"].split[1]
payload = JWT.decode token, JWT_SECRET, true, algorithm: "HS256" payload = JWT.decode token, JWT_SECRET, true, algorithm: "HS256"
json payload json payload
end end
post "/session" do post "/session" do
session.merge! params session.merge! params
json session.to_hash json session.to_hash
end end
get "/session" do get "/session" do
j = session.to_hash j = session.to_hash
j[:hostname] = ENV["HOSTNAME"] j[:hostname] = ENV["HOSTNAME"]
json j json j
end end
@ -372,3 +405,15 @@ get "/chunked/:delay" do
out << "Hello, world!\n" out << "Hello, world!\n"
end end
end end
route :delete, :get, :patch, :post, :put, "/auth/basic", provides: "json" do
pretty = params.key? :pretty
if params.key? :hidden
protected! hidden: true
else
protected!
end
json({authenticated: true, user: @auth.username}, pretty:)
end

View File

@ -1,24 +1,12 @@
--- ---
apiVersion: argoproj.io/v1alpha1 apiVersion: v1
kind: Rollout kind: Service
metadata: metadata:
name: kipunji name: kipunji
annotations: annotations:
reloader.stakater.com/auto: "true" reloader.stakater.com/auto: "true"
spec: spec:
replicas: 5 replicas: 5
strategy:
canary:
steps:
- setWeight: 20
- pause: {}
- setWeight: 40
- pause: {duration: 10}
- setWeight: 60
- pause: {duration: 10}
- setWeight: 80
- pause: {duration: 10}
revisionHistoryLimit: 2
selector: selector:
matchLabels: matchLabels:
app: kipunji app: kipunji

View File

@ -5,6 +5,6 @@ namespace: kipunji
resources: resources:
- secret.yaml - secret.yaml
- configmap.yaml - configmap.yaml
- rollout.yaml - deployment.yaml
- services.yaml - services.yaml
- ingress.yaml - ingress.yaml

View File

@ -1,6 +1,8 @@
--- ---
apiVersion: kustomize.config.k8s.io/v1beta1 apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization kind: Kustomization
metadata:
name: kipunji
namespace: kipunji namespace: kipunji
resources: resources:
- namespace.yaml - namespace.yaml