-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added rego loading and evaluate API impl
- Loading branch information
1 parent
5f8ea27
commit 9752596
Showing
9 changed files
with
404 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,44 @@ | ||
package opa | ||
|
||
import "context" | ||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/nuts-foundation/nuts-pxp/policy" | ||
"strings" | ||
) | ||
|
||
var _ StrictServerInterface = (*Wrapper)(nil) | ||
|
||
type Wrapper struct{} | ||
type Wrapper struct { | ||
DecisionMaker policy.DecisionMaker | ||
} | ||
|
||
func (w Wrapper) EvaluateDocument(ctx context.Context, request EvaluateDocumentRequestObject) (EvaluateDocumentResponseObject, error) { | ||
//TODO implement me | ||
panic("implement me") | ||
// parse the requestLine and extract the method and path | ||
// the requestLine is formatted as an HTTP request line | ||
// e.g. "GET /api/v1/resource HTTP/1.1" | ||
// we are only interested in the method and path | ||
method, path, err := parseRequestLine(request.Params.Request) | ||
if err != nil { | ||
return nil, err | ||
} | ||
httpRequest := map[string]interface{}{} | ||
httpRequest["method"] = method | ||
httpRequest["path"] = path | ||
|
||
descision, err := w.DecisionMaker.Query(ctx, httpRequest, request.Params.XUserinfo) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return EvaluateDocument200JSONResponse{Allow: descision}, nil | ||
} | ||
|
||
// parseRequestLine parses the request line and extracts the method and path | ||
// e.g. "GET /api/v1/resource HTTP/1.1" -> "GET", "/api/v1/resource" | ||
func parseRequestLine(requestLine string) (method, path string, err error) { | ||
parts := strings.Split(requestLine, " ") | ||
if len(parts) != 3 { | ||
return "", "", fmt.Errorf("invalid request line: %s", requestLine) | ||
} | ||
return parts[0], parts[1], nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.