Skip to content
Snippets Groups Projects
Commit d6b97a28 authored by Lars Seipel's avatar Lars Seipel
Browse files

initial import

parents
Branches main
No related tags found
No related merge requests found
Pipeline #227810 passed
stages:
- build
- release
include:
- component: $CI_SERVER_FQDN/its/templates-and-utilities/gitlab-ci-components/build-container-image/build-container-image@1
inputs:
containerfile: $CI_PROJECT_DIR/Dockerfile
context: $CI_PROJECT_DIR
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
- component: $CI_SERVER_FQDN/its/templates-and-utilities/gitlab-ci-components/tag-container-image/tag-container-image@1
inputs:
job-stage: release
image: $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
tag: latest
build-container-image:
rules:
- if: $CI_COMMIT_BRANCH
tag-container-image:
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
ARG goversion=1.23
FROM docker.io/golang:$goversion as build
WORKDIR /build
COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download
COPY . ./
RUN CGO_ENABLED=0 go build -o a.out
FROM gcr.io/distroless/static:nonroot
COPY --from=build /build/a.out /a.out
ENTRYPOINT ["/a.out"]
go.mod 0 → 100644
module code.fbi.h-da.de/hdacloud/caddy-authorize-domain
go 1.23.0
require (
github.com/miekg/dns v1.1.62
go.uber.org/zap v1.27.0
)
require (
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/tools v0.22.0 // indirect
)
main.go 0 → 100644
package main
import (
"flag"
"fmt"
"net/http"
"os"
"strings"
"github.com/miekg/dns"
"go.uber.org/zap"
)
var listenAddr = flag.String("listen-addr",
getEnvDefault("LISTEN_ADDR", ":8080"),
"local address for serving HTTP (`host:port`)")
func main() {
flag.Parse()
logger, err := zap.NewProduction()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
log := logger.Sugar()
mux := http.NewServeMux()
mux.HandleFunc("GET /twm/ask", func(w http.ResponseWriter, r *http.Request) {
log := log.With(
zap.String("remote_addr", r.RemoteAddr),
zap.String("request_method", r.Method),
zap.String("request_path", r.URL.Path),
zap.String("request_url", r.URL.String()),
zap.String("xff", r.Header.Get("X-Forwarded-For")),
)
domain := r.FormValue("domain")
log.Info("handle request", "domain", domain)
// We don't want to tie down names to a specific h-da.cloud
// project, so accept everything beneath users.h-da.cloud.
if dns.IsSubDomain("users.h-da.cloud.", strings.TrimSuffix(domain, ".")+".") {
w.WriteHeader(204)
}
// Deny everything else
w.WriteHeader(403)
})
// For readiness/liveliness indication
readyz := func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(200)
}
livez := readyz
mux.HandleFunc("GET /readyz", readyz)
mux.HandleFunc("GET /livez", livez)
log.Fatal(
http.ListenAndServe(*listenAddr, mux),
)
}
func getEnvDefault(k, def string) string {
if v := os.Getenv(k); v != "" {
return v
}
return def
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment