Skip to content

Commit

Permalink
Generate shim stub with oapi-codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
sevein committed Jul 8, 2024
1 parent f6e9dd8 commit e184eda
Show file tree
Hide file tree
Showing 13 changed files with 3,649 additions and 10 deletions.
6 changes: 2 additions & 4 deletions hack/ccp/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,19 @@ issues:
exclude-dirs:
- hack
- proto
- internal/shim/gen
exclude-rules:
- path: _test\.go
linters:
- errcheck

linters-settings:
gci:
no-inline-comments: true
no-prefix-comments: false
sections:
- standard
- default
- prefix(github.com/artefactual/archivematica/hack/ccp)
section-separators:
- newLine
custom-order: true
gofumpt:
extra-rules: true
gosec:
Expand Down
19 changes: 16 additions & 3 deletions hack/ccp/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

PROJECT := ccp
MAKEDIR := hack/make
SHELL := /bin/bash
Expand All @@ -20,6 +21,7 @@ include hack/make/dep_goenum.mk
include hack/make/dep_golangci_lint.mk
include hack/make/dep_gotestsum.mk
include hack/make/dep_mockgen.mk
include hack/make/dep_oapi_codegen.mk
include hack/make/dep_sqlc.mk
include hack/make/dep_tparse.mk
include hack/make/enums.mk
Expand All @@ -30,6 +32,7 @@ TOOLS = $(BUF) \
$(GOLANGCI_LINT) \
$(GOTESTSUM) \
$(MOCKGEN) \
$(OAPI_CODEGEN) \
$(SQLC) \
$(TPARSE)

Expand All @@ -40,6 +43,7 @@ endef

IGNORED_PACKAGES := \
github.com/artefactual/archivematica/hack/ccp/internal/api/gen/% \
github.com/artefactual/archivematica/hack/ccp/internal/shim/gen \
github.com/artefactual/archivematica/hack/ccp/internal/%/enums \
github.com/artefactual/archivematica/hack/ccp/internal/ssclient/ssclientmock \
github.com/artefactual/archivematica/hack/ccp/internal/store/sqlcmysql \
Expand Down Expand Up @@ -110,7 +114,7 @@ deps:
@go mod tidy

gen: # @HELP Generage code.
gen: gen-mocks gen-sqlc gen-enums gen-buf
gen: gen-mocks gen-sqlc gen-enums gen-buf gen-web gen-shim

