diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f92de4ed3bc43b1337bb35a71a18ba444c412ae2..b13a5279eb652883c708185ad9c13a6e9382f477 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -30,7 +30,7 @@ lint: before_script: [] unit tests: - image: golang:1.20.5 + image: golang:1.21.3 extends: .gotest stage: test tags: @@ -39,7 +39,7 @@ unit tests: coverage: '/total:\s+\(statements\)\s+(\d+.\d+\%)/' govulncheck: - image: golang:1.20.5 + image: golang:1.21.3 stage: test tags: - amd64-docker diff --git a/deployment/ci/Dockerfile b/deployment/ci/Dockerfile index 69b06050d630194d356186a86665e8d7a834f97d..7108a3053f7e5c0ccc5e8e6d18e22ad70db23e51 100644 --- a/deployment/ci/Dockerfile +++ b/deployment/ci/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.5-alpine3.17 as builder +FROM golang:1.21.3-alpine3.17 as builder RUN apk add git diff --git a/deployment/compose/Dockerfile b/deployment/compose/Dockerfile index aecea02ecd15a9c5bfcd8fee00101e76fe2657c2..f725a89a95668264c5e13020792e2a4946ce5235 100644 --- a/deployment/compose/Dockerfile +++ b/deployment/compose/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.20.5 +FROM golang:1.21.3 RUN go install github.com/ysmood/kit/cmd/guard@v0.25.11 diff --git a/design/design.go b/design/design.go index ab4a588b968db49bc06f167adf45f447df6868f9..1d19cd42e4f2f292eeb50f8a8922ea76c705c19a 100644 --- a/design/design.go +++ b/design/design.go @@ -59,6 +59,22 @@ var _ = Service("policy", func() { Response(StatusOK) }) }) + + Method("ListPolicies", func() { + Description("Listing all policies") + Payload(PoliciesRequest) + Result(PoliciesResult) + HTTP(func() { + GET("/v1/policies") + Params(func() { + Param("locked", Boolean, "return only locked or unlocked policies") + Param("rego", Boolean, "return the rego code of the policies also") + Param("data", Boolean, "return the data of the policies also") + Param("dataConfig", Boolean, "return the data config of the policies also") + }) + Response(StatusOK) + }) + }) }) var _ = Service("health", func() { diff --git a/design/types.go b/design/types.go index 33542dfcf8e0900821cc4909eda4f17610be8df9..e0e571baae850b6a9556e3fbb48a2060264f7508 100644 --- a/design/types.go +++ b/design/types.go @@ -38,3 +38,27 @@ var UnlockRequest = Type("UnlockRequest", func() { Field(3, "version", String, "Policy version.") Required("group", "policyName", "version") }) + +var Policy = Type("Policy", func() { + Field(1, "policyName", String, "policy name") + Field(2, "group", String, "policy group") + Field(3, "version", String, "policy version") + Field(4, "rego", String, "policy rego code") + Field(5, "data", String, "policy data") + Field(6, "dataConfig", String, "policy data config") + Field(7, "locked", Boolean, "if it true gives locked status on the policy") + Field(8, "lastUpdate", Int64, "Last update (timestamp).") + Required("group", "policyName", "version", "locked", "lastUpdate") +}) + +var PoliciesRequest = Type("PoliciesRequest", func() { + Field(1, "locked", Boolean) + Field(2, "rego", Boolean) + Field(3, "data", Boolean) + Field(4, "dataConfig", Boolean) +}) + +var PoliciesResult = Type("PoliciesResult", func() { + Field(1, "policies", ArrayOf(Policy), "policy list") + Required("policies") +}) diff --git a/gen/health/client.go b/gen/health/client.go index 0d326f2ff9d4bf4f8c23f496ee8d4b3ab9ec4acd..68b00b3e05a2ce2010c89a7a04b43bca4f2dcb92 100644 --- a/gen/health/client.go +++ b/gen/health/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health client // diff --git a/gen/health/endpoints.go b/gen/health/endpoints.go index 1bab50270f8b7e3fd66162a69ea9e324859690b2..99758d7fdc5c8c6682061d8469e36c5838cb4d44 100644 --- a/gen/health/endpoints.go +++ b/gen/health/endpoints.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health endpoints // diff --git a/gen/health/service.go b/gen/health/service.go index 8b84257344fd91d75f03e4adb78cb0b8b29d7f81..8062b06e026ec88fe41322b6ceacd55823a9430b 100644 --- a/gen/health/service.go +++ b/gen/health/service.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health service // diff --git a/gen/http/cli/policy/cli.go b/gen/http/cli/policy/cli.go index 8860bc2b6d0400667b8dc8c8068f91fb7da6daa1..b4fa97d11229963414bedb31611b15b4c9e3a747 100644 --- a/gen/http/cli/policy/cli.go +++ b/gen/http/cli/policy/cli.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP client CLI support package // @@ -24,14 +24,14 @@ import ( // command (subcommand1|subcommand2|...) func UsageCommands() string { return `health (liveness|readiness) -policy (evaluate|lock|unlock) +policy (evaluate|lock|unlock|list-policies) ` } // UsageExamples produces an example of a valid invocation of the CLI tool. func UsageExamples() string { return os.Args[0] + ` health liveness` + "\n" + - os.Args[0] + ` policy evaluate --body "Ipsum nihil quo." --group "example" --policy-name "example" --version "1.0" --evaluation-id "Aut id odio." --ttl 1804438149079407927` + "\n" + + os.Args[0] + ` policy evaluate --body "Quibusdam ab repellendus in illum." --group "example" --policy-name "example" --version "1.0" --evaluation-id "Nihil repudiandae dolore quod sunt aut." --ttl 4633716418015214972` + "\n" + "" } @@ -70,6 +70,12 @@ func ParseEndpoint( policyUnlockGroupFlag = policyUnlockFlags.String("group", "REQUIRED", "Policy group.") policyUnlockPolicyNameFlag = policyUnlockFlags.String("policy-name", "REQUIRED", "Policy name.") policyUnlockVersionFlag = policyUnlockFlags.String("version", "REQUIRED", "Policy version.") + + policyListPoliciesFlags = flag.NewFlagSet("list-policies", flag.ExitOnError) + policyListPoliciesLockedFlag = policyListPoliciesFlags.String("locked", "", "") + policyListPoliciesRegoFlag = policyListPoliciesFlags.String("rego", "", "") + policyListPoliciesDataFlag = policyListPoliciesFlags.String("data", "", "") + policyListPoliciesDataConfigFlag = policyListPoliciesFlags.String("data-config", "", "") ) healthFlags.Usage = healthUsage healthLivenessFlags.Usage = healthLivenessUsage @@ -79,6 +85,7 @@ func ParseEndpoint( policyEvaluateFlags.Usage = policyEvaluateUsage policyLockFlags.Usage = policyLockUsage policyUnlockFlags.Usage = policyUnlockUsage + policyListPoliciesFlags.Usage = policyListPoliciesUsage if err := flag.CommandLine.Parse(os.Args[1:]); err != nil { return nil, nil, err @@ -135,6 +142,9 @@ func ParseEndpoint( case "unlock": epf = policyUnlockFlags + case "list-policies": + epf = policyListPoliciesFlags + } } @@ -179,6 +189,9 @@ func ParseEndpoint( case "unlock": endpoint = c.Unlock() data, err = policyc.BuildUnlockPayload(*policyUnlockGroupFlag, *policyUnlockPolicyNameFlag, *policyUnlockVersionFlag) + case "list-policies": + endpoint = c.ListPolicies() + data, err = policyc.BuildListPoliciesPayload(*policyListPoliciesLockedFlag, *policyListPoliciesRegoFlag, *policyListPoliciesDataFlag, *policyListPoliciesDataConfigFlag) } } } @@ -233,6 +246,7 @@ COMMAND: evaluate: Evaluate executes a policy with the given 'data' as input. lock: Lock a policy so that it cannot be evaluated. unlock: Unlock a policy so it can be evaluated again. + list-policies: Listing all policies Additional help: %[1]s policy COMMAND --help @@ -250,7 +264,7 @@ Evaluate executes a policy with the given 'data' as input. -ttl INT: Example: - %[1]s policy evaluate --body "Ipsum nihil quo." --group "example" --policy-name "example" --version "1.0" --evaluation-id "Aut id odio." --ttl 1804438149079407927 + %[1]s policy evaluate --body "Quibusdam ab repellendus in illum." --group "example" --policy-name "example" --version "1.0" --evaluation-id "Nihil repudiandae dolore quod sunt aut." --ttl 4633716418015214972 `, os.Args[0]) } @@ -263,7 +277,7 @@ Lock a policy so that it cannot be evaluated. -version STRING: Policy version. Example: - %[1]s policy lock --group "Repudiandae dolore quod." --policy-name "Aut ut fuga quae eius minus." --version "Architecto quibusdam ab." + %[1]s policy lock --group "Aliquam atque voluptatum ut dolorem." --policy-name "Aut facere veniam repudiandae id." --version "Aut minus alias." `, os.Args[0]) } @@ -276,6 +290,20 @@ Unlock a policy so it can be evaluated again. -version STRING: Policy version. Example: - %[1]s policy unlock --group "Omnis quasi aut consequuntur." --policy-name "Tempore minus." --version "Quis quos qui earum velit illum." + %[1]s policy unlock --group "Aut voluptas." --policy-name "Sint nam voluptatem ea consequatur similique et." --version "Non mollitia nesciunt impedit facere." +`, os.Args[0]) +} + +func policyListPoliciesUsage() { + fmt.Fprintf(os.Stderr, `%[1]s [flags] policy list-policies -locked BOOL -rego BOOL -data BOOL -data-config BOOL + +Listing all policies + -locked BOOL: + -rego BOOL: + -data BOOL: + -data-config BOOL: + +Example: + %[1]s policy list-policies --locked false --rego true --data false --data-config false `, os.Args[0]) } diff --git a/gen/http/health/client/cli.go b/gen/http/health/client/cli.go index 9a5dd72f41c4044c5c1c1b609221725f7ad3069b..cb91c607ae3e385d9c78ea6fdadf547b8c6822aa 100644 --- a/gen/http/health/client/cli.go +++ b/gen/http/health/client/cli.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health HTTP client CLI support package // diff --git a/gen/http/health/client/client.go b/gen/http/health/client/client.go index 73eb15fbee1a441cfbdbd7db9525d466902deb2a..0dd74ee3371452ab68b7e2fce0e1b48adb6e6aaa 100644 --- a/gen/http/health/client/client.go +++ b/gen/http/health/client/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health client HTTP transport // diff --git a/gen/http/health/client/encode_decode.go b/gen/http/health/client/encode_decode.go index 129a14ca6e5d75e577a36dc8c70814670f1d7147..10b9b8968fbd303e14401a1d417d78ad95e82881 100644 --- a/gen/http/health/client/encode_decode.go +++ b/gen/http/health/client/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health HTTP client encoders and decoders // diff --git a/gen/http/health/client/paths.go b/gen/http/health/client/paths.go index 197bb77d0a512e9b68d5e53414f01ed3120abd13..37d9b325ff3ac0a1fb2d85b53337f3c6fc3f41bf 100644 --- a/gen/http/health/client/paths.go +++ b/gen/http/health/client/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // HTTP request path constructors for the health service. // diff --git a/gen/http/health/client/types.go b/gen/http/health/client/types.go index 3fdcd7b7389049281968de77451f452db0e0410a..f5ea9ffef248109d9f2ac6485009394664fba140 100644 --- a/gen/http/health/client/types.go +++ b/gen/http/health/client/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health HTTP client types // diff --git a/gen/http/health/server/encode_decode.go b/gen/http/health/server/encode_decode.go index 6f60524b0a9f6c84d57fb709ab8765c9814267cd..42e520a4891df2de95339d8802bba1289a099225 100644 --- a/gen/http/health/server/encode_decode.go +++ b/gen/http/health/server/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health HTTP server encoders and decoders // diff --git a/gen/http/health/server/paths.go b/gen/http/health/server/paths.go index d9f2d27f904b1f3a752ec956430a5127bc124476..acaad7720cd759878ba8bba7e0177564fa8590de 100644 --- a/gen/http/health/server/paths.go +++ b/gen/http/health/server/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // HTTP request path constructors for the health service. // diff --git a/gen/http/health/server/server.go b/gen/http/health/server/server.go index 821b057387276af1021a6432c1c8eb50c9d8c3bb..8315818bc59e4d2eda3d008e24a73de15baa6287 100644 --- a/gen/http/health/server/server.go +++ b/gen/http/health/server/server.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health HTTP server // diff --git a/gen/http/health/server/types.go b/gen/http/health/server/types.go index e00b6e25de4bc605b5a65094d21e272c73a55797..cc6c3b5c9d0378fbd5f838e3ae329fc433c1392a 100644 --- a/gen/http/health/server/types.go +++ b/gen/http/health/server/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // health HTTP server types // diff --git a/gen/http/openapi.json b/gen/http/openapi.json index f8333f00c2c6c2f647f7289e9b3f493d7cc5deab..6bee8d21aa2f32fdf8176fd7ce80f4ef1d1ee52c 100644 --- a/gen/http/openapi.json +++ b/gen/http/openapi.json @@ -1 +1 @@ -{"swagger":"2.0","info":{"title":"Policy Service","description":"The policy service exposes HTTP API for executing policies.","version":""},"host":"localhost:8081","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/policy/{group}/{policyName}/{version}/evaluation":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#1","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","description":"Input data passed to the policy execution runtime.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"},"headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","type":"string"}}}},"schemes":["http"]},"post":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#2","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","description":"Input data passed to the policy execution runtime.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"},"headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","type":"string"}}}},"schemes":["http"]}},"/policy/{group}/{policyName}/{version}/evaluation/did.json":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","description":"Input data passed to the policy execution runtime.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"},"headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","type":"string"}}}},"schemes":["http"]}},"/policy/{group}/{policyName}/{version}/lock":{"post":{"tags":["policy"],"summary":"Lock policy","description":"Lock a policy so that it cannot be evaluated.","operationId":"policy#Lock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"}],"responses":{"200":{"description":"OK response."}},"schemes":["http"]},"delete":{"tags":["policy"],"summary":"Unlock policy","description":"Unlock a policy so it can be evaluated again.","operationId":"policy#Unlock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"}],"responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}}}} \ No newline at end of file +{"swagger":"2.0","info":{"title":"Policy Service","description":"The policy service exposes HTTP API for executing policies.","version":""},"host":"localhost:8081","consumes":["application/json","application/xml","application/gob"],"produces":["application/json","application/xml","application/gob"],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/policy/{group}/{policyName}/{version}/evaluation":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#1","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","description":"Input data passed to the policy execution runtime.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"},"headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","type":"string"}}}},"schemes":["http"]},"post":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#2","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","description":"Input data passed to the policy execution runtime.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"},"headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","type":"string"}}}},"schemes":["http"]}},"/policy/{group}/{policyName}/{version}/evaluation/did.json":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","required":false,"type":"string"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","required":false,"type":"integer"},{"name":"any","in":"body","description":"Input data passed to the policy execution runtime.","required":true,"schema":{"type":"string","format":"binary"}}],"responses":{"200":{"description":"OK response.","schema":{"type":"string","format":"binary"},"headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","type":"string"}}}},"schemes":["http"]}},"/policy/{group}/{policyName}/{version}/lock":{"post":{"tags":["policy"],"summary":"Lock policy","description":"Lock a policy so that it cannot be evaluated.","operationId":"policy#Lock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"}],"responses":{"200":{"description":"OK response."}},"schemes":["http"]},"delete":{"tags":["policy"],"summary":"Unlock policy","description":"Unlock a policy so it can be evaluated again.","operationId":"policy#Unlock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"type":"string"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"type":"string"},{"name":"version","in":"path","description":"Policy version.","required":true,"type":"string"}],"responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}},"schemes":["http"]}},"/v1/policies":{"get":{"tags":["policy"],"summary":"ListPolicies policy","description":"Listing all policies","operationId":"policy#ListPolicies","parameters":[{"name":"locked","in":"query","description":"return only locked or unlocked policies","required":false,"type":"boolean"},{"name":"rego","in":"query","description":"return the rego code of the policies also","required":false,"type":"boolean"},{"name":"data","in":"query","description":"return the data of the policies also","required":false,"type":"boolean"},{"name":"dataConfig","in":"query","description":"return the data config of the policies also","required":false,"type":"boolean"}],"responses":{"200":{"description":"OK response.","schema":{"$ref":"#/definitions/PolicyListPoliciesResponseBody","required":["policies"]}}},"schemes":["http"]}}},"definitions":{"PolicyListPoliciesResponseBody":{"title":"PolicyListPoliciesResponseBody","type":"object","properties":{"policies":{"type":"array","items":{"$ref":"#/definitions/PolicyResponseBody"},"description":"policy list","example":[{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."}]}},"example":{"policies":[{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."}]},"required":["policies"]},"PolicyResponseBody":{"title":"PolicyResponseBody","type":"object","properties":{"data":{"type":"string","description":"policy data","example":"Accusamus enim."},"dataConfig":{"type":"string","description":"policy data config","example":"Recusandae est rerum corrupti quia."},"group":{"type":"string","description":"policy group","example":"Optio quia et laborum."},"lastUpdate":{"type":"integer","description":"Last update (timestamp).","example":1029654258457164464,"format":"int64"},"locked":{"type":"boolean","description":"if it true gives locked status on the policy","example":true},"policyName":{"type":"string","description":"policy name","example":"Quia non voluptatibus error."},"rego":{"type":"string","description":"policy rego code","example":"Ut amet."},"version":{"type":"string","description":"policy version","example":"In libero perspiciatis voluptatum ut soluta."}},"example":{"data":"Totam officia necessitatibus tempore nulla animi.","dataConfig":"Consequatur vel rerum rem ipsam nam.","group":"Adipisci inventore ipsum voluptatibus recusandae.","lastUpdate":1724369781608544610,"locked":true,"policyName":"Architecto itaque voluptatum voluptas ad.","rego":"Ab perspiciatis voluptatem pariatur corporis est rem.","version":"Nisi distinctio vitae."},"required":["group","policyName","version","locked","lastUpdate"]}}} \ No newline at end of file diff --git a/gen/http/openapi.yaml b/gen/http/openapi.yaml index ec5b9852e71d46f3a82a3bc0e7ec7f80f3035d83..98e79a3a4474ac502a345b82fb704cd75eda7310 100644 --- a/gen/http/openapi.yaml +++ b/gen/http/openapi.yaml @@ -245,3 +245,163 @@ paths: description: OK response. schemes: - http + /v1/policies: + get: + tags: + - policy + summary: ListPolicies policy + description: Listing all policies + operationId: policy#ListPolicies + parameters: + - name: locked + in: query + description: return only locked or unlocked policies + required: false + type: boolean + - name: rego + in: query + description: return the rego code of the policies also + required: false + type: boolean + - name: data + in: query + description: return the data of the policies also + required: false + type: boolean + - name: dataConfig + in: query + description: return the data config of the policies also + required: false + type: boolean + responses: + "200": + description: OK response. + schema: + $ref: '#/definitions/PolicyListPoliciesResponseBody' + required: + - policies + schemes: + - http +definitions: + PolicyListPoliciesResponseBody: + title: PolicyListPoliciesResponseBody + type: object + properties: + policies: + type: array + items: + $ref: '#/definitions/PolicyResponseBody' + description: policy list + example: + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + example: + policies: + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + required: + - policies + PolicyResponseBody: + title: PolicyResponseBody + type: object + properties: + data: + type: string + description: policy data + example: Accusamus enim. + dataConfig: + type: string + description: policy data config + example: Recusandae est rerum corrupti quia. + group: + type: string + description: policy group + example: Optio quia et laborum. + lastUpdate: + type: integer + description: Last update (timestamp). + example: 1029654258457164464 + format: int64 + locked: + type: boolean + description: if it true gives locked status on the policy + example: true + policyName: + type: string + description: policy name + example: Quia non voluptatibus error. + rego: + type: string + description: policy rego code + example: Ut amet. + version: + type: string + description: policy version + example: In libero perspiciatis voluptatum ut soluta. + example: + data: Totam officia necessitatibus tempore nulla animi. + dataConfig: Consequatur vel rerum rem ipsam nam. + group: Adipisci inventore ipsum voluptatibus recusandae. + lastUpdate: 1724369781608544610 + locked: true + policyName: Architecto itaque voluptatum voluptas ad. + rego: Ab perspiciatis voluptatem pariatur corporis est rem. + version: Nisi distinctio vitae. + required: + - group + - policyName + - version + - locked + - lastUpdate diff --git a/gen/http/openapi/client/client.go b/gen/http/openapi/client/client.go index ade4d37ad4eaaec479fa6bbdcb33df2e2e1fc2ca..06201d72200f44983d96411f795b3852d64f8619 100644 --- a/gen/http/openapi/client/client.go +++ b/gen/http/openapi/client/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi client HTTP transport // diff --git a/gen/http/openapi/client/encode_decode.go b/gen/http/openapi/client/encode_decode.go index 030a3216666cfca3d452b2cff31f89763beb71b0..0ab3f5429d3f14949be4ebd7fdf20ad4069b6e8d 100644 --- a/gen/http/openapi/client/encode_decode.go +++ b/gen/http/openapi/client/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi HTTP client encoders and decoders // diff --git a/gen/http/openapi/client/paths.go b/gen/http/openapi/client/paths.go index 9e57a7084c7dadd1317f7c5a6f038a0d1f923f8c..234f7fd450e3ac5ad6d4752cc29f160150d5f241 100644 --- a/gen/http/openapi/client/paths.go +++ b/gen/http/openapi/client/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // HTTP request path constructors for the openapi service. // diff --git a/gen/http/openapi/client/types.go b/gen/http/openapi/client/types.go index cc8bb193e8af9880b32fdacfde6e7bca067ceadd..f2926f2154dbe33695ce29edb2c26c58d18b9299 100644 --- a/gen/http/openapi/client/types.go +++ b/gen/http/openapi/client/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi HTTP client types // diff --git a/gen/http/openapi/server/paths.go b/gen/http/openapi/server/paths.go index 259261038bac5e88b7baf94e767ad9f185a312a3..dde467b943e054efc0e02018b126290a353c2abb 100644 --- a/gen/http/openapi/server/paths.go +++ b/gen/http/openapi/server/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // HTTP request path constructors for the openapi service. // diff --git a/gen/http/openapi/server/server.go b/gen/http/openapi/server/server.go index 7f4f763b4095da1e215f4706bae2c3246e20b1f4..b9fe416a445588eca4c4817aa09e65687199453f 100644 --- a/gen/http/openapi/server/server.go +++ b/gen/http/openapi/server/server.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi HTTP server // diff --git a/gen/http/openapi/server/types.go b/gen/http/openapi/server/types.go index d122dd97eb38fd195a7e07f9678ab33e037791d1..c0dde6f3ebd6d5f04ca80b81559b25bc4bf32487 100644 --- a/gen/http/openapi/server/types.go +++ b/gen/http/openapi/server/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi HTTP server types // diff --git a/gen/http/openapi3.json b/gen/http/openapi3.json index 6f1ce7b8aaf5d3efd3a3a3ce5b094d42b500bf1a..daaaba2b78e0235fe78131ad93a11fae89b330f4 100644 --- a/gen/http/openapi3.json +++ b/gen/http/openapi3.json @@ -1 +1 @@ -{"openapi":"3.0.3","info":{"title":"Policy Service","description":"The policy service exposes HTTP API for executing policies.","version":"1.0"},"servers":[{"url":"http://localhost:8081","description":"Policy Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/policy/{group}/{policyName}/{version}/evaluation":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#1","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"example"},"example":"example"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"example"},"example":"example"},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"1.0"},"example":"1.0"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","allowEmptyValue":true,"schema":{"type":"string","description":"EvaluationID allows overwriting the randomly generated evaluationID","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Policy result cache TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"description":"Input data passed to the policy execution runtime.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Input data passed to the policy execution runtime.","example":"Aliquam atque voluptatum ut dolorem.","format":"binary"},"example":"Sint nam voluptatem ea consequatur similique et."}}},"responses":{"200":{"description":"OK response.","headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","required":true,"schema":{"type":"string","description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","example":"Non mollitia nesciunt impedit facere."},"example":"Accusamus autem sequi."}},"content":{"application/json":{"schema":{"type":"string","description":"Arbitrary JSON response.","example":"Aut facere veniam repudiandae id.","format":"binary"},"example":"Et nulla."}}}}},"post":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#2","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"example"},"example":"example"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"example"},"example":"example"},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"1.0"},"example":"1.0"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","allowEmptyValue":true,"schema":{"type":"string","description":"EvaluationID allows overwriting the randomly generated evaluationID","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Policy result cache TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"description":"Input data passed to the policy execution runtime.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Input data passed to the policy execution runtime.","example":"Aliquam atque voluptatum ut dolorem.","format":"binary"},"example":"In quis nesciunt autem et."}}},"responses":{"200":{"description":"OK response.","headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","required":true,"schema":{"type":"string","description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","example":"Sunt in et quia cum."},"example":"Qui non quia."}},"content":{"application/json":{"schema":{"type":"string","description":"Arbitrary JSON response.","example":"Aut facere veniam repudiandae id.","format":"binary"},"example":"Error maxime quasi quia non voluptatibus error."}}}}}},"/policy/{group}/{policyName}/{version}/evaluation/did.json":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"example"},"example":"example"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"example"},"example":"example"},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"1.0"},"example":"1.0"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","allowEmptyValue":true,"schema":{"type":"string","description":"EvaluationID allows overwriting the randomly generated evaluationID","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Policy result cache TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"description":"Input data passed to the policy execution runtime.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Input data passed to the policy execution runtime.","example":"Aliquam atque voluptatum ut dolorem.","format":"binary"},"example":"Aut minus alias."}}},"responses":{"200":{"description":"OK response.","headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","required":true,"schema":{"type":"string","description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","example":"At eos facilis molestias in voluptas rem."},"example":"Dolorem cumque laborum quis nesciunt."}},"content":{"application/json":{"schema":{"type":"string","description":"Arbitrary JSON response.","example":"Aut facere veniam repudiandae id.","format":"binary"},"example":"Aut voluptas."}}}}}},"/policy/{group}/{policyName}/{version}/lock":{"delete":{"tags":["policy"],"summary":"Unlock policy","description":"Unlock a policy so it can be evaluated again.","operationId":"policy#Unlock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"Voluptas ad corporis adipisci inventore ipsum."},"example":"Recusandae dolorum nisi distinctio vitae ad."},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"Perspiciatis voluptatem."},"example":"Corporis est rem."},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"Totam officia necessitatibus tempore nulla animi."},"example":"Consequatur vel rerum rem ipsam nam."}],"responses":{"200":{"description":"OK response."}}},"post":{"tags":["policy"],"summary":"Lock policy","description":"Lock a policy so that it cannot be evaluated.","operationId":"policy#Lock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"Optio quia et laborum."},"example":"In libero perspiciatis voluptatum ut soluta."},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"Ut amet."},"example":"Accusamus enim."},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"Recusandae est rerum corrupti quia."},"example":"Quam dolores architecto itaque."}],"responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}}},"components":{},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"policy","description":"Policy Service provides evaluation of policies through Open Policy Agent."}]} \ No newline at end of file +{"openapi":"3.0.3","info":{"title":"Policy Service","description":"The policy service exposes HTTP API for executing policies.","version":"1.0"},"servers":[{"url":"http://localhost:8081","description":"Policy Server"}],"paths":{"/liveness":{"get":{"tags":["health"],"summary":"Liveness health","operationId":"health#Liveness","responses":{"200":{"description":"OK response."}}}},"/policy/{group}/{policyName}/{version}/evaluation":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#1","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"example"},"example":"example"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"example"},"example":"example"},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"1.0"},"example":"1.0"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","allowEmptyValue":true,"schema":{"type":"string","description":"EvaluationID allows overwriting the randomly generated evaluationID","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Policy result cache TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"description":"Input data passed to the policy execution runtime.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Input data passed to the policy execution runtime.","example":"Aperiam dolores reiciendis ut voluptate amet.","format":"binary"},"example":"Et quis nisi vitae iure."}}},"responses":{"200":{"description":"OK response.","headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","required":true,"schema":{"type":"string","description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","example":"Sed sit."},"example":"Et eaque."}},"content":{"application/json":{"schema":{"type":"string","description":"Arbitrary JSON response.","example":"Aut et.","format":"binary"},"example":"Et mollitia."}}}}},"post":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate#2","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"example"},"example":"example"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"example"},"example":"example"},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"1.0"},"example":"1.0"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","allowEmptyValue":true,"schema":{"type":"string","description":"EvaluationID allows overwriting the randomly generated evaluationID","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Policy result cache TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"description":"Input data passed to the policy execution runtime.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Input data passed to the policy execution runtime.","example":"Aperiam dolores reiciendis ut voluptate amet.","format":"binary"},"example":"Non quo ut molestias rerum sunt."}}},"responses":{"200":{"description":"OK response.","headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","required":true,"schema":{"type":"string","description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","example":"Omnis dolores totam voluptatem rerum."},"example":"Est impedit."}},"content":{"application/json":{"schema":{"type":"string","description":"Arbitrary JSON response.","example":"Aut et.","format":"binary"},"example":"Consequatur ut suscipit."}}}}}},"/policy/{group}/{policyName}/{version}/evaluation/did.json":{"get":{"tags":["policy"],"summary":"Evaluate policy","description":"Evaluate executes a policy with the given 'data' as input.","operationId":"policy#Evaluate","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"example"},"example":"example"},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"example"},"example":"example"},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"1.0"},"example":"1.0"},{"name":"x-evaluation-id","in":"header","description":"EvaluationID allows overwriting the randomly generated evaluationID","allowEmptyValue":true,"schema":{"type":"string","description":"EvaluationID allows overwriting the randomly generated evaluationID","example":"did:web:example.com"},"example":"did:web:example.com"},{"name":"x-cache-ttl","in":"header","description":"Policy result cache TTL in seconds","allowEmptyValue":true,"schema":{"type":"integer","description":"Policy result cache TTL in seconds","example":60,"format":"int64"},"example":60}],"requestBody":{"description":"Input data passed to the policy execution runtime.","required":true,"content":{"application/json":{"schema":{"type":"string","description":"Input data passed to the policy execution runtime.","example":"Aperiam dolores reiciendis ut voluptate amet.","format":"binary"},"example":"Dolore laborum aperiam aut."}}},"responses":{"200":{"description":"OK response.","headers":{"ETag":{"description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","required":true,"schema":{"type":"string","description":"ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache.","example":"Dolorum suscipit quae."},"example":"Accusamus et voluptatibus cupiditate ea."}},"content":{"application/json":{"schema":{"type":"string","description":"Arbitrary JSON response.","example":"Aut et.","format":"binary"},"example":"Inventore ut doloremque recusandae."}}}}}},"/policy/{group}/{policyName}/{version}/lock":{"delete":{"tags":["policy"],"summary":"Unlock policy","description":"Unlock a policy so it can be evaluated again.","operationId":"policy#Unlock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"Explicabo expedita ipsum minus ipsam at vel."},"example":"Nisi et praesentium ut reiciendis."},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"Dolorum cupiditate provident."},"example":"Dolor dolorem modi aut officiis veritatis impedit."},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"Recusandae eligendi."},"example":"Id quibusdam quia deserunt officiis."}],"responses":{"200":{"description":"OK response."}}},"post":{"tags":["policy"],"summary":"Lock policy","description":"Lock a policy so that it cannot be evaluated.","operationId":"policy#Lock","parameters":[{"name":"group","in":"path","description":"Policy group.","required":true,"schema":{"type":"string","description":"Policy group.","example":"Neque et sed modi accusantium."},"example":"Rerum asperiores nulla."},{"name":"policyName","in":"path","description":"Policy name.","required":true,"schema":{"type":"string","description":"Policy name.","example":"Tenetur rerum necessitatibus fugit."},"example":"Ut velit aut nobis repellendus."},{"name":"version","in":"path","description":"Policy version.","required":true,"schema":{"type":"string","description":"Policy version.","example":"Rem et occaecati quam."},"example":"Laborum harum voluptate et ut similique doloremque."}],"responses":{"200":{"description":"OK response."}}}},"/readiness":{"get":{"tags":["health"],"summary":"Readiness health","operationId":"health#Readiness","responses":{"200":{"description":"OK response."}}}},"/v1/policies":{"get":{"tags":["policy"],"summary":"ListPolicies policy","description":"Listing all policies","operationId":"policy#ListPolicies","parameters":[{"name":"locked","in":"query","description":"return only locked or unlocked policies","allowEmptyValue":true,"schema":{"type":"boolean","description":"return only locked or unlocked policies","example":false},"example":true},{"name":"rego","in":"query","description":"return the rego code of the policies also","allowEmptyValue":true,"schema":{"type":"boolean","description":"return the rego code of the policies also","example":false},"example":true},{"name":"data","in":"query","description":"return the data of the policies also","allowEmptyValue":true,"schema":{"type":"boolean","description":"return the data of the policies also","example":false},"example":false},{"name":"dataConfig","in":"query","description":"return the data config of the policies also","allowEmptyValue":true,"schema":{"type":"boolean","description":"return the data config of the policies also","example":false},"example":true}],"responses":{"200":{"description":"OK response.","content":{"application/json":{"schema":{"$ref":"#/components/schemas/PoliciesResult"},"example":{"policies":[{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."}]}}}}}}}},"components":{"schemas":{"PoliciesResult":{"type":"object","properties":{"policies":{"type":"array","items":{"$ref":"#/components/schemas/Policy"},"description":"policy list","example":[{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."}]}},"example":{"policies":[{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."},{"data":"Commodi nemo fugiat id praesentium accusantium expedita.","dataConfig":"Qui non quia.","group":"Sequi adipisci et nulla.","lastUpdate":8181859392515170659,"locked":false,"policyName":"Consequatur accusamus.","rego":"Sunt in et quia cum.","version":"In quis nesciunt autem et."}]},"required":["policies"]},"Policy":{"type":"object","properties":{"data":{"type":"string","description":"policy data","example":"Ipsa ad voluptatum maxime ut."},"dataConfig":{"type":"string","description":"policy data config","example":"Aut asperiores."},"group":{"type":"string","description":"policy group","example":"Veritatis quam qui nostrum eaque."},"lastUpdate":{"type":"integer","description":"Last update (timestamp).","example":1131015782715696616,"format":"int64"},"locked":{"type":"boolean","description":"if it true gives locked status on the policy","example":false},"policyName":{"type":"string","description":"policy name","example":"Maiores et minus."},"rego":{"type":"string","description":"policy rego code","example":"Delectus rerum molestiae possimus cum laboriosam."},"version":{"type":"string","description":"policy version","example":"Et dolores."}},"example":{"data":"Similique architecto.","dataConfig":"Sunt ut est ut molestias.","group":"Error minus vel voluptate quasi.","lastUpdate":2308837710267791288,"locked":true,"policyName":"Omnis molestiae tempora sed repellendus.","rego":"Vel sunt dolorem ea architecto iure.","version":"Debitis consectetur."},"required":["group","policyName","version","locked","lastUpdate"]}}},"tags":[{"name":"health","description":"Health service provides health check endpoints."},{"name":"policy","description":"Policy Service provides evaluation of policies through Open Policy Agent."}]} \ No newline at end of file diff --git a/gen/http/openapi3.yaml b/gen/http/openapi3.yaml index 30ff1a7abf17dd9d04faba301bbb7c1befba35f3..4767e0ca443930bfafdafda0ae1695ef5b253fe4 100644 --- a/gen/http/openapi3.yaml +++ b/gen/http/openapi3.yaml @@ -78,9 +78,9 @@ paths: schema: type: string description: Input data passed to the policy execution runtime. - example: Aliquam atque voluptatum ut dolorem. + example: Aperiam dolores reiciendis ut voluptate amet. format: binary - example: Sint nam voluptatem ea consequatur similique et. + example: Et quis nisi vitae iure. responses: "200": description: OK response. @@ -91,16 +91,16 @@ paths: schema: type: string description: ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache. - example: Non mollitia nesciunt impedit facere. - example: Accusamus autem sequi. + example: Sed sit. + example: Et eaque. content: application/json: schema: type: string description: Arbitrary JSON response. - example: Aut facere veniam repudiandae id. + example: Aut et. format: binary - example: Et nulla. + example: Et mollitia. post: tags: - policy @@ -162,9 +162,9 @@ paths: schema: type: string description: Input data passed to the policy execution runtime. - example: Aliquam atque voluptatum ut dolorem. + example: Aperiam dolores reiciendis ut voluptate amet. format: binary - example: In quis nesciunt autem et. + example: Non quo ut molestias rerum sunt. responses: "200": description: OK response. @@ -175,16 +175,16 @@ paths: schema: type: string description: ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache. - example: Sunt in et quia cum. - example: Qui non quia. + example: Omnis dolores totam voluptatem rerum. + example: Est impedit. content: application/json: schema: type: string description: Arbitrary JSON response. - example: Aut facere veniam repudiandae id. + example: Aut et. format: binary - example: Error maxime quasi quia non voluptatibus error. + example: Consequatur ut suscipit. /policy/{group}/{policyName}/{version}/evaluation/did.json: get: tags: @@ -247,9 +247,9 @@ paths: schema: type: string description: Input data passed to the policy execution runtime. - example: Aliquam atque voluptatum ut dolorem. + example: Aperiam dolores reiciendis ut voluptate amet. format: binary - example: Aut minus alias. + example: Dolore laborum aperiam aut. responses: "200": description: OK response. @@ -260,16 +260,16 @@ paths: schema: type: string description: ETag contains unique identifier of the policy evaluation and can be used to later retrieve the results from Cache. - example: At eos facilis molestias in voluptas rem. - example: Dolorem cumque laborum quis nesciunt. + example: Dolorum suscipit quae. + example: Accusamus et voluptatibus cupiditate ea. content: application/json: schema: type: string description: Arbitrary JSON response. - example: Aut facere veniam repudiandae id. + example: Aut et. format: binary - example: Aut voluptas. + example: Inventore ut doloremque recusandae. /policy/{group}/{policyName}/{version}/lock: delete: tags: @@ -285,8 +285,8 @@ paths: schema: type: string description: Policy group. - example: Voluptas ad corporis adipisci inventore ipsum. - example: Recusandae dolorum nisi distinctio vitae ad. + example: Explicabo expedita ipsum minus ipsam at vel. + example: Nisi et praesentium ut reiciendis. - name: policyName in: path description: Policy name. @@ -294,8 +294,8 @@ paths: schema: type: string description: Policy name. - example: Perspiciatis voluptatem. - example: Corporis est rem. + example: Dolorum cupiditate provident. + example: Dolor dolorem modi aut officiis veritatis impedit. - name: version in: path description: Policy version. @@ -303,8 +303,8 @@ paths: schema: type: string description: Policy version. - example: Totam officia necessitatibus tempore nulla animi. - example: Consequatur vel rerum rem ipsam nam. + example: Recusandae eligendi. + example: Id quibusdam quia deserunt officiis. responses: "200": description: OK response. @@ -322,8 +322,8 @@ paths: schema: type: string description: Policy group. - example: Optio quia et laborum. - example: In libero perspiciatis voluptatum ut soluta. + example: Neque et sed modi accusantium. + example: Rerum asperiores nulla. - name: policyName in: path description: Policy name. @@ -331,8 +331,8 @@ paths: schema: type: string description: Policy name. - example: Ut amet. - example: Accusamus enim. + example: Tenetur rerum necessitatibus fugit. + example: Ut velit aut nobis repellendus. - name: version in: path description: Policy version. @@ -340,8 +340,8 @@ paths: schema: type: string description: Policy version. - example: Recusandae est rerum corrupti quia. - example: Quam dolores architecto itaque. + example: Rem et occaecati quam. + example: Laborum harum voluptate et ut similique doloremque. responses: "200": description: OK response. @@ -354,7 +354,213 @@ paths: responses: "200": description: OK response. -components: {} + /v1/policies: + get: + tags: + - policy + summary: ListPolicies policy + description: Listing all policies + operationId: policy#ListPolicies + parameters: + - name: locked + in: query + description: return only locked or unlocked policies + allowEmptyValue: true + schema: + type: boolean + description: return only locked or unlocked policies + example: false + example: true + - name: rego + in: query + description: return the rego code of the policies also + allowEmptyValue: true + schema: + type: boolean + description: return the rego code of the policies also + example: false + example: true + - name: data + in: query + description: return the data of the policies also + allowEmptyValue: true + schema: + type: boolean + description: return the data of the policies also + example: false + example: false + - name: dataConfig + in: query + description: return the data config of the policies also + allowEmptyValue: true + schema: + type: boolean + description: return the data config of the policies also + example: false + example: true + responses: + "200": + description: OK response. + content: + application/json: + schema: + $ref: '#/components/schemas/PoliciesResult' + example: + policies: + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. +components: + schemas: + PoliciesResult: + type: object + properties: + policies: + type: array + items: + $ref: '#/components/schemas/Policy' + description: policy list + example: + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + example: + policies: + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + - data: Commodi nemo fugiat id praesentium accusantium expedita. + dataConfig: Qui non quia. + group: Sequi adipisci et nulla. + lastUpdate: 8181859392515170659 + locked: false + policyName: Consequatur accusamus. + rego: Sunt in et quia cum. + version: In quis nesciunt autem et. + required: + - policies + Policy: + type: object + properties: + data: + type: string + description: policy data + example: Ipsa ad voluptatum maxime ut. + dataConfig: + type: string + description: policy data config + example: Aut asperiores. + group: + type: string + description: policy group + example: Veritatis quam qui nostrum eaque. + lastUpdate: + type: integer + description: Last update (timestamp). + example: 1131015782715696616 + format: int64 + locked: + type: boolean + description: if it true gives locked status on the policy + example: false + policyName: + type: string + description: policy name + example: Maiores et minus. + rego: + type: string + description: policy rego code + example: Delectus rerum molestiae possimus cum laboriosam. + version: + type: string + description: policy version + example: Et dolores. + example: + data: Similique architecto. + dataConfig: Sunt ut est ut molestias. + group: Error minus vel voluptate quasi. + lastUpdate: 2308837710267791288 + locked: true + policyName: Omnis molestiae tempora sed repellendus. + rego: Vel sunt dolorem ea architecto iure. + version: Debitis consectetur. + required: + - group + - policyName + - version + - locked + - lastUpdate tags: - name: health description: Health service provides health check endpoints. diff --git a/gen/http/policy/client/cli.go b/gen/http/policy/client/cli.go index ebce3c247deb7a50c0c95f9b5b1dd8c742b4f6a8..c032452f7ed3cb2596000498d6a11acabb8f2773 100644 --- a/gen/http/policy/client/cli.go +++ b/gen/http/policy/client/cli.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP client CLI support package // @@ -23,7 +23,7 @@ func BuildEvaluatePayload(policyEvaluateBody string, policyEvaluateGroup string, { err = json.Unmarshal([]byte(policyEvaluateBody), &body) if err != nil { - return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Ipsum nihil quo.\"") + return nil, fmt.Errorf("invalid JSON for body, \nerror: %s, \nexample of valid JSON:\n%s", err, "\"Quibusdam ab repellendus in illum.\"") } } var group string @@ -114,3 +114,60 @@ func BuildUnlockPayload(policyUnlockGroup string, policyUnlockPolicyName string, return v, nil } + +// BuildListPoliciesPayload builds the payload for the policy ListPolicies +// endpoint from CLI flags. +func BuildListPoliciesPayload(policyListPoliciesLocked string, policyListPoliciesRego string, policyListPoliciesData string, policyListPoliciesDataConfig string) (*policy.PoliciesRequest, error) { + var err error + var locked *bool + { + if policyListPoliciesLocked != "" { + var val bool + val, err = strconv.ParseBool(policyListPoliciesLocked) + locked = &val + if err != nil { + return nil, fmt.Errorf("invalid value for locked, must be BOOL") + } + } + } + var rego *bool + { + if policyListPoliciesRego != "" { + var val bool + val, err = strconv.ParseBool(policyListPoliciesRego) + rego = &val + if err != nil { + return nil, fmt.Errorf("invalid value for rego, must be BOOL") + } + } + } + var data *bool + { + if policyListPoliciesData != "" { + var val bool + val, err = strconv.ParseBool(policyListPoliciesData) + data = &val + if err != nil { + return nil, fmt.Errorf("invalid value for data, must be BOOL") + } + } + } + var dataConfig *bool + { + if policyListPoliciesDataConfig != "" { + var val bool + val, err = strconv.ParseBool(policyListPoliciesDataConfig) + dataConfig = &val + if err != nil { + return nil, fmt.Errorf("invalid value for dataConfig, must be BOOL") + } + } + } + v := &policy.PoliciesRequest{} + v.Locked = locked + v.Rego = rego + v.Data = data + v.DataConfig = dataConfig + + return v, nil +} diff --git a/gen/http/policy/client/client.go b/gen/http/policy/client/client.go index af52c1bcf36168d5573e3774a9cb09415017673a..afcf58c9ff68a7f4a4f708f7b555a90114059207 100644 --- a/gen/http/policy/client/client.go +++ b/gen/http/policy/client/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy client HTTP transport // @@ -27,6 +27,10 @@ type Client struct { // Unlock Doer is the HTTP client used to make requests to the Unlock endpoint. UnlockDoer goahttp.Doer + // ListPolicies Doer is the HTTP client used to make requests to the + // ListPolicies endpoint. + ListPoliciesDoer goahttp.Doer + // RestoreResponseBody controls whether the response bodies are reset after // decoding so they can be read again. RestoreResponseBody bool @@ -50,6 +54,7 @@ func NewClient( EvaluateDoer: doer, LockDoer: doer, UnlockDoer: doer, + ListPoliciesDoer: doer, RestoreResponseBody: restoreBody, scheme: scheme, host: host, @@ -119,3 +124,27 @@ func (c *Client) Unlock() goa.Endpoint { return decodeResponse(resp) } } + +// ListPolicies returns an endpoint that makes HTTP requests to the policy +// service ListPolicies server. +func (c *Client) ListPolicies() goa.Endpoint { + var ( + encodeRequest = EncodeListPoliciesRequest(c.encoder) + decodeResponse = DecodeListPoliciesResponse(c.decoder, c.RestoreResponseBody) + ) + return func(ctx context.Context, v any) (any, error) { + req, err := c.BuildListPoliciesRequest(ctx, v) + if err != nil { + return nil, err + } + err = encodeRequest(req, v) + if err != nil { + return nil, err + } + resp, err := c.ListPoliciesDoer.Do(req) + if err != nil { + return nil, goahttp.ErrRequestError("policy", "ListPolicies", err) + } + return decodeResponse(resp) + } +} diff --git a/gen/http/policy/client/encode_decode.go b/gen/http/policy/client/encode_decode.go index 3820af7992a3d271eb71a7b0520b5370cbffff1d..417538d82bfd8fffd8819c87b9aab48745cd6445 100644 --- a/gen/http/policy/client/encode_decode.go +++ b/gen/http/policy/client/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP client encoders and decoders // @@ -10,6 +10,7 @@ package client import ( "bytes" "context" + "fmt" "io" "net/http" "net/url" @@ -232,3 +233,101 @@ func DecodeUnlockResponse(decoder func(*http.Response) goahttp.Decoder, restoreB } } } + +// BuildListPoliciesRequest instantiates a HTTP request object with method and +// path set to call the "policy" service "ListPolicies" endpoint +func (c *Client) BuildListPoliciesRequest(ctx context.Context, v any) (*http.Request, error) { + u := &url.URL{Scheme: c.scheme, Host: c.host, Path: ListPoliciesPolicyPath()} + req, err := http.NewRequest("GET", u.String(), nil) + if err != nil { + return nil, goahttp.ErrInvalidURL("policy", "ListPolicies", u.String(), err) + } + if ctx != nil { + req = req.WithContext(ctx) + } + + return req, nil +} + +// EncodeListPoliciesRequest returns an encoder for requests sent to the policy +// ListPolicies server. +func EncodeListPoliciesRequest(encoder func(*http.Request) goahttp.Encoder) func(*http.Request, any) error { + return func(req *http.Request, v any) error { + p, ok := v.(*policy.PoliciesRequest) + if !ok { + return goahttp.ErrInvalidType("policy", "ListPolicies", "*policy.PoliciesRequest", v) + } + values := req.URL.Query() + if p.Locked != nil { + values.Add("locked", fmt.Sprintf("%v", *p.Locked)) + } + if p.Rego != nil { + values.Add("rego", fmt.Sprintf("%v", *p.Rego)) + } + if p.Data != nil { + values.Add("data", fmt.Sprintf("%v", *p.Data)) + } + if p.DataConfig != nil { + values.Add("dataConfig", fmt.Sprintf("%v", *p.DataConfig)) + } + req.URL.RawQuery = values.Encode() + return nil + } +} + +// DecodeListPoliciesResponse returns a decoder for responses returned by the +// policy ListPolicies endpoint. restoreBody controls whether the response body +// should be restored after having been read. +func DecodeListPoliciesResponse(decoder func(*http.Response) goahttp.Decoder, restoreBody bool) func(*http.Response) (any, error) { + return func(resp *http.Response) (any, error) { + if restoreBody { + b, err := io.ReadAll(resp.Body) + if err != nil { + return nil, err + } + resp.Body = io.NopCloser(bytes.NewBuffer(b)) + defer func() { + resp.Body = io.NopCloser(bytes.NewBuffer(b)) + }() + } else { + defer resp.Body.Close() + } + switch resp.StatusCode { + case http.StatusOK: + var ( + body ListPoliciesResponseBody + err error + ) + err = decoder(resp).Decode(&body) + if err != nil { + return nil, goahttp.ErrDecodingError("policy", "ListPolicies", err) + } + err = ValidateListPoliciesResponseBody(&body) + if err != nil { + return nil, goahttp.ErrValidationError("policy", "ListPolicies", err) + } + res := NewListPoliciesPoliciesResultOK(&body) + return res, nil + default: + body, _ := io.ReadAll(resp.Body) + return nil, goahttp.ErrInvalidResponse("policy", "ListPolicies", resp.StatusCode, string(body)) + } + } +} + +// unmarshalPolicyResponseBodyToPolicyPolicy builds a value of type +// *policy.Policy from a value of type *PolicyResponseBody. +func unmarshalPolicyResponseBodyToPolicyPolicy(v *PolicyResponseBody) *policy.Policy { + res := &policy.Policy{ + PolicyName: *v.PolicyName, + Group: *v.Group, + Version: *v.Version, + Rego: v.Rego, + Data: v.Data, + DataConfig: v.DataConfig, + Locked: *v.Locked, + LastUpdate: *v.LastUpdate, + } + + return res +} diff --git a/gen/http/policy/client/paths.go b/gen/http/policy/client/paths.go index 5515ad1e4dcfba965601db0a69620b8d45136826..a5da8845a897c497d06e6dc0ed55e98437560100 100644 --- a/gen/http/policy/client/paths.go +++ b/gen/http/policy/client/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // HTTP request path constructors for the policy service. // @@ -35,3 +35,8 @@ func LockPolicyPath(group string, policyName string, version string) string { func UnlockPolicyPath(group string, policyName string, version string) string { return fmt.Sprintf("/policy/%v/%v/%v/lock", group, policyName, version) } + +// ListPoliciesPolicyPath returns the URL path to the policy service ListPolicies HTTP endpoint. +func ListPoliciesPolicyPath() string { + return "/v1/policies" +} diff --git a/gen/http/policy/client/types.go b/gen/http/policy/client/types.go index e23db62a94b78bc48f8e6d0f82423b80ec6586ef..9956549073f5e62ab0cbbe0fb1df3f5bfeb05d66 100644 --- a/gen/http/policy/client/types.go +++ b/gen/http/policy/client/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP client types // @@ -9,8 +9,36 @@ package client import ( policy "gitlab.eclipse.org/eclipse/xfsc/tsa/policy/gen/policy" + goa "goa.design/goa/v3/pkg" ) +// ListPoliciesResponseBody is the type of the "policy" service "ListPolicies" +// endpoint HTTP response body. +type ListPoliciesResponseBody struct { + // policy list + Policies []*PolicyResponseBody `form:"policies,omitempty" json:"policies,omitempty" xml:"policies,omitempty"` +} + +// PolicyResponseBody is used to define fields on response body types. +type PolicyResponseBody struct { + // policy name + PolicyName *string `form:"policyName,omitempty" json:"policyName,omitempty" xml:"policyName,omitempty"` + // policy group + Group *string `form:"group,omitempty" json:"group,omitempty" xml:"group,omitempty"` + // policy version + Version *string `form:"version,omitempty" json:"version,omitempty" xml:"version,omitempty"` + // policy rego code + Rego *string `form:"rego,omitempty" json:"rego,omitempty" xml:"rego,omitempty"` + // policy data + Data *string `form:"data,omitempty" json:"data,omitempty" xml:"data,omitempty"` + // policy data config + DataConfig *string `form:"dataConfig,omitempty" json:"dataConfig,omitempty" xml:"dataConfig,omitempty"` + // if it true gives locked status on the policy + Locked *bool `form:"locked,omitempty" json:"locked,omitempty" xml:"locked,omitempty"` + // Last update (timestamp). + LastUpdate *int64 `form:"lastUpdate,omitempty" json:"lastUpdate,omitempty" xml:"lastUpdate,omitempty"` +} + // NewEvaluateResultOK builds a "policy" service "Evaluate" endpoint result // from a HTTP "OK" response. func NewEvaluateResultOK(body any, eTag string) *policy.EvaluateResult { @@ -22,3 +50,51 @@ func NewEvaluateResultOK(body any, eTag string) *policy.EvaluateResult { return res } + +// NewListPoliciesPoliciesResultOK builds a "policy" service "ListPolicies" +// endpoint result from a HTTP "OK" response. +func NewListPoliciesPoliciesResultOK(body *ListPoliciesResponseBody) *policy.PoliciesResult { + v := &policy.PoliciesResult{} + v.Policies = make([]*policy.Policy, len(body.Policies)) + for i, val := range body.Policies { + v.Policies[i] = unmarshalPolicyResponseBodyToPolicyPolicy(val) + } + + return v +} + +// ValidateListPoliciesResponseBody runs the validations defined on +// ListPoliciesResponseBody +func ValidateListPoliciesResponseBody(body *ListPoliciesResponseBody) (err error) { + if body.Policies == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("policies", "body")) + } + for _, e := range body.Policies { + if e != nil { + if err2 := ValidatePolicyResponseBody(e); err2 != nil { + err = goa.MergeErrors(err, err2) + } + } + } + return +} + +// ValidatePolicyResponseBody runs the validations defined on PolicyResponseBody +func ValidatePolicyResponseBody(body *PolicyResponseBody) (err error) { + if body.Group == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("group", "body")) + } + if body.PolicyName == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("policyName", "body")) + } + if body.Version == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("version", "body")) + } + if body.Locked == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("locked", "body")) + } + if body.LastUpdate == nil { + err = goa.MergeErrors(err, goa.MissingFieldError("lastUpdate", "body")) + } + return +} diff --git a/gen/http/policy/server/encode_decode.go b/gen/http/policy/server/encode_decode.go index b1cd9c6750ca7dbdaeec2c1f45d52092cb4de6e1..8556a4be5eb12a836422f45341b5a3b9d0cf2cc5 100644 --- a/gen/http/policy/server/encode_decode.go +++ b/gen/http/policy/server/encode_decode.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP server encoders and decoders // @@ -141,3 +141,92 @@ func DecodeUnlockRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp. return payload, nil } } + +// EncodeListPoliciesResponse returns an encoder for responses returned by the +// policy ListPolicies endpoint. +func EncodeListPoliciesResponse(encoder func(context.Context, http.ResponseWriter) goahttp.Encoder) func(context.Context, http.ResponseWriter, any) error { + return func(ctx context.Context, w http.ResponseWriter, v any) error { + res, _ := v.(*policy.PoliciesResult) + enc := encoder(ctx, w) + body := NewListPoliciesResponseBody(res) + w.WriteHeader(http.StatusOK) + return enc.Encode(body) + } +} + +// DecodeListPoliciesRequest returns a decoder for requests sent to the policy +// ListPolicies endpoint. +func DecodeListPoliciesRequest(mux goahttp.Muxer, decoder func(*http.Request) goahttp.Decoder) func(*http.Request) (any, error) { + return func(r *http.Request) (any, error) { + var ( + locked *bool + rego *bool + data *bool + dataConfig *bool + err error + ) + { + lockedRaw := r.URL.Query().Get("locked") + if lockedRaw != "" { + v, err2 := strconv.ParseBool(lockedRaw) + if err2 != nil { + err = goa.MergeErrors(err, goa.InvalidFieldTypeError("locked", lockedRaw, "boolean")) + } + locked = &v + } + } + { + regoRaw := r.URL.Query().Get("rego") + if regoRaw != "" { + v, err2 := strconv.ParseBool(regoRaw) + if err2 != nil { + err = goa.MergeErrors(err, goa.InvalidFieldTypeError("rego", regoRaw, "boolean")) + } + rego = &v + } + } + { + dataRaw := r.URL.Query().Get("data") + if dataRaw != "" { + v, err2 := strconv.ParseBool(dataRaw) + if err2 != nil { + err = goa.MergeErrors(err, goa.InvalidFieldTypeError("data", dataRaw, "boolean")) + } + data = &v + } + } + { + dataConfigRaw := r.URL.Query().Get("dataConfig") + if dataConfigRaw != "" { + v, err2 := strconv.ParseBool(dataConfigRaw) + if err2 != nil { + err = goa.MergeErrors(err, goa.InvalidFieldTypeError("dataConfig", dataConfigRaw, "boolean")) + } + dataConfig = &v + } + } + if err != nil { + return nil, err + } + payload := NewListPoliciesPoliciesRequest(locked, rego, data, dataConfig) + + return payload, nil + } +} + +// marshalPolicyPolicyToPolicyResponseBody builds a value of type +// *PolicyResponseBody from a value of type *policy.Policy. +func marshalPolicyPolicyToPolicyResponseBody(v *policy.Policy) *PolicyResponseBody { + res := &PolicyResponseBody{ + PolicyName: v.PolicyName, + Group: v.Group, + Version: v.Version, + Rego: v.Rego, + Data: v.Data, + DataConfig: v.DataConfig, + Locked: v.Locked, + LastUpdate: v.LastUpdate, + } + + return res +} diff --git a/gen/http/policy/server/paths.go b/gen/http/policy/server/paths.go index 8d60f4e7c5a3ba444bb90dadde4caca8e46b7512..f224fbe4c1bc4f5ef5c1d86d22d95f746c08feec 100644 --- a/gen/http/policy/server/paths.go +++ b/gen/http/policy/server/paths.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // HTTP request path constructors for the policy service. // @@ -35,3 +35,8 @@ func LockPolicyPath(group string, policyName string, version string) string { func UnlockPolicyPath(group string, policyName string, version string) string { return fmt.Sprintf("/policy/%v/%v/%v/lock", group, policyName, version) } + +// ListPoliciesPolicyPath returns the URL path to the policy service ListPolicies HTTP endpoint. +func ListPoliciesPolicyPath() string { + return "/v1/policies" +} diff --git a/gen/http/policy/server/server.go b/gen/http/policy/server/server.go index e135942888969cbb123b1c2401958acdbc18b4eb..2043d7396d4c8ca1b50983eda1b7664ee9e11a2b 100644 --- a/gen/http/policy/server/server.go +++ b/gen/http/policy/server/server.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP server // @@ -18,10 +18,11 @@ import ( // Server lists the policy service endpoint HTTP handlers. type Server struct { - Mounts []*MountPoint - Evaluate http.Handler - Lock http.Handler - Unlock http.Handler + Mounts []*MountPoint + Evaluate http.Handler + Lock http.Handler + Unlock http.Handler + ListPolicies http.Handler } // MountPoint holds information about the mounted endpoints. @@ -56,10 +57,12 @@ func New( {"Evaluate", "POST", "/policy/{group}/{policyName}/{version}/evaluation"}, {"Lock", "POST", "/policy/{group}/{policyName}/{version}/lock"}, {"Unlock", "DELETE", "/policy/{group}/{policyName}/{version}/lock"}, + {"ListPolicies", "GET", "/v1/policies"}, }, - Evaluate: NewEvaluateHandler(e.Evaluate, mux, decoder, encoder, errhandler, formatter), - Lock: NewLockHandler(e.Lock, mux, decoder, encoder, errhandler, formatter), - Unlock: NewUnlockHandler(e.Unlock, mux, decoder, encoder, errhandler, formatter), + Evaluate: NewEvaluateHandler(e.Evaluate, mux, decoder, encoder, errhandler, formatter), + Lock: NewLockHandler(e.Lock, mux, decoder, encoder, errhandler, formatter), + Unlock: NewUnlockHandler(e.Unlock, mux, decoder, encoder, errhandler, formatter), + ListPolicies: NewListPoliciesHandler(e.ListPolicies, mux, decoder, encoder, errhandler, formatter), } } @@ -71,6 +74,7 @@ func (s *Server) Use(m func(http.Handler) http.Handler) { s.Evaluate = m(s.Evaluate) s.Lock = m(s.Lock) s.Unlock = m(s.Unlock) + s.ListPolicies = m(s.ListPolicies) } // MethodNames returns the methods served. @@ -81,6 +85,7 @@ func Mount(mux goahttp.Muxer, h *Server) { MountEvaluateHandler(mux, h.Evaluate) MountLockHandler(mux, h.Lock) MountUnlockHandler(mux, h.Unlock) + MountListPoliciesHandler(mux, h.ListPolicies) } // Mount configures the mux to serve the policy endpoints. @@ -242,3 +247,54 @@ func NewUnlockHandler( } }) } + +// MountListPoliciesHandler configures the mux to serve the "policy" service +// "ListPolicies" endpoint. +func MountListPoliciesHandler(mux goahttp.Muxer, h http.Handler) { + f, ok := h.(http.HandlerFunc) + if !ok { + f = func(w http.ResponseWriter, r *http.Request) { + h.ServeHTTP(w, r) + } + } + mux.Handle("GET", "/v1/policies", f) +} + +// NewListPoliciesHandler creates a HTTP handler which loads the HTTP request +// and calls the "policy" service "ListPolicies" endpoint. +func NewListPoliciesHandler( + endpoint goa.Endpoint, + mux goahttp.Muxer, + decoder func(*http.Request) goahttp.Decoder, + encoder func(context.Context, http.ResponseWriter) goahttp.Encoder, + errhandler func(context.Context, http.ResponseWriter, error), + formatter func(ctx context.Context, err error) goahttp.Statuser, +) http.Handler { + var ( + decodeRequest = DecodeListPoliciesRequest(mux, decoder) + encodeResponse = EncodeListPoliciesResponse(encoder) + encodeError = goahttp.ErrorEncoder(encoder, formatter) + ) + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + ctx := context.WithValue(r.Context(), goahttp.AcceptTypeKey, r.Header.Get("Accept")) + ctx = context.WithValue(ctx, goa.MethodKey, "ListPolicies") + ctx = context.WithValue(ctx, goa.ServiceKey, "policy") + payload, err := decodeRequest(r) + if err != nil { + if err := encodeError(ctx, w, err); err != nil { + errhandler(ctx, w, err) + } + return + } + res, err := endpoint(ctx, payload) + if err != nil { + if err := encodeError(ctx, w, err); err != nil { + errhandler(ctx, w, err) + } + return + } + if err := encodeResponse(ctx, w, res); err != nil { + errhandler(ctx, w, err) + } + }) +} diff --git a/gen/http/policy/server/types.go b/gen/http/policy/server/types.go index 696bbaac0f8bc3df4c526c6269ec3586e23d802c..a193109d17fbba8de1becf811ecd5a41d3dd0e3f 100644 --- a/gen/http/policy/server/types.go +++ b/gen/http/policy/server/types.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy HTTP server types // @@ -11,6 +11,48 @@ import ( policy "gitlab.eclipse.org/eclipse/xfsc/tsa/policy/gen/policy" ) +// ListPoliciesResponseBody is the type of the "policy" service "ListPolicies" +// endpoint HTTP response body. +type ListPoliciesResponseBody struct { + // policy list + Policies []*PolicyResponseBody `form:"policies" json:"policies" xml:"policies"` +} + +// PolicyResponseBody is used to define fields on response body types. +type PolicyResponseBody struct { + // policy name + PolicyName string `form:"policyName" json:"policyName" xml:"policyName"` + // policy group + Group string `form:"group" json:"group" xml:"group"` + // policy version + Version string `form:"version" json:"version" xml:"version"` + // policy rego code + Rego *string `form:"rego,omitempty" json:"rego,omitempty" xml:"rego,omitempty"` + // policy data + Data *string `form:"data,omitempty" json:"data,omitempty" xml:"data,omitempty"` + // policy data config + DataConfig *string `form:"dataConfig,omitempty" json:"dataConfig,omitempty" xml:"dataConfig,omitempty"` + // if it true gives locked status on the policy + Locked bool `form:"locked" json:"locked" xml:"locked"` + // Last update (timestamp). + LastUpdate int64 `form:"lastUpdate" json:"lastUpdate" xml:"lastUpdate"` +} + +// NewListPoliciesResponseBody builds the HTTP response body from the result of +// the "ListPolicies" endpoint of the "policy" service. +func NewListPoliciesResponseBody(res *policy.PoliciesResult) *ListPoliciesResponseBody { + body := &ListPoliciesResponseBody{} + if res.Policies != nil { + body.Policies = make([]*PolicyResponseBody, len(res.Policies)) + for i, val := range res.Policies { + body.Policies[i] = marshalPolicyPolicyToPolicyResponseBody(val) + } + } else { + body.Policies = []*PolicyResponseBody{} + } + return body +} + // NewEvaluateRequest builds a policy service Evaluate endpoint payload. func NewEvaluateRequest(body any, group string, policyName string, version string, evaluationID *string, ttl *int) *policy.EvaluateRequest { v := body @@ -45,3 +87,15 @@ func NewUnlockRequest(group string, policyName string, version string) *policy.U return v } + +// NewListPoliciesPoliciesRequest builds a policy service ListPolicies endpoint +// payload. +func NewListPoliciesPoliciesRequest(locked *bool, rego *bool, data *bool, dataConfig *bool) *policy.PoliciesRequest { + v := &policy.PoliciesRequest{} + v.Locked = locked + v.Rego = rego + v.Data = data + v.DataConfig = dataConfig + + return v +} diff --git a/gen/openapi/client.go b/gen/openapi/client.go index 3bdf3e8d5a163626f9de708933f3baefa9f53927..266d9c02e64115c9c0b9528118ec753f858e8386 100644 --- a/gen/openapi/client.go +++ b/gen/openapi/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi client // diff --git a/gen/openapi/endpoints.go b/gen/openapi/endpoints.go index 8e849c52337b8bf022d878d162a24c640be937b1..4f31d68436914102a817af788b5a4cfdea8efba2 100644 --- a/gen/openapi/endpoints.go +++ b/gen/openapi/endpoints.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi endpoints // diff --git a/gen/openapi/service.go b/gen/openapi/service.go index 0d73592d7bc45b89229dda2144cd9e8b255845ef..918f003f1085f17bdc1324b496d9fa3f6fcc98d5 100644 --- a/gen/openapi/service.go +++ b/gen/openapi/service.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // openapi service // diff --git a/gen/policy/client.go b/gen/policy/client.go index 7eecf79fa3e14d575dcc8f6330d904115e6d2f33..49cb8cd5cac1433254711a75ee6c0a94f0e91687 100644 --- a/gen/policy/client.go +++ b/gen/policy/client.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy client // @@ -15,17 +15,19 @@ import ( // Client is the "policy" service client. type Client struct { - EvaluateEndpoint goa.Endpoint - LockEndpoint goa.Endpoint - UnlockEndpoint goa.Endpoint + EvaluateEndpoint goa.Endpoint + LockEndpoint goa.Endpoint + UnlockEndpoint goa.Endpoint + ListPoliciesEndpoint goa.Endpoint } // NewClient initializes a "policy" service client given the endpoints. -func NewClient(evaluate, lock, unlock goa.Endpoint) *Client { +func NewClient(evaluate, lock, unlock, listPolicies goa.Endpoint) *Client { return &Client{ - EvaluateEndpoint: evaluate, - LockEndpoint: lock, - UnlockEndpoint: unlock, + EvaluateEndpoint: evaluate, + LockEndpoint: lock, + UnlockEndpoint: unlock, + ListPoliciesEndpoint: listPolicies, } } @@ -50,3 +52,13 @@ func (c *Client) Unlock(ctx context.Context, p *UnlockRequest) (err error) { _, err = c.UnlockEndpoint(ctx, p) return } + +// ListPolicies calls the "ListPolicies" endpoint of the "policy" service. +func (c *Client) ListPolicies(ctx context.Context, p *PoliciesRequest) (res *PoliciesResult, err error) { + var ires any + ires, err = c.ListPoliciesEndpoint(ctx, p) + if err != nil { + return + } + return ires.(*PoliciesResult), nil +} diff --git a/gen/policy/endpoints.go b/gen/policy/endpoints.go index e0cc5dcff820140da8faf485f70280499138f4ca..e1c82db041f06b640cfcc82dfcf81e65272001c2 100644 --- a/gen/policy/endpoints.go +++ b/gen/policy/endpoints.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy endpoints // @@ -15,17 +15,19 @@ import ( // Endpoints wraps the "policy" service endpoints. type Endpoints struct { - Evaluate goa.Endpoint - Lock goa.Endpoint - Unlock goa.Endpoint + Evaluate goa.Endpoint + Lock goa.Endpoint + Unlock goa.Endpoint + ListPolicies goa.Endpoint } // NewEndpoints wraps the methods of the "policy" service with endpoints. func NewEndpoints(s Service) *Endpoints { return &Endpoints{ - Evaluate: NewEvaluateEndpoint(s), - Lock: NewLockEndpoint(s), - Unlock: NewUnlockEndpoint(s), + Evaluate: NewEvaluateEndpoint(s), + Lock: NewLockEndpoint(s), + Unlock: NewUnlockEndpoint(s), + ListPolicies: NewListPoliciesEndpoint(s), } } @@ -34,6 +36,7 @@ func (e *Endpoints) Use(m func(goa.Endpoint) goa.Endpoint) { e.Evaluate = m(e.Evaluate) e.Lock = m(e.Lock) e.Unlock = m(e.Unlock) + e.ListPolicies = m(e.ListPolicies) } // NewEvaluateEndpoint returns an endpoint function that calls the method @@ -62,3 +65,12 @@ func NewUnlockEndpoint(s Service) goa.Endpoint { return nil, s.Unlock(ctx, p) } } + +// NewListPoliciesEndpoint returns an endpoint function that calls the method +// "ListPolicies" of service "policy". +func NewListPoliciesEndpoint(s Service) goa.Endpoint { + return func(ctx context.Context, req any) (any, error) { + p := req.(*PoliciesRequest) + return s.ListPolicies(ctx, p) + } +} diff --git a/gen/policy/service.go b/gen/policy/service.go index 6c9cdccdc75faceef928eb293fb8c32b86d95de0..f4ce024b2ae980b6fec09ae44a7bdc17015c5527 100644 --- a/gen/policy/service.go +++ b/gen/policy/service.go @@ -1,4 +1,4 @@ -// Code generated by goa v3.12.1, DO NOT EDIT. +// Code generated by goa v3.12.3, DO NOT EDIT. // // policy service // @@ -19,6 +19,8 @@ type Service interface { Lock(context.Context, *LockRequest) (err error) // Unlock a policy so it can be evaluated again. Unlock(context.Context, *UnlockRequest) (err error) + // Listing all policies + ListPolicies(context.Context, *PoliciesRequest) (res *PoliciesResult, err error) } // ServiceName is the name of the service as defined in the design. This is the @@ -29,7 +31,7 @@ const ServiceName = "policy" // MethodNames lists the service method names as defined in the design. These // are the same values that are set in the endpoint request contexts under the // MethodKey key. -var MethodNames = [3]string{"Evaluate", "Lock", "Unlock"} +var MethodNames = [4]string{"Evaluate", "Lock", "Unlock", "ListPolicies"} // EvaluateRequest is the payload type of the policy service Evaluate method. type EvaluateRequest struct { @@ -67,6 +69,40 @@ type LockRequest struct { Version string } +// PoliciesRequest is the payload type of the policy service ListPolicies +// method. +type PoliciesRequest struct { + Locked *bool + Rego *bool + Data *bool + DataConfig *bool +} + +// PoliciesResult is the result type of the policy service ListPolicies method. +type PoliciesResult struct { + // policy list + Policies []*Policy +} + +type Policy struct { + // policy name + PolicyName string + // policy group + Group string + // policy version + Version string + // policy rego code + Rego *string + // policy data + Data *string + // policy data config + DataConfig *string + // if it true gives locked status on the policy + Locked bool + // Last update (timestamp). + LastUpdate int64 +} + // UnlockRequest is the payload type of the policy service Unlock method. type UnlockRequest struct { // Policy group. diff --git a/internal/service/policy/policydata/refresher_test.go b/internal/service/policy/policydata/refresher_test.go index 96c8a293c64f723b3932a54bdc4a64b3ba8cda18..b2a0f7b06e8747d6dd6962416f694296e26d131a 100644 --- a/internal/service/policy/policydata/refresher_test.go +++ b/internal/service/policy/policydata/refresher_test.go @@ -121,7 +121,7 @@ func Test_Execute(t *testing.T) { }) } refresher := policydata.NewRefresher(test.storage, time.Duration(0), httpClient, logger) - refresher.Execute(context.Background(), &test.policy) + refresher.Execute(context.Background(), (*storage.Policy)(&test.policy)) assert.Equal(t, test.logCnt, observedLogs.Len()) if observedLogs.Len() > 0 { diff --git a/internal/service/policy/policyfakes/fake_storage.go b/internal/service/policy/policyfakes/fake_storage.go index 667137dcdca1bbd7f2505450cf390db6f767b957..acf20f5ae889e77e6fbc799dccdfa87270d15293 100644 --- a/internal/service/policy/policyfakes/fake_storage.go +++ b/internal/service/policy/policyfakes/fake_storage.go @@ -10,6 +10,20 @@ import ( ) type FakeStorage struct { + GetPoliciesStub func(context.Context, *bool) ([]*storage.Policy, error) + getPoliciesMutex sync.RWMutex + getPoliciesArgsForCall []struct { + arg1 context.Context + arg2 *bool + } + getPoliciesReturns struct { + result1 []*storage.Policy + result2 error + } + getPoliciesReturnsOnCall map[int]struct { + result1 []*storage.Policy + result2 error + } PolicyStub func(context.Context, string, string, string) (*storage.Policy, error) policyMutex sync.RWMutex policyArgsForCall []struct { @@ -45,6 +59,71 @@ type FakeStorage struct { invocationsMutex sync.RWMutex } +func (fake *FakeStorage) GetPolicies(arg1 context.Context, arg2 *bool) ([]*storage.Policy, error) { + fake.getPoliciesMutex.Lock() + ret, specificReturn := fake.getPoliciesReturnsOnCall[len(fake.getPoliciesArgsForCall)] + fake.getPoliciesArgsForCall = append(fake.getPoliciesArgsForCall, struct { + arg1 context.Context + arg2 *bool + }{arg1, arg2}) + stub := fake.GetPoliciesStub + fakeReturns := fake.getPoliciesReturns + fake.recordInvocation("GetPolicies", []interface{}{arg1, arg2}) + fake.getPoliciesMutex.Unlock() + if stub != nil { + return stub(arg1, arg2) + } + if specificReturn { + return ret.result1, ret.result2 + } + return fakeReturns.result1, fakeReturns.result2 +} + +func (fake *FakeStorage) GetPoliciesCallCount() int { + fake.getPoliciesMutex.RLock() + defer fake.getPoliciesMutex.RUnlock() + return len(fake.getPoliciesArgsForCall) +} + +func (fake *FakeStorage) GetPoliciesCalls(stub func(context.Context, *bool) ([]*storage.Policy, error)) { + fake.getPoliciesMutex.Lock() + defer fake.getPoliciesMutex.Unlock() + fake.GetPoliciesStub = stub +} + +func (fake *FakeStorage) GetPoliciesArgsForCall(i int) (context.Context, *bool) { + fake.getPoliciesMutex.RLock() + defer fake.getPoliciesMutex.RUnlock() + argsForCall := fake.getPoliciesArgsForCall[i] + return argsForCall.arg1, argsForCall.arg2 +} + +func (fake *FakeStorage) GetPoliciesReturns(result1 []*storage.Policy, result2 error) { + fake.getPoliciesMutex.Lock() + defer fake.getPoliciesMutex.Unlock() + fake.GetPoliciesStub = nil + fake.getPoliciesReturns = struct { + result1 []*storage.Policy + result2 error + }{result1, result2} +} + +func (fake *FakeStorage) GetPoliciesReturnsOnCall(i int, result1 []*storage.Policy, result2 error) { + fake.getPoliciesMutex.Lock() + defer fake.getPoliciesMutex.Unlock() + fake.GetPoliciesStub = nil + if fake.getPoliciesReturnsOnCall == nil { + fake.getPoliciesReturnsOnCall = make(map[int]struct { + result1 []*storage.Policy + result2 error + }) + } + fake.getPoliciesReturnsOnCall[i] = struct { + result1 []*storage.Policy + result2 error + }{result1, result2} +} + func (fake *FakeStorage) Policy(arg1 context.Context, arg2 string, arg3 string, arg4 string) (*storage.Policy, error) { fake.policyMutex.Lock() ret, specificReturn := fake.policyReturnsOnCall[len(fake.policyArgsForCall)] @@ -180,6 +259,8 @@ func (fake *FakeStorage) SetPolicyLockReturnsOnCall(i int, result1 error) { func (fake *FakeStorage) Invocations() map[string][][]interface{} { fake.invocationsMutex.RLock() defer fake.invocationsMutex.RUnlock() + fake.getPoliciesMutex.RLock() + defer fake.getPoliciesMutex.RUnlock() fake.policyMutex.RLock() defer fake.policyMutex.RUnlock() fake.setPolicyLockMutex.RLock() diff --git a/internal/service/policy/service.go b/internal/service/policy/service.go index ee178f178b7e758a22b4f951f597fce5a24358aa..b22ab5f19741b917a510e99b7b732d4c624be947 100644 --- a/internal/service/policy/service.go +++ b/internal/service/policy/service.go @@ -11,6 +11,7 @@ import ( "go.uber.org/zap" "gitlab.eclipse.org/eclipse/xfsc/tsa/golib/errors" + "gitlab.eclipse.org/eclipse/xfsc/tsa/golib/ptr" "gitlab.eclipse.org/eclipse/xfsc/tsa/policy/gen/policy" "gitlab.eclipse.org/eclipse/xfsc/tsa/policy/internal/header" "gitlab.eclipse.org/eclipse/xfsc/tsa/policy/internal/regofunc" @@ -28,6 +29,7 @@ type Cache interface { type Storage interface { Policy(ctx context.Context, group, name, version string) (*storage.Policy, error) SetPolicyLock(ctx context.Context, group, name, version string, lock bool) error + GetPolicies(ctx context.Context, locked *bool) ([]*storage.Policy, error) } type RegoCache interface { @@ -199,6 +201,46 @@ func (s *Service) Unlock(ctx context.Context, req *policy.UnlockRequest) error { return nil } +func (s *Service) ListPolicies(ctx context.Context, req *policy.PoliciesRequest) (*policy.PoliciesResult, error) { + logger := s.logger.With( + zap.String("operaiton", "listPolicies"), + ) + + policies, err := s.storage.GetPolicies(ctx, req.Locked) + if err != nil { + logger.Error("error retrieving policies", zap.Error(err)) + return nil, errors.New("error retrieving policies", err) + } + + policiesResult := make([]*policy.Policy, 0, len(policies)) + + for _, p := range policies { + policy := &policy.Policy{ + PolicyName: p.Name, + Group: p.Group, + Version: p.Version, + Locked: p.Locked, + LastUpdate: p.LastUpdate.Unix(), + } + + if req.Rego != nil && *req.Rego { + policy.Rego = ptr.String(p.Rego) + } + + if req.Data != nil && *req.Data { + policy.Data = ptr.String(p.Data) + } + + if req.DataConfig != nil && *req.DataConfig { + policy.DataConfig = ptr.String(p.DataConfig) + } + + policiesResult = append(policiesResult, policy) + } + + return &policy.PoliciesResult{Policies: policiesResult}, nil +} + // prepareQuery tries to get a prepared query from the regocache. // If the policyCache entry is not found, it will try to prepare a new // query and will set it into the policyCache for future use. diff --git a/internal/service/policy/service_test.go b/internal/service/policy/service_test.go index bb9858e5f0d5113c5ffa3de3b1cb6ffc62ce2558..dbfcc966e957daa1cc09e69808a8955f2dfffa75 100644 --- a/internal/service/policy/service_test.go +++ b/internal/service/policy/service_test.go @@ -2,6 +2,7 @@ package policy_test import ( "context" + "fmt" "net/http" "net/http/httptest" "testing" @@ -577,3 +578,222 @@ func TestService_Unlock(t *testing.T) { }) } } + +func TestService_ListPolicies(t *testing.T) { + strPointer := func(str string) *string { + return &str + } + boolTrue := true + boolFalse := false + tests := []struct { + name string + storage policy.Storage + request *goapolicy.PoliciesRequest + + response *goapolicy.PoliciesResult + errText string + }{ + { + name: "storage return error", + storage: &policyfakes.FakeStorage{GetPoliciesStub: func(ctx context.Context, b *bool) ([]*storage.Policy, error) { + return nil, fmt.Errorf("some error") + }}, + request: &goapolicy.PoliciesRequest{ + Locked: new(bool), + Rego: new(bool), + Data: new(bool), + DataConfig: new(bool), + }, + + errText: "some error", + }, + { + name: "request without errors and any additional request parameter return all policies", + storage: &policyfakes.FakeStorage{GetPoliciesStub: func(ctx context.Context, b *bool) ([]*storage.Policy, error) { + return []*storage.Policy{{ + Name: "example", + Group: "example", + Version: "example", + Rego: "some rego", + Data: "some Data", + DataConfig: "data config", + Locked: false, + LastUpdate: time.Time{}, + }, { + Name: "example", + Group: "example", + Version: "example", + Rego: "some rego", + Data: "some data", + DataConfig: "data config", + Locked: true, + LastUpdate: time.Time{}, + }}, nil + }}, + request: &goapolicy.PoliciesRequest{}, + + response: &goapolicy.PoliciesResult{ + Policies: []*goapolicy.Policy{ + { + PolicyName: "example", + Group: "example", + Version: "example", + Locked: false, + LastUpdate: time.Time{}.Unix(), + }, + { + PolicyName: "example", + Group: "example", + Version: "example", + Locked: true, + LastUpdate: time.Time{}.Unix(), + }, + }, + }, + }, + { + name: "request with only locked parameter equal to true returns only locked policies", + storage: &policyfakes.FakeStorage{GetPoliciesStub: func(ctx context.Context, b *bool) ([]*storage.Policy, error) { + return []*storage.Policy{{ + Name: "example", + Group: "example", + Version: "example", + Rego: "some rego", + Data: "some data", + DataConfig: "data config", + Locked: true, + LastUpdate: time.Time{}, + }}, nil + }}, + request: &goapolicy.PoliciesRequest{ + Locked: &boolTrue, + }, + + response: &goapolicy.PoliciesResult{ + Policies: []*goapolicy.Policy{ + { + PolicyName: "example", + Group: "example", + Version: "example", + Locked: true, + LastUpdate: time.Time{}.Unix(), + }, + }, + }, + }, + { + name: "request with only locked parameter equal to false returns only unlocked policies", + storage: &policyfakes.FakeStorage{GetPoliciesStub: func(ctx context.Context, b *bool) ([]*storage.Policy, error) { + return []*storage.Policy{{ + Name: "example", + Group: "example", + Version: "example", + Rego: "some rego", + Data: "some data", + DataConfig: "data config", + Locked: false, + LastUpdate: time.Time{}, + }}, nil + }}, + request: &goapolicy.PoliciesRequest{ + Locked: &boolFalse, + }, + + response: &goapolicy.PoliciesResult{ + Policies: []*goapolicy.Policy{ + { + PolicyName: "example", + Group: "example", + Version: "example", + Locked: false, + LastUpdate: time.Time{}.Unix(), + }, + }, + }, + }, + { + name: "request with all additional params set to true", + storage: &policyfakes.FakeStorage{GetPoliciesStub: func(ctx context.Context, b *bool) ([]*storage.Policy, error) { + return []*storage.Policy{{ + Name: "example", + Group: "example", + Version: "example", + Rego: "some rego", + Data: "some data", + DataConfig: "data config", + Locked: false, + LastUpdate: time.Time{}, + }}, nil + }}, + request: &goapolicy.PoliciesRequest{ + Locked: new(bool), + Rego: &boolTrue, + Data: &boolTrue, + DataConfig: &boolTrue, + }, + + response: &goapolicy.PoliciesResult{ + Policies: []*goapolicy.Policy{ + { + PolicyName: "example", + Group: "example", + Version: "example", + Rego: strPointer("some rego"), + Data: strPointer("some data"), + DataConfig: strPointer("data config"), + Locked: false, + LastUpdate: time.Time{}.Unix(), + }, + }, + }, + }, + { + name: "request with all additional params set to false", + storage: &policyfakes.FakeStorage{GetPoliciesStub: func(ctx context.Context, b *bool) ([]*storage.Policy, error) { + return []*storage.Policy{{ + Name: "example", + Group: "example", + Version: "example", + Rego: "some rego", + Data: "some data", + DataConfig: "data config", + Locked: false, + LastUpdate: time.Time{}, + }}, nil + }}, + request: &goapolicy.PoliciesRequest{ + Locked: new(bool), + Rego: &boolFalse, + Data: &boolFalse, + DataConfig: &boolFalse, + }, + + response: &goapolicy.PoliciesResult{ + Policies: []*goapolicy.Policy{ + { + PolicyName: "example", + Group: "example", + Version: "example", + Locked: false, + LastUpdate: time.Time{}.Unix(), + }, + }, + }, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + svc := policy.New(test.storage, nil, nil, zap.NewNop()) + result, err := svc.ListPolicies(context.Background(), test.request) + + if test.errText != "" { + assert.ErrorContains(t, err, test.errText) + assert.Nil(t, result) + } else { + assert.NoError(t, err) + assert.Equal(t, result, test.response) + } + }) + } +} diff --git a/internal/storage/storage.go b/internal/storage/storage.go index f107beb88bf20816d92ad4dd2280fd80bc0b1d96..f30c7a67aa86d7cd71d5387a41cd4de9bbe2e3b2 100644 --- a/internal/storage/storage.go +++ b/internal/storage/storage.go @@ -14,6 +14,7 @@ import ( ) const ( + lockedField = "locked" dataField = "data" nextDataRefreshTimeField = "nextDataRefreshTime" refreshPostponePeriod = 5 * time.Minute @@ -166,7 +167,7 @@ func (s *Storage) GetRefreshPolicies(ctx context.Context) ([]*Policy, error) { func (s *Storage) PostponeRefresh(ctx context.Context, policies []*Policy) error { var ids []*primitive.ObjectID for _, p := range policies { - ids = append(ids, &p.ID) + ids = append(ids, (*primitive.ObjectID)(&p.ID)) } filter := bson.M{"_id": bson.M{"$in": ids}} @@ -202,3 +203,22 @@ func (s *Storage) Transaction(ctx context.Context, callback func(mCtx mongo.Sess return res, nil } + +func (s *Storage) GetPolicies(ctx context.Context, locked *bool) ([]*Policy, error) { + var filter bson.M + if locked != nil { + filter = bson.M{lockedField: locked} + } + + cursor, err := s.policy.Find(ctx, filter) + if err != nil { + return nil, err + } + + var policies []*Policy + if err := cursor.All(ctx, &policies); err != nil { + return nil, err + } + + return policies, nil +}