diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 221d47c44d88f5a12af980ba118da0cd4018df41..0585c7b4fb44eeb77d0bc28bff507d7a94189beb 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,7 +16,7 @@ include: - template: 'Workflows/Branch-Pipelines.gitlab-ci.yml' lint: - image: golangci/golangci-lint:v1.50.0 + image: golangci/golangci-lint:v1.50.1 stage: test tags: - amd64-docker @@ -28,7 +28,7 @@ lint: - cd /go/src/gitlab.com/${CI_PROJECT_PATH} unit tests: - image: golang:1.19.2 + image: golang:1.19.3 extends: .gotest stage: test tags: @@ -37,7 +37,7 @@ unit tests: coverage: '/total:\s+\(statements\)\s+(\d+.\d+\%)/' govulncheck: - image: golang:1.19.2 + image: golang:1.19.3 stage: test tags: - amd64-docker diff --git a/cmd/policy/main.go b/cmd/policy/main.go index 2f3cc54834c5538489556a19ffe1832edcd3b025..8e1efed6f10eee05624813d84bd6445d8ac3585f 100644 --- a/cmd/policy/main.go +++ b/cmd/policy/main.go @@ -100,8 +100,8 @@ func main() { regofunc.Register("didResolve", rego.Function1(didResolverFuncs.ResolveFunc())) regofunc.Register("taskCreate", rego.Function2(taskFuncs.CreateTaskFunc())) regofunc.Register("taskListCreate", rego.Function2(taskFuncs.CreateTaskListFunc())) - regofunc.Register("getKey", rego.Function3(signerFuncs.GetKeyFunc())) - regofunc.Register("getAllKeys", rego.Function2(signerFuncs.GetAllKeysFunc())) + regofunc.Register("verificationMethod", rego.Function3(signerFuncs.VerificationMethodFunc())) + regofunc.Register("verificationMethods", rego.Function2(signerFuncs.VerificationMethodsFunc())) regofunc.Register("addVCProof", rego.Function3(signerFuncs.AddVCProofFunc())) regofunc.Register("addVPProof", rego.Function4(signerFuncs.AddVPProofFunc())) regofunc.Register("verifyProof", rego.Function1(signerFuncs.VerifyProofFunc())) diff --git a/deployment/ci/Dockerfile b/deployment/ci/Dockerfile index 81a5368b219523506e9b44b42585c99e15d28486..bab25afa9cc08ac606515bff0afe68016afa6151 100644 --- a/deployment/ci/Dockerfile +++ b/deployment/ci/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.2-alpine3.15 as builder +FROM golang:1.19.3-alpine3.15 as builder RUN apk add git diff --git a/deployment/compose/Dockerfile b/deployment/compose/Dockerfile index 49788678f33240ebf5385e792dc2872a08d9560c..6461908e334da2e5911921870e538d83c031d01c 100644 --- a/deployment/compose/Dockerfile +++ b/deployment/compose/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.19.2 +FROM golang:1.19.3 RUN go install github.com/canthefason/go-watcher/cmd/watcher@v0.2.4 diff --git a/internal/regofunc/signer.go b/internal/regofunc/signer.go index 86cc62508edeb8a0a2fc4fa1830d4349587ef606..70afe349e2321796623fb47d7220ad08c334f99b 100644 --- a/internal/regofunc/signer.go +++ b/internal/regofunc/signer.go @@ -14,8 +14,10 @@ import ( ) const ( - createVCProofPath = "/v1/credential/proof" - createVPProofPath = "/v1/presentation/proof" + verificationMethodPath = "/v1/verification-methods/%s/%s/%s" + verificationMethodsPath = "/v1/verification-methods/%s/%s" + createVCProofPath = "/v1/credential/proof" + createVPProofPath = "/v1/presentation/proof" ) type SignerFuncs struct { @@ -30,9 +32,9 @@ func NewSignerFuncs(signerAddr string, httpClient *http.Client) *SignerFuncs { } } -func (sf *SignerFuncs) GetKeyFunc() (*rego.Function, rego.Builtin3) { +func (sf *SignerFuncs) VerificationMethodFunc() (*rego.Function, rego.Builtin3) { return ®o.Function{ - Name: "keys.get", + Name: "verification_method", Decl: types.NewFunction(types.Args(types.S, types.S, types.S), types.A), Memoize: true, }, @@ -56,7 +58,7 @@ func (sf *SignerFuncs) GetKeyFunc() (*rego.Function, rego.Builtin3) { return nil, fmt.Errorf("empty keyname") } - path := fmt.Sprintf("/v1/keys/%s/%s/%s", did, namespace, key) + path := fmt.Sprintf(verificationMethodPath, namespace, key, did) uri, err := url.ParseRequestURI(sf.signerAddr + path) if err != nil { return nil, err @@ -86,9 +88,9 @@ func (sf *SignerFuncs) GetKeyFunc() (*rego.Function, rego.Builtin3) { } } -func (sf *SignerFuncs) GetAllKeysFunc() (*rego.Function, rego.Builtin2) { +func (sf *SignerFuncs) VerificationMethodsFunc() (*rego.Function, rego.Builtin2) { return ®o.Function{ - Name: "keys.getAll", + Name: "verification_methods", Decl: types.NewFunction(types.Args(types.S, types.S), types.A), Memoize: true, }, @@ -107,7 +109,7 @@ func (sf *SignerFuncs) GetAllKeysFunc() (*rego.Function, rego.Builtin2) { return nil, fmt.Errorf("empty key namespace") } - path := fmt.Sprintf("/v1/keys/%s/%s", did, namespace) + path := fmt.Sprintf(verificationMethodsPath, namespace, did) uri, err := url.ParseRequestURI(sf.signerAddr + path) if err != nil { return nil, err diff --git a/internal/regofunc/signer_test.go b/internal/regofunc/signer_test.go index 2525dcd6e358df41e7bfaba9234e755d7e0ef5dd..f32723772e943d14b5967ca829e1361a7ab46ad5 100644 --- a/internal/regofunc/signer_test.go +++ b/internal/regofunc/signer_test.go @@ -14,7 +14,7 @@ import ( "gitlab.com/gaia-x/data-infrastructure-federation-services/tsa/policy/internal/regofunc" ) -func TestGetKeyFunc(t *testing.T) { +func TestVerificationMethodFunc(t *testing.T) { expected := `{"key1":"key1 data"}` signerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = fmt.Fprint(w, expected) @@ -23,8 +23,8 @@ func TestGetKeyFunc(t *testing.T) { keysFuncs := regofunc.NewSignerFuncs(signerSrv.URL, http.DefaultClient) r := rego.New( - rego.Query(`keys.get("did:web:example.com", "transit", "key1")`), - rego.Function3(keysFuncs.GetKeyFunc()), + rego.Query(`verification_method("did:web:example.com", "transit", "key1")`), + rego.Function3(keysFuncs.VerificationMethodFunc()), rego.StrictBuiltinErrors(true), ) resultSet, err := r.Eval(context.Background()) @@ -35,7 +35,7 @@ func TestGetKeyFunc(t *testing.T) { assert.Equal(t, expected, string(resultBytes)) } -func TestGetKeyFuncError(t *testing.T) { +func TestVerificationMethodFuncError(t *testing.T) { signerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) })) @@ -43,19 +43,19 @@ func TestGetKeyFuncError(t *testing.T) { keysFuncs := regofunc.NewSignerFuncs(signerSrv.URL, http.DefaultClient) r := rego.New( - rego.Query(`keys.get("did:web:example.com", "transit", "key1")`), - rego.Function3(keysFuncs.GetKeyFunc()), + rego.Query(`verification_method("did:web:example.com", "transit", "key1")`), + rego.Function3(keysFuncs.VerificationMethodFunc()), rego.StrictBuiltinErrors(true), ) resultSet, err := r.Eval(context.Background()) assert.Nil(t, resultSet) assert.Error(t, err) - expectedError := `keys.get("did:web:example.com", "transit", "key1"): eval_builtin_error: keys.get: unexpected response from signer: 404 Not Found` + expectedError := `verification_method("did:web:example.com", "transit", "key1"): eval_builtin_error: verification_method: unexpected response from signer: 404 Not Found` assert.Equal(t, expectedError, err.Error()) } -func TestGetAllKeysFunc(t *testing.T) { +func TestVerificationMethodsFunc(t *testing.T) { expected := `[{"key1":"key1 data"},{"key2":"key2 data"}]` signerSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { _, _ = fmt.Fprint(w, expected) @@ -64,8 +64,8 @@ func TestGetAllKeysFunc(t *testing.T) { keysFuncs := regofunc.NewSignerFuncs(signerSrv.URL, http.DefaultClient) r := rego.New( - rego.Query(`keys.getAll("did:web:example.com", "transit")`), - rego.Function2(keysFuncs.GetAllKeysFunc()), + rego.Query(`verification_methods("did:web:example.com", "transit")`), + rego.Function2(keysFuncs.VerificationMethodsFunc()), rego.StrictBuiltinErrors(true), ) resultSet, err := r.Eval(context.Background())