From 8d04d2d0dc083348c28d98d27db6fedef4f5f9ac Mon Sep 17 00:00:00 2001 From: Iggy Jackson Date: Sat, 18 May 2024 08:59:06 -0700 Subject: [PATCH] move pkg indexing to separate function/endponit --- .hadolint.yaml | 1 + Dockerfile | 18 +-- cmd/api/main.go | 10 +- go.mod | 38 +++--- go.sum | 78 ++++++++--- internal/openapi/api.gen.go | 255 +++++++++++++++++++++++++++++++---- internal/openapi/fs.go | 3 +- internal/openapi/packages.go | 23 +++- openapi/packages.yaml | 61 ++++++++- 9 files changed, 405 insertions(+), 82 deletions(-) diff --git a/.hadolint.yaml b/.hadolint.yaml index a00e8ac..d6fa0ce 100644 --- a/.hadolint.yaml +++ b/.hadolint.yaml @@ -5,3 +5,4 @@ ignored: # specific version is just a recipe for having to constantly update # the versions in your Dockerfile - DL3018 + - DL3059 diff --git a/Dockerfile b/Dockerfile index de87379..4a9b84d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,17 @@ -FROM golang:alpine AS builder +FROM --platform=$BUILDPLATFORM golang:alpine AS builder WORKDIR /app # go build needs git to be installed RUN apk add --no-cache git -# copy just the go mod file and download mods so we can hopefully get some docker layer caching benefits -COPY ./go.* /app/ -RUN ["go", "mod", "download"] - COPY ./ /app/ -ENV CGO_ENABLED=0 -RUN go build -ldflags="-extldflags=-static" ./cmd/api/ -# RUN ["find", "."] +ARG TARGETARCH +ARG TARGETOS +RUN ["go", "mod", "download"] +RUN ["go", "mod", "tidy"] +RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \ + go build -ldflags="-s -w" ./cmd/api # we need edge because we built packages for edge FROM alpine:edge @@ -26,9 +25,6 @@ EXPOSE 8888 HEALTHCHECK --interval=5m --timeout=10s \ CMD curl -fs localhost:8888/health/ready -# the service internally calls abuild to create the package index -RUN ["apk", "add", "--no-cache", "abuild"] - COPY --from=builder /app/api /app/ USER 1000:1000 diff --git a/cmd/api/main.go b/cmd/api/main.go index bddc90d..30d1fa0 100644 --- a/cmd/api/main.go +++ b/cmd/api/main.go @@ -14,11 +14,13 @@ import ( "github.com/labstack/echo-contrib/prometheus" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" - "github.com/oapi-codegen/echo-middleware" + echomiddleware "github.com/oapi-codegen/echo-middleware" ) func main() { var port = flag.Int("port", 8888, "Port for HTTP server") + var dir = flag.String("dir", "/srv/packages", "Root directory for packages/config") + flag.Parse() swagger, err := repoApi.GetSwagger() @@ -32,7 +34,7 @@ func main() { swagger.Servers = nil // Create an instance of our handler which satisfies the generated interface - papi := repoApi.NewPkgRepo() + papi := repoApi.NewPkgRepo(*dir) // This is how you set up a basic Echo router e := echo.New() @@ -53,7 +55,9 @@ func main() { validatorOptions.Options.AuthenticationFunc = func(ctx context.Context, input *openapi3filter.AuthenticationInput) error { orgName := input.RequestValidationInput.PathParams["org"] validTokens := repoApi.GetValidTokens(orgName) - if input.RequestValidationInput.Request.Header.Get("Authorization") == "" { + // they probably forgot to set the auth header or the env var for the token + if input.RequestValidationInput.Request.Header.Get("Authorization") == "" || + input.RequestValidationInput.Request.Header["Authorization"][0] == "Bearer" { return errors.New("no auth token") } token := strings.Split(input.RequestValidationInput.Request.Header["Authorization"][0], " ")[1] diff --git a/go.mod b/go.mod index a97cc4b..bb9b83a 100644 --- a/go.mod +++ b/go.mod @@ -5,13 +5,14 @@ go 1.21 // replace gitlab.alpinelinux.org/alpine/go => /home/iggy/projects/gitlab.alpinelinux.org/iggy/go require ( - github.com/getkin/kin-openapi v0.123.0 - github.com/labstack/echo-contrib v0.16.0 - github.com/labstack/echo/v4 v4.11.4 + github.com/deepmap/oapi-codegen v1.16.2 + github.com/getkin/kin-openapi v0.124.0 + github.com/labstack/echo-contrib v0.17.1 + github.com/labstack/echo/v4 v4.12.0 github.com/oapi-codegen/echo-middleware v1.0.1 github.com/oapi-codegen/runtime v1.1.1 github.com/rs/zerolog v1.32.0 - github.com/viant/afs v1.25.0 + github.com/viant/afs v1.25.1 gitlab.alpinelinux.org/alpine/go v0.10.0 ) @@ -19,14 +20,14 @@ require ( github.com/MakeNowJust/heredoc/v2 v2.0.1 // indirect github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect github.com/beorn7/perks v1.0.1 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/go-errors/errors v1.5.1 // indirect - github.com/go-openapi/jsonpointer v0.20.2 // indirect - github.com/go-openapi/swag v0.22.9 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/swag v0.23.0 // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/mux v1.8.1 // indirect - github.com/invopop/yaml v0.2.0 // indirect + github.com/invopop/yaml v0.3.1 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/labstack/gommon v0.4.2 // indirect github.com/mailru/easyjson v0.7.7 // indirect @@ -36,20 +37,23 @@ require ( github.com/perimeterx/marshmallow v1.1.5 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - github.com/prometheus/client_golang v1.19.0 // indirect - github.com/prometheus/client_model v0.6.0 // indirect - github.com/prometheus/common v0.50.0 // indirect - github.com/prometheus/procfs v0.13.0 // indirect + github.com/prometheus/client_golang v1.19.1 // indirect + github.com/prometheus/client_model v0.6.1 // indirect + github.com/prometheus/common v0.53.0 // indirect + github.com/prometheus/procfs v0.15.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/net v0.22.0 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/crypto v0.23.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/term v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect golang.org/x/time v0.5.0 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + mvdan.cc/sh/v3 v3.8.0 // indirect ) // replace gitlab.alpinelinux.org/alpine/go => gitlab.alpinelinux.org/abemedia/go v0.8.1-0.20231202003941-ea851dc19408 diff --git a/go.sum b/go.sum index 50f9dee..95e1823 100644 --- a/go.sum +++ b/go.sum @@ -6,20 +6,26 @@ github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= +github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= +github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/getkin/kin-openapi v0.123.0 h1:zIik0mRwFNLyvtXK274Q6ut+dPh6nlxBp0x7mNrPhs8= -github.com/getkin/kin-openapi v0.123.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= +github.com/deepmap/oapi-codegen v1.16.2 h1:xGHx0dNqYfy9gE8a7AVgVM8Sd5oF9SEgePzP+UPAUXI= +github.com/deepmap/oapi-codegen v1.16.2/go.mod h1:rdYoEA2GE+riuZ91DvpmBX9hJbQpuY9wchXpfQ3n+ho= +github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8= +github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/getkin/kin-openapi v0.124.0 h1:VSFNMB9C9rTKBnQ/fpyDU8ytMTr4dWI9QovSKj9kz/M= +github.com/getkin/kin-openapi v0.124.0/go.mod h1:wb1aSZA/iWmorQP9KTAS/phLj/t17B5jT7+fS8ed9NM= github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk= github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= -github.com/go-openapi/jsonpointer v0.20.2 h1:mQc3nmndL8ZBzStEo3JYF8wzmeWffDH4VbXz58sAx6Q= -github.com/go-openapi/jsonpointer v0.20.2/go.mod h1:bHen+N0u1KEO3YlmqOjTT9Adn1RfD91Ar825/PuiRVs= -github.com/go-openapi/swag v0.22.9 h1:XX2DssF+mQKM2DHsbgZK74y/zj4mo9I99+89xUmuZCE= -github.com/go-openapi/swag v0.22.9/go.mod h1:3/OXnFfnMAwBD099SwYRk7GD3xOrr1iL7d/XNLXVVwE= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM= github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -33,6 +39,8 @@ github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= github.com/gorilla/mux v1.8.1/go.mod h1:AKf9I4AEqPTmMytcMc0KkNouC66V3BtZ4qD5fmWSiMQ= github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY= github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q= +github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso= +github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/juju/gnuflag v0.0.0-20171113085948-2ce1bb71843d/go.mod h1:2PavIy+JPciBPrBUjwbNvtwB6RQlve+hkpll6QSNmOE= @@ -42,8 +50,12 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/labstack/echo-contrib v0.16.0 h1:vk5Kd+egpTOJxD3l+3IvZzQWPbrXiYxhkkgkJL99j/w= github.com/labstack/echo-contrib v0.16.0/go.mod h1:mjX5VB3OqJcroIEycptBOY9Hr7rK+unq79W8QFKGNV0= +github.com/labstack/echo-contrib v0.17.1 h1:7I/he7ylVKsDUieaGRZ9XxxTYOjfQwVzHzUYrNykfCU= +github.com/labstack/echo-contrib v0.17.1/go.mod h1:SnsCZtwHBAZm5uBSAtQtXQHI3wqEA73hvTn0bYMKnZA= github.com/labstack/echo/v4 v4.11.4 h1:vDZmA+qNeh1pd/cCkEicDMrjtrnMGQ1QFI9gWN1zGq8= github.com/labstack/echo/v4 v4.11.4/go.mod h1:noh7EvLwqDsmh/X/HWKPUl1AjzJrhyptRyEbQJfxen8= +github.com/labstack/echo/v4 v4.12.0 h1:IKpw49IMryVB2p1a4dzwlhP1O2Tf2E0Ir/450lH+kI0= +github.com/labstack/echo/v4 v4.12.0/go.mod h1:UP9Cr2DJXbOK3Kr9ONYzNowSh7HP0aG0ShAyycHSJvM= github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0= github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -69,12 +81,18 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_golang v1.19.0 h1:ygXvpU1AoN1MhdzckN+PyD9QJOSD4x7kmXYlnfbA6JU= github.com/prometheus/client_golang v1.19.0/go.mod h1:ZRM9uEAypZakd+q/x7+gmsvXdURP+DABIEIjnmDdp+k= -github.com/prometheus/client_model v0.6.0 h1:k1v3CzpSRUTrKMppY35TLwPvxHqBu0bYgxZzqGIgaos= -github.com/prometheus/client_model v0.6.0/go.mod h1:NTQHnmxFpouOD0DpvP4XujX3CdOAGQPoaGhyTchlyt8= -github.com/prometheus/common v0.50.0 h1:YSZE6aa9+luNa2da6/Tik0q0A5AbR+U003TItK57CPQ= -github.com/prometheus/common v0.50.0/go.mod h1:wHFBCEVWVmHMUpg7pYcOm2QUR/ocQdYSJVQJKnHc3xQ= +github.com/prometheus/client_golang v1.19.1 h1:wZWJDwK+NameRJuPGDhlnFgx8e8HN3XHQeLaYJFJBOE= +github.com/prometheus/client_golang v1.19.1/go.mod h1:mP78NwGzrVks5S2H6ab8+ZZGJLZUq1hoULYBAYBw1Ho= +github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= +github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= +github.com/prometheus/common v0.52.2 h1:LW8Vk7BccEdONfrJBDffQGRtpSzi5CQaRZGtboOO2ck= +github.com/prometheus/common v0.52.2/go.mod h1:lrWtQx+iDfn2mbH5GUzlH9TSHyfZpHkSiG1W7y3sF2Q= +github.com/prometheus/common v0.53.0 h1:U2pL9w9nmJwJDa4qqLQ3ZaePJ6ZTwt7cMD3AG3+aLCE= +github.com/prometheus/common v0.53.0/go.mod h1:BrxBKv3FWBIGXw89Mg1AeBq7FSyRzXWI3l3e7W3RN5U= github.com/prometheus/procfs v0.13.0 h1:GqzLlQyfsPbaEHaQkO7tbDlriv/4o5Hudv6OXHGKX7o= github.com/prometheus/procfs v0.13.0/go.mod h1:cd4PFCR54QLnGKPaKGA6l+cfuNXtht43ZKY6tow0Y1g= +github.com/prometheus/procfs v0.15.0 h1:A82kmvXJq2jTu5YUhSGNlYoxh85zLnKgPz4bMZgI5Ek= +github.com/prometheus/procfs v0.15.0/go.mod h1:Y0RJ/Y5g5wJpkTisOtqwDSo4HwhGmLB4VQSw2sQJLHk= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= @@ -93,25 +111,43 @@ github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQ github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ= github.com/viant/afs v1.25.0 h1:5N/gGht4clZck42MBcCkzWTmENfG1xGnoMJ4sfXTrhI= github.com/viant/afs v1.25.0/go.mod h1:bo/jkTH8sBUhG0PQcPsuskvjb/5uEzgiwygGwtaDw8Q= +github.com/viant/afs v1.25.1 h1:IPcqwzsPUaWqsSkQXoM1vXwQuRI6u7ZgqQHKQZ8Wxyg= +github.com/viant/afs v1.25.1/go.mod h1:rScbFd9LJPGTM8HOI8Kjwee0AZ+MZMupAvFpPg+Qdj4= gitlab.alpinelinux.org/alpine/go v0.10.0 h1:/ekBiNqDSXZpK+AfZx4lrtVwKTDrWz3N3ck0S+fCxwU= gitlab.alpinelinux.org/alpine/go v0.10.0/go.mod h1:LKzOqYjGTZNLwcHl+c2I5VNioQio7agzRFvlGB9Owk4= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= +golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.18.0 h1:FcHjZXDMxI8mM3nwhX9HlKop4C0YQvCVCdwYl2wOtE8= -golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q= +golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk= +golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw= +golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= @@ -120,3 +156,5 @@ gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +mvdan.cc/sh/v3 v3.8.0 h1:ZxuJipLZwr/HLbASonmXtcvvC9HXY9d2lXZHnKGjFc8= +mvdan.cc/sh/v3 v3.8.0/go.mod h1:w04623xkgBVo7/IUK89E0g8hBykgEpN0vgOj3RJr6MY= diff --git a/internal/openapi/api.gen.go b/internal/openapi/api.gen.go index 1e82938..b12d703 100644 --- a/internal/openapi/api.gen.go +++ b/internal/openapi/api.gen.go @@ -38,6 +38,12 @@ type Error struct { Message string `json:"message"` } +// GenerateIndex defines model for GenerateIndex. +type GenerateIndex struct { + // Status package index success status + Status bool `json:"status"` +} + // NewRepo defines model for NewRepo. type NewRepo struct { // Description Description of the repo to add - not functional - just for ease of use @@ -201,6 +207,9 @@ type ClientInterface interface { // ListArches request ListArches(ctx context.Context, org string, distro string, version string, repo string, reqEditors ...RequestEditorFn) (*http.Response, error) + // CreatePackageIndex request + CreatePackageIndex(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*http.Response, error) + // ListPackagesByRepo request ListPackagesByRepo(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*http.Response, error) @@ -364,6 +373,18 @@ func (c *Client) ListArches(ctx context.Context, org string, distro string, vers return c.Client.Do(req) } +func (c *Client) CreatePackageIndex(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*http.Response, error) { + req, err := NewCreatePackageIndexRequest(c.Server, org, distro, version, repo, arch) + if err != nil { + return nil, err + } + req = req.WithContext(ctx) + if err := c.applyEditors(ctx, req, reqEditors); err != nil { + return nil, err + } + return c.Client.Do(req) +} + func (c *Client) ListPackagesByRepo(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*http.Response, error) { req, err := NewListPackagesByRepoRequest(c.Server, org, distro, version, repo, arch) if err != nil { @@ -851,6 +872,68 @@ func NewListArchesRequest(server string, org string, distro string, version stri return req, nil } +// NewCreatePackageIndexRequest generates requests for CreatePackageIndex +func NewCreatePackageIndexRequest(server string, org string, distro string, version string, repo string, arch string) (*http.Request, error) { + var err error + + var pathParam0 string + + pathParam0, err = runtime.StyleParamWithLocation("simple", false, "org", runtime.ParamLocationPath, org) + if err != nil { + return nil, err + } + + var pathParam1 string + + pathParam1, err = runtime.StyleParamWithLocation("simple", false, "distro", runtime.ParamLocationPath, distro) + if err != nil { + return nil, err + } + + var pathParam2 string + + pathParam2, err = runtime.StyleParamWithLocation("simple", false, "version", runtime.ParamLocationPath, version) + if err != nil { + return nil, err + } + + var pathParam3 string + + pathParam3, err = runtime.StyleParamWithLocation("simple", false, "repo", runtime.ParamLocationPath, repo) + if err != nil { + return nil, err + } + + var pathParam4 string + + pathParam4, err = runtime.StyleParamWithLocation("simple", false, "arch", runtime.ParamLocationPath, arch) + if err != nil { + return nil, err + } + + serverURL, err := url.Parse(server) + if err != nil { + return nil, err + } + + operationPath := fmt.Sprintf("/%s/%s/%s/%s/%s/index", pathParam0, pathParam1, pathParam2, pathParam3, pathParam4) + if operationPath[0] == '/' { + operationPath = "." + operationPath + } + + queryURL, err := serverURL.Parse(operationPath) + if err != nil { + return nil, err + } + + req, err := http.NewRequest("POST", queryURL.String(), nil) + if err != nil { + return nil, err + } + + return req, nil +} + // NewListPackagesByRepoRequest generates requests for ListPackagesByRepo func NewListPackagesByRepoRequest(server string, org string, distro string, version string, repo string, arch string) (*http.Request, error) { var err error @@ -1058,6 +1141,9 @@ type ClientWithResponsesInterface interface { // ListArchesWithResponse request ListArchesWithResponse(ctx context.Context, org string, distro string, version string, repo string, reqEditors ...RequestEditorFn) (*ListArchesResponse, error) + // CreatePackageIndexWithResponse request + CreatePackageIndexWithResponse(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*CreatePackageIndexResponse, error) + // ListPackagesByRepoWithResponse request ListPackagesByRepoWithResponse(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*ListPackagesByRepoResponse, error) @@ -1334,6 +1420,29 @@ func (r ListArchesResponse) StatusCode() int { return 0 } +type CreatePackageIndexResponse struct { + Body []byte + HTTPResponse *http.Response + JSON200 *map[string]interface{} + JSONDefault *Error +} + +// Status returns HTTPResponse.Status +func (r CreatePackageIndexResponse) Status() string { + if r.HTTPResponse != nil { + return r.HTTPResponse.Status + } + return http.StatusText(0) +} + +// StatusCode returns HTTPResponse.StatusCode +func (r CreatePackageIndexResponse) StatusCode() int { + if r.HTTPResponse != nil { + return r.HTTPResponse.StatusCode + } + return 0 +} + type ListPackagesByRepoResponse struct { Body []byte HTTPResponse *http.Response @@ -1496,6 +1605,15 @@ func (c *ClientWithResponses) ListArchesWithResponse(ctx context.Context, org st return ParseListArchesResponse(rsp) } +// CreatePackageIndexWithResponse request returning *CreatePackageIndexResponse +func (c *ClientWithResponses) CreatePackageIndexWithResponse(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*CreatePackageIndexResponse, error) { + rsp, err := c.CreatePackageIndex(ctx, org, distro, version, repo, arch, reqEditors...) + if err != nil { + return nil, err + } + return ParseCreatePackageIndexResponse(rsp) +} + // ListPackagesByRepoWithResponse request returning *ListPackagesByRepoResponse func (c *ClientWithResponses) ListPackagesByRepoWithResponse(ctx context.Context, org string, distro string, version string, repo string, arch string, reqEditors ...RequestEditorFn) (*ListPackagesByRepoResponse, error) { rsp, err := c.ListPackagesByRepo(ctx, org, distro, version, repo, arch, reqEditors...) @@ -1852,6 +1970,39 @@ func ParseListArchesResponse(rsp *http.Response) (*ListArchesResponse, error) { return response, nil } +// ParseCreatePackageIndexResponse parses an HTTP response from a CreatePackageIndexWithResponse call +func ParseCreatePackageIndexResponse(rsp *http.Response) (*CreatePackageIndexResponse, error) { + bodyBytes, err := io.ReadAll(rsp.Body) + defer func() { _ = rsp.Body.Close() }() + if err != nil { + return nil, err + } + + response := &CreatePackageIndexResponse{ + Body: bodyBytes, + HTTPResponse: rsp, + } + + switch { + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && rsp.StatusCode == 200: + var dest map[string]interface{} + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSON200 = &dest + + case strings.Contains(rsp.Header.Get("Content-Type"), "json") && true: + var dest Error + if err := json.Unmarshal(bodyBytes, &dest); err != nil { + return nil, err + } + response.JSONDefault = &dest + + } + + return response, nil +} + // ParseListPackagesByRepoResponse parses an HTTP response from a ListPackagesByRepoWithResponse call func ParseListPackagesByRepoResponse(rsp *http.Response) (*ListPackagesByRepoResponse, error) { bodyBytes, err := io.ReadAll(rsp.Body) @@ -1957,6 +2108,9 @@ type ServerInterface interface { // (GET /{org}/{distro}/{version}/{repo}/architectures) ListArches(ctx echo.Context, org string, distro string, version string, repo string) error + // (POST /{org}/{distro}/{version}/{repo}/{arch}/index) + CreatePackageIndex(ctx echo.Context, org string, distro string, version string, repo string, arch string) error + // (GET /{org}/{distro}/{version}/{repo}/{arch}/pkgs) ListPackagesByRepo(ctx echo.Context, org string, distro string, version string, repo string, arch string) error @@ -2229,6 +2383,56 @@ func (w *ServerInterfaceWrapper) ListArches(ctx echo.Context) error { return err } +// CreatePackageIndex converts echo context to params. +func (w *ServerInterfaceWrapper) CreatePackageIndex(ctx echo.Context) error { + var err error + // ------------- Path parameter "org" ------------- + var org string + + err = runtime.BindStyledParameterWithLocation("simple", false, "org", runtime.ParamLocationPath, ctx.Param("org"), &org) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter org: %s", err)) + } + + // ------------- Path parameter "distro" ------------- + var distro string + + err = runtime.BindStyledParameterWithLocation("simple", false, "distro", runtime.ParamLocationPath, ctx.Param("distro"), &distro) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter distro: %s", err)) + } + + // ------------- Path parameter "version" ------------- + var version string + + err = runtime.BindStyledParameterWithLocation("simple", false, "version", runtime.ParamLocationPath, ctx.Param("version"), &version) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter version: %s", err)) + } + + // ------------- Path parameter "repo" ------------- + var repo string + + err = runtime.BindStyledParameterWithLocation("simple", false, "repo", runtime.ParamLocationPath, ctx.Param("repo"), &repo) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter repo: %s", err)) + } + + // ------------- Path parameter "arch" ------------- + var arch string + + err = runtime.BindStyledParameterWithLocation("simple", false, "arch", runtime.ParamLocationPath, ctx.Param("arch"), &arch) + if err != nil { + return echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Invalid format for parameter arch: %s", err)) + } + + ctx.Set(BearerAuthScopes, []string{}) + + // Invoke the callback with all the unmarshaled arguments + err = w.Handler.CreatePackageIndex(ctx, org, distro, version, repo, arch) + return err +} + // ListPackagesByRepo converts echo context to params. func (w *ServerInterfaceWrapper) ListPackagesByRepo(ctx echo.Context) error { var err error @@ -2369,6 +2573,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL router.GET(baseURL+"/:org/:distro/:version/repos", wrapper.ListRepos) router.GET(baseURL+"/:org/:distro/:version/:repo", wrapper.FindRepoByName) router.GET(baseURL+"/:org/:distro/:version/:repo/architectures", wrapper.ListArches) + router.POST(baseURL+"/:org/:distro/:version/:repo/:arch/index", wrapper.CreatePackageIndex) router.GET(baseURL+"/:org/:distro/:version/:repo/:arch/pkgs", wrapper.ListPackagesByRepo) router.POST(baseURL+"/:org/:distro/:version/:repo/:arch/pkgs", wrapper.CreatePackage) @@ -2377,30 +2582,32 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL // Base64 encoded, gzipped, json marshaled Swagger object var swaggerSpec = []string{ - "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", + "AAA=", } // GetSwagger returns the content of the embedded swagger specification file diff --git a/internal/openapi/fs.go b/internal/openapi/fs.go index 2aa08b3..def586d 100644 --- a/internal/openapi/fs.go +++ b/internal/openapi/fs.go @@ -287,7 +287,7 @@ func generateAPKIndex(org, distro, version, repo, arch string) { } walkerF := func(ctx context.Context, baseURL string, parent string, info os.FileInfo, reader io.Reader) (toContinue bool, err error) { - // log.Debug().Str("baseurl", baseURL).Str("parent", parent).Msg("generateAPKIndex: walker") + log.Trace().Str("baseurl", baseURL).Str("filename", info.Name()).Str("parent", parent).Msg("generateAPKIndex: walker") if strings.HasSuffix(info.Name(), ".apk") { if parent == "" { // if parent is set that means we've recursed @@ -359,4 +359,5 @@ func generateAPKIndex(org, distro, version, repo, arch string) { if err != nil || c == 0 { log.Error().Err(err).Int("count", c).Msg("failed to write signed archive") } + log.Trace().Msg("finished generating apk index") } diff --git a/internal/openapi/packages.go b/internal/openapi/packages.go index 55cbf5f..8975baa 100644 --- a/internal/openapi/packages.go +++ b/internal/openapi/packages.go @@ -14,19 +14,24 @@ import ( // * Check if org/arch/repo/etc are in known // * Beef up path traversal protection -// PackageBaseDirectory - the base directory where packages are organized/stored -var PackageBaseDirectory = "file:///srv/packages/" +// TODO this is a transitional var, need to move everything to use pkgrepoapi.packagebasedir +var PackageBaseDirectory string // PkgRepoAPI - a collection packages, repos, versions, etc type PkgRepoAPI struct { Repos map[string]Repo + // PackageBaseDirectory - the base directory where packages are organized/stored + PackageBaseDirectory string } // NewPkgRepo - called by main function to -func NewPkgRepo() *PkgRepoAPI { +func NewPkgRepo(dir string) *PkgRepoAPI { p := &PkgRepoAPI{ Repos: make(map[string]Repo), } + // PackageBaseDirectory - the base directory where packages are organized/stored + p.PackageBaseDirectory = "file://" + dir + PackageBaseDirectory = "file://" + dir return p } @@ -132,11 +137,21 @@ func (p *PkgRepoAPI) CreatePackage(ctx echo.Context, org, distro, ver, repo, arc writeUploadedPkg(file, org, distro, ver, repo, arch) - go generateAPKIndex(org, distro, ver, repo, arch) + // go generateAPKIndex(org, distro, ver, repo, arch) return ctx.JSON(http.StatusOK, &Package{Name: pkg.Name, Version: &pkg.Version}) // TODO do we really pkgrel? } +// CreatePackageIndex - regenerate the index for a repo +func (p *PkgRepoAPI) CreatePackageIndex(ctx echo.Context, org, distro, ver, repo, arch string) error { + // generateAPKIndex is meant to be run in a goroutine, so we don't actually get any return from the function + // for now, just blindly return true, but we should tidy this up later + generateAPKIndex(org, distro, ver, repo, arch) + + status := &GenerateIndex{Status: true} + return ctx.JSON(http.StatusOK, status) +} + // ListDistros - return a list of the supported distros func (p *PkgRepoAPI) ListDistros(ctx echo.Context, org string) error { distros, err := listDistros(org) diff --git a/openapi/packages.yaml b/openapi/packages.yaml index 8dbb491..b83f9ed 100644 --- a/openapi/packages.yaml +++ b/openapi/packages.yaml @@ -307,7 +307,6 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" - /{org}/{distro}/{version}/{repo}/{arch}/pkgs: parameters: - name: org @@ -388,9 +387,59 @@ paths: application/json: schema: $ref: "#/components/schemas/Error" + /{org}/{distro}/{version}/{repo}/{arch}/index: + parameters: + - name: org + in: path + description: the name of the organization + required: true + schema: + type: string + - name: distro + in: path + description: the name of the distribution + required: true + schema: + type: string + - name: version + in: path + description: version of repo to look for packages + required: true + schema: + type: string + - name: repo + in: path + description: name of repo to look for packages + required: true + schema: + type: string + - name: arch + in: path + description: arch of repo to look for packages + required: true + schema: + type: string + post: + description: Create a package index in a repo + operationId: CreatePackageIndex + responses: + "200": + description: package index response + content: + application/json: + schema: + type: object + items: + $ref: "#/components/schemas/GenerateIndex" + default: + description: unexpected error + content: + application/json: + schema: + $ref: "#/components/schemas/Error" # try to get the LCD of everything... probably poorly - # /o/{org}/p/{package_type}/r/{repotype}/v/{version}/ + # /{org}/{distro}/{version}/{repo}/{arch}/ # package_type = debian/alpine/npm/maven/etc # repo_type = community/testing/main/ # repo version = stable/buster/3.14/latest/beta @@ -526,3 +575,11 @@ components: description: type: string description: Description of the repo - not functional - just for ease of use + GenerateIndex: + type: object + required: + - status + properties: + status: + type: boolean + description: package index success status