gen-mocks: # @HELP Generate mocks.
gen-mocks: $(MOCKGEN)
Expand All @@ -134,10 +138,19 @@ gen-buf: $(BUF)
$(CURDIR)/../../src/dashboard/src/client/gen/archivematica/ccp/admin/v1beta1/*.py \
$(CURDIR)/../../src/dashboard/src/client/gen/buf/validate/*.py

gen-ui: # @HELP Generate webui assets.
gen-ui:
gen-web: # @HELP Generate webui assets.
gen-web:
npm --prefix=$(CURDIR)/web run build

gen-shim: # @HELP Generate Go server boilerplate from OpenAPIv3 spec.
gen-shim: SPEC_COMMIT := b0b9af20
gen-shim: SPEC_URL := https://raw.githubusercontent.com/artefactual-labs/archivematica-api-specification/$(SPEC_COMMIT)/typespec/tsp-output/@typespec/openapi3/openapi.v1.yaml
gen-shim: $(OAPI_CODEGEN)
@echo "Downloading Archivematica API specification ($(SPEC_COMMIT))..."
@echo "Full URL: $(SPEC_URL)"
curl -Ls -o /tmp/amspec.yml $(SPEC_URL)
cd $(CURDIR)/internal/shim && oapi-codegen -config=config.yml /tmp/amspec.yml

push: # @HELP Push new build of CCP to development environment.
push:
docker compose up -d --force-recreate --build --no-deps archivematica-ccp
Expand Down
12 changes: 11 additions & 1 deletion hack/ccp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/doug-martin/goqu/v9 v9.19.0
github.com/elliotchance/orderedmap/v2 v2.2.0
github.com/fsnotify/fsnotify v1.7.0
github.com/getkin/kin-openapi v0.123.0
github.com/go-logr/logr v1.4.2
github.com/go-sql-driver/mysql v1.8.1
github.com/gohugoio/hugo v0.128.1
Expand All @@ -25,6 +26,7 @@ require (
github.com/hashicorp/go-retryablehttp v0.7.7
github.com/jellydator/ttlcache/v3 v3.2.0
github.com/mikespook/gearman-go v0.0.0-20220520031403-2a518e866145
github.com/oapi-codegen/runtime v1.1.1
github.com/otiai10/copy v1.14.0
github.com/peterbourgon/ff/v3 v3.4.0
github.com/prometheus/client_golang v1.19.1
Expand Down Expand Up @@ -52,6 +54,7 @@ require (
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/Microsoft/hcsshim v0.11.4 // indirect
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bep/godartsass v1.2.0 // indirect
github.com/bep/godartsass/v2 v2.0.0 // indirect
Expand All @@ -71,15 +74,20 @@ require (
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-logr/zapr v1.3.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/cel-go v0.20.1 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/klauspost/compress v1.16.0 // indirect
github.com/invopop/yaml v0.2.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/microsoft/kiota-abstractions-go v1.6.0 // indirect
github.com/microsoft/kiota-http-go v1.4.1 // indirect
Expand All @@ -92,11 +100,13 @@ require (
github.com/moby/sys/sequential v0.5.0 // indirect
github.com/moby/sys/user v0.1.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
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/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
Expand Down
18 changes: 16 additions & 2 deletions hack/ccp/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/Microsoft/hcsshim v0.11.4 h1:68vKo2VN8DE9AdN4tnkWnmdhqdbpUFM8OF3Airm7fz8=
github.com/Microsoft/hcsshim v0.11.4/go.mod h1:smjE4dvqPX9Zldna+t5FG3rnoHhaB7QYxPRqGcpAD9w=
github.com/RaveNoX/go-jsoncommentstrip v1.0.0/go.mod h1:78ihd09MekBnJnxpICcwzCMzGrKSKYe4AqU6PDYYpjk=
github.com/alecthomas/chroma/v2 v2.14.0 h1:R3+wzpnUArGcQz7fCETQBzO5n9IMNi13iIs46aU4V9E=
github.com/alecthomas/chroma/v2 v2.14.0/go.mod h1:QolEbTfmUHIMVpBqxeDnNBj2uoeI4EbYP4i6n68SG4I=
github.com/antlr4-go/antlr/v4 v4.13.0 h1:lxCg3LAv+EUK6t1i0y1V6/SLeUi0eKEKdhQAlS8TVTI=
github.com/antlr4-go/antlr/v4 v4.13.0/go.mod h1:pfChB/xh/Unjila75QW7+VU4TSnWnnk9UTnmpPaOR2g=
github.com/apapsch/go-jsonmerge/v2 v2.0.0 h1:axGnT1gRIfimI7gJifB699GoE/oq+F2MU7Dml6nw9rQ=
github.com/apapsch/go-jsonmerge/v2 v2.0.0/go.mod h1:lvDnEdqiQrp0O42VQGgmlKpxL1AP2+08jFMw88y4klk=
github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c h1:651/eoCRnQ7YtSjAnSzRucrJz+3iGEFt+ysraELS81M=
github.com/armon/go-radix v1.0.1-0.20221118154546-54df44f2176c/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/artefactual-labs/gearmin v0.3.0 h1:2XK72IdrY+JV50+a55/bcdlkuDXz5Uir5g4Ob8W+hgc=
Expand Down Expand Up @@ -60,6 +63,7 @@ github.com/bep/overlayfs v0.9.2 h1:qJEmFInsW12L7WW7dOTUhnMfyk/fN9OCDEO5Gr8HSDs=
github.com/bep/overlayfs v0.9.2/go.mod h1:aYY9W7aXQsGcA7V9x/pzeR8LjEgIxbtisZm8Q7zPz40=
github.com/bep/tmc v0.5.1 h1:CsQnSC6MsomH64gw0cT5f+EwQDcvZz4AazKunFwTpuI=
github.com/bep/tmc v0.5.1/go.mod h1:tGYHN8fS85aJPhDLgXETVKp+PR382OvFi2+q2GkGsq0=
github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvFv1sNto9p6w=
github.com/bool64/dev v0.2.17 h1:jE+T92oazAIV8fvMDJrKjsF1bzfr5XezZ8bM5GS1Cl0=
github.com/bool64/dev v0.2.17/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg=
github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E=
Expand Down Expand Up @@ -145,6 +149,8 @@ github.com/go-openapi/swag v0.22.8/go.mod h1:6QT22icPLEqAM/z/TChgb4WAveCHF92+2gF
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
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/gobuffalo/flect v1.0.2 h1:eqjPGSo2WmjgY2XlpGwo2NXgL3RucAKo4k4qQMNA5sA=
github.com/gobuffalo/flect v1.0.2/go.mod h1:A5msMlrHtLqh9umBSnvabjsMrCcCpAyzglnDvkbYKHs=
github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
Expand Down Expand Up @@ -222,10 +228,11 @@ github.com/jellydator/ttlcache/v3 v3.2.0 h1:6lqVJ8X3ZaUwvzENqPAobDsXNExfUJd61u++
github.com/jellydator/ttlcache/v3 v3.2.0/go.mod h1:hi7MGFdMAwZna5n2tuvh63DvFLzVKySzCVW6+0gA2n4=
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=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.16.0 h1:iULayQNOReoYUe+1qtKOqw9CwJv3aNQu8ivo7lw1HU4=
github.com/klauspost/compress v1.16.0/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I=
github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down Expand Up @@ -291,6 +298,8 @@ github.com/niklasfasching/go-org v1.7.0 h1:vyMdcMWWTe/XmANk19F4k8XGBYg0GQ/gJGMim
github.com/niklasfasching/go-org v1.7.0/go.mod h1:WuVm4d45oePiE0eX25GqTDQIt/qPW1T9DGkRscqLW5o=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oapi-codegen/runtime v1.1.1 h1:EXLHh0DXIJnWhdRPN2w4MXAzFyE4CskzhNLUmtpMYro=
github.com/oapi-codegen/runtime v1.1.1/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/onsi/ginkgo v1.15.2 h1:l77YT15o814C2qVL47NOyjV/6RbaP7kKdrvZnxQ3Org=
Expand Down Expand Up @@ -352,6 +361,7 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/std-uritemplate/std-uritemplate/go v0.0.55 h1:muSH037g97K7U2f94G9LUuE8tZlJsoSSrPsO9V281WY=
github.com/std-uritemplate/std-uritemplate/go v0.0.55/go.mod h1:rG/bqh/ThY4xE5de7Rap3vaDkYUT76B0GPJ0loYeTTc=
github.com/stoewer/go-strcase v1.3.0 h1:g0eASXYtp+yvN9fK8sH94oCIk0fau9uV1/ZdJ0AVEzs=
Expand All @@ -361,6 +371,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
Expand All @@ -387,6 +398,8 @@ github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFA
github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI=
github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk=
github.com/tklauser/numcpus v0.6.1/go.mod h1:1XfjsgE2zo8GVw7POkMbHENHzVg3GzmoZ9fESEdAacY=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA=
github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg=
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M=
Expand Down Expand Up @@ -548,6 +561,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
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=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
Expand Down
16 changes: 16 additions & 0 deletions hack/ccp/hack/make/dep_oapi_codegen.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
$(call _assert_var,MAKEDIR)
$(call _conditional_include,$(MAKEDIR)/base.mk)
$(call _assert_var,CACHE_VERSIONS)
$(call _assert_var,CACHE_BIN)

OAPI_CODEGEN_VERSION ?= 2.3.0

OAPI_CODEGEN := $(CACHE_VERSIONS)/oapi-codegen/$(OAPI_CODEGEN_VERSION)
$(OAPI_CODEGEN):
rm -f $(CACHE_BIN)/oapi-codegen
mkdir -p $(CACHE_BIN)
env GOBIN=$(CACHE_BIN) go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@v$(OAPI_CODEGEN_VERSION)
chmod +x $(CACHE_BIN)/oapi-codegen
rm -rf $(dir $(OAPI_CODEGEN))
mkdir -p $(dir $(OAPI_CODEGEN))
touch $(OAPI_CODEGEN)
2 changes: 2 additions & 0 deletions hack/ccp/internal/cmd/servercmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func New(rootConfig *rootcmd.Config, out io.Writer) *ffcli.Command {
fs.StringVar(&cfg.ssclient.BaseURL, "ssclient.url", "", "Storage Service API base URL")
fs.StringVar(&cfg.ssclient.Username, "ssclient.username", "", "Storage Service API username")
fs.StringVar(&cfg.ssclient.Key, "ssclient.key", "", "Storage Service API key")
fs.BoolVar(&cfg.shim.Enabled, "shim.enabled", false, "Enable the Archivematica API shim for backward compatibility with older clients.")
fs.StringVar(&cfg.shim.Addr, "shim.addr", "", "Archivematica API shim listen address")
fs.StringVar(&cfg.metrics.Addr, "metrics.addr", "", "Prometheus HTTP API listen address")

rootConfig.RegisterFlags(fs)
Expand Down
2 changes: 2 additions & 0 deletions hack/ccp/internal/cmd/servercmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/artefactual/archivematica/hack/ccp/internal/api/admin"
"github.com/artefactual/archivematica/hack/ccp/internal/cmd/rootcmd"
"github.com/artefactual/archivematica/hack/ccp/internal/cmd/servercmd/metrics"
"github.com/artefactual/archivematica/hack/ccp/internal/shim"
"github.com/artefactual/archivematica/hack/ccp/internal/ssclient"
"github.com/artefactual/archivematica/hack/ccp/internal/webui"
)
Expand All @@ -20,6 +21,7 @@ type Config struct {
gearmin gearminConfig
ssclient ssclient.Config
webui webui.Config
shim shim.Config
metrics metrics.Config
}

Expand Down
16 changes: 16 additions & 0 deletions hack/ccp/internal/cmd/servercmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/artefactual/archivematica/hack/ccp/internal/api/admin"
"github.com/artefactual/archivematica/hack/ccp/internal/controller"
"github.com/artefactual/archivematica/hack/ccp/internal/shim"
"github.com/artefactual/archivematica/hack/ccp/internal/ssclient"
"github.com/artefactual/archivematica/hack/ccp/internal/store"
"github.com/artefactual/archivematica/hack/ccp/internal/webui"
Expand Down Expand Up @@ -46,6 +47,9 @@ type Server struct {
// Admin API.
admin *admin.Server

// Shim API.
shim *shim.Server

// Web UI.
webui *webui.Server
}
Expand Down Expand Up @@ -150,6 +154,14 @@ func (s *Server) Run() error {
return fmt.Errorf("error running admin API: %v", err)
}

if s.config.shim.Enabled {
s.logger.V(1).Info("Creating Archivematica API shim.")
s.shim = shim.NewServer(s.logger.WithName("shim"), s.config.shim)
if err := s.shim.Run(); err != nil {
return fmt.Errorf("error creating shim API: %v", err)
}
}

s.logger.V(1).Info("Creating web UI.")
s.webui = webui.New(s.logger.WithName("webui"), s.config.webui, s.admin.Addr())
if err := s.webui.Run(); err != nil {
Expand Down Expand Up @@ -187,6 +199,10 @@ func (s *Server) Close() error {
errs = errors.Join(errs, s.admin.Close(ctx))
}

if s.shim != nil {
errs = errors.Join(errs, s.shim.Close(ctx))
}

if s.webui != nil {
errs = errors.Join(errs, s.webui.Close(ctx))
}
Expand Down
6 changes: 6 additions & 0 deletions hack/ccp/internal/shim/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package shim

type Config struct {
Enabled bool
Addr string
}
13 changes: 13 additions & 0 deletions hack/ccp/internal/shim/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/deepmap/oapi-codegen/HEAD/configuration-schema.json
package: gen
generate:
std-http-server: true
strict-server: true
models: true
embedded-spec: true
output: gen/shim.go
output-options:
name-normalizer: ToCamelCaseWithInitialisms
disable-type-aliases-for-type: []
compatibility:
always-prefix-enum-values: true
Loading

0 comments on commit e184eda

Please sign in to comment.