diff --git a/api/opa/api.go b/api/opa/api.go index 88fc7ed..ecd91f7 100644 --- a/api/opa/api.go +++ b/api/opa/api.go @@ -15,7 +15,7 @@ type Wrapper struct { DecisionMaker policy.DecisionMaker } -func (w Wrapper) EvaluateDocumentApisix(ctx context.Context, request EvaluateDocumentApisixRequestObject) (EvaluateDocumentApisixResponseObject, error) { +func (w Wrapper) EvaluateDocumentWildcardPolicy(ctx context.Context, request EvaluateDocumentWildcardPolicyRequestObject) (EvaluateDocumentWildcardPolicyResponseObject, error) { if request.Body == nil { return nil, errors.New("missing body") } @@ -62,7 +62,7 @@ func (w Wrapper) EvaluateDocumentApisix(ctx context.Context, request EvaluateDoc // "allow": true // } //} - return EvaluateDocumentApisix200JSONResponse(*outcome), nil + return EvaluateDocumentWildcardPolicy200JSONResponse(*outcome), nil } func (w Wrapper) EvaluateDocument(ctx context.Context, request EvaluateDocumentRequestObject) (EvaluateDocumentResponseObject, error) { diff --git a/api/opa/generated.go b/api/opa/generated.go index 60a7343..a6bd359 100644 --- a/api/opa/generated.go +++ b/api/opa/generated.go @@ -28,8 +28,8 @@ type Outcome struct { // EvaluateDocumentJSONRequestBody defines body for EvaluateDocument for application/json ContentType. type EvaluateDocumentJSONRequestBody = Input -// EvaluateDocumentApisixJSONRequestBody defines body for EvaluateDocumentApisix for application/json ContentType. -type EvaluateDocumentApisixJSONRequestBody = Input +// EvaluateDocumentWildcardPolicyJSONRequestBody defines body for EvaluateDocumentWildcardPolicy for application/json ContentType. +type EvaluateDocumentWildcardPolicyJSONRequestBody = Input // ServerInterface represents all server handlers. type ServerInterface interface { @@ -37,8 +37,8 @@ type ServerInterface interface { // (POST /v1/data) EvaluateDocument(ctx echo.Context) error // calls https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document-with-input internally - // (POST /v1/data/apisix) - EvaluateDocumentApisix(ctx echo.Context) error + // (POST /v1/data/*) + EvaluateDocumentWildcardPolicy(ctx echo.Context) error } // ServerInterfaceWrapper converts echo contexts to parameters. @@ -55,12 +55,12 @@ func (w *ServerInterfaceWrapper) EvaluateDocument(ctx echo.Context) error { return err } -// EvaluateDocumentApisix converts echo context to params. -func (w *ServerInterfaceWrapper) EvaluateDocumentApisix(ctx echo.Context) error { +// EvaluateDocumentWildcardPolicy converts echo context to params. +func (w *ServerInterfaceWrapper) EvaluateDocumentWildcardPolicy(ctx echo.Context) error { var err error // Invoke the callback with all the unmarshaled arguments - err = w.Handler.EvaluateDocumentApisix(ctx) + err = w.Handler.EvaluateDocumentWildcardPolicy(ctx) return err } @@ -93,7 +93,7 @@ func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL } router.POST(baseURL+"/v1/data", wrapper.EvaluateDocument) - router.POST(baseURL+"/v1/data/apisix", wrapper.EvaluateDocumentApisix) + router.POST(baseURL+"/v1/data/*", wrapper.EvaluateDocumentWildcardPolicy) } @@ -114,17 +114,17 @@ func (response EvaluateDocument200JSONResponse) VisitEvaluateDocumentResponse(w return json.NewEncoder(w).Encode(response) } -type EvaluateDocumentApisixRequestObject struct { - Body *EvaluateDocumentApisixJSONRequestBody +type EvaluateDocumentWildcardPolicyRequestObject struct { + Body *EvaluateDocumentWildcardPolicyJSONRequestBody } -type EvaluateDocumentApisixResponseObject interface { - VisitEvaluateDocumentApisixResponse(w http.ResponseWriter) error +type EvaluateDocumentWildcardPolicyResponseObject interface { + VisitEvaluateDocumentWildcardPolicyResponse(w http.ResponseWriter) error } -type EvaluateDocumentApisix200JSONResponse Outcome +type EvaluateDocumentWildcardPolicy200JSONResponse Outcome -func (response EvaluateDocumentApisix200JSONResponse) VisitEvaluateDocumentApisixResponse(w http.ResponseWriter) error { +func (response EvaluateDocumentWildcardPolicy200JSONResponse) VisitEvaluateDocumentWildcardPolicyResponse(w http.ResponseWriter) error { w.Header().Set("Content-Type", "application/json") w.WriteHeader(200) @@ -137,8 +137,8 @@ type StrictServerInterface interface { // (POST /v1/data) EvaluateDocument(ctx context.Context, request EvaluateDocumentRequestObject) (EvaluateDocumentResponseObject, error) // calls https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document-with-input internally - // (POST /v1/data/apisix) - EvaluateDocumentApisix(ctx context.Context, request EvaluateDocumentApisixRequestObject) (EvaluateDocumentApisixResponseObject, error) + // (POST /v1/data/*) + EvaluateDocumentWildcardPolicy(ctx context.Context, request EvaluateDocumentWildcardPolicyRequestObject) (EvaluateDocumentWildcardPolicyResponseObject, error) } type StrictHandlerFunc = strictecho.StrictEchoHandlerFunc @@ -182,29 +182,29 @@ func (sh *strictHandler) EvaluateDocument(ctx echo.Context) error { return nil } -// EvaluateDocumentApisix operation middleware -func (sh *strictHandler) EvaluateDocumentApisix(ctx echo.Context) error { - var request EvaluateDocumentApisixRequestObject +// EvaluateDocumentWildcardPolicy operation middleware +func (sh *strictHandler) EvaluateDocumentWildcardPolicy(ctx echo.Context) error { + var request EvaluateDocumentWildcardPolicyRequestObject - var body EvaluateDocumentApisixJSONRequestBody + var body EvaluateDocumentWildcardPolicyJSONRequestBody if err := ctx.Bind(&body); err != nil { return err } request.Body = &body handler := func(ctx echo.Context, request interface{}) (interface{}, error) { - return sh.ssi.EvaluateDocumentApisix(ctx.Request().Context(), request.(EvaluateDocumentApisixRequestObject)) + return sh.ssi.EvaluateDocumentWildcardPolicy(ctx.Request().Context(), request.(EvaluateDocumentWildcardPolicyRequestObject)) } for _, middleware := range sh.middlewares { - handler = middleware(handler, "EvaluateDocumentApisix") + handler = middleware(handler, "EvaluateDocumentWildcardPolicy") } response, err := handler(ctx, request) if err != nil { return err - } else if validResponse, ok := response.(EvaluateDocumentApisixResponseObject); ok { - return validResponse.VisitEvaluateDocumentApisixResponse(ctx.Response()) + } else if validResponse, ok := response.(EvaluateDocumentWildcardPolicyResponseObject); ok { + return validResponse.VisitEvaluateDocumentWildcardPolicyResponse(ctx.Response()) } else if response != nil { return fmt.Errorf("unexpected response type: %T", response) } diff --git a/oas/opa.yaml b/oas/opa.yaml index 29e162e..4a07382 100644 --- a/oas/opa.yaml +++ b/oas/opa.yaml @@ -26,12 +26,13 @@ paths: application/json: schema: $ref: '#/components/schemas/Outcome' - /v1/data/apisix: + /v1/data/*: post: - operationId: evaluateDocumentApisix + operationId: evaluateDocumentWildcardPolicy summary: calls https://www.openpolicyagent.org/docs/latest/rest-api/#get-a-document-with-input internally description: | - The given request and X-Userinfo headers are used to create the input document for the OPA policy. + The wildcard contains path elements normally used to select an OPA policy. + This API ignores the wildcard (policy) and does the same thing as /v1/data (select policy based on scope). tags: - opa requestBody: