Skip to content

Commit

Permalink
added rego loading and evaluate API impl
Browse files Browse the repository at this point in the history
  • Loading branch information
woutslakhorst committed May 24, 2024
1 parent 5f8ea27 commit 9752596
Show file tree
Hide file tree
Showing 9 changed files with 404 additions and 24 deletions.
40 changes: 36 additions & 4 deletions api/opa/api.go
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
}
15 changes: 11 additions & 4 deletions api/opa/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const configValueListSeparator = ","

type Config struct {
configMap *koanf.Koanf
PolicyDir string `koanf:"policy_dir"`
SQL SQLConfig `koanf:"sql"`
}

Expand Down
35 changes: 34 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/knadh/koanf v1.5.0
github.com/labstack/echo/v4 v4.12.0
github.com/oapi-codegen/runtime v1.1.1
github.com/open-policy-agent/opa v0.64.1
github.com/pressly/goose/v3 v3.20.0
github.com/spf13/pflag v1.0.5
gorm.io/driver/mysql v1.5.6
Expand All @@ -17,13 +18,23 @@ require (

require (
filippo.io/edwards25519 v1.1.0 // indirect
github.com/OneOfOne/xxhash v1.2.8 // indirect
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/glebarez/go-sqlite v1.21.2 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-sql-driver/mysql v1.8.1 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 // indirect
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/mux v1.8.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.5.5 // indirect
Expand All @@ -39,20 +50,42 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/prometheus/client_golang v1.19.0 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.48.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rcrowley/go-metrics v0.0.0-20200313005456-10cdbea86bc0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/sethvargo/go-retry v0.2.4 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tchap/go-patricia/v2 v2.3.1 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
github.com/yashtewari/glob-intersection v0.2.0 // indirect
go.opentelemetry.io/otel v1.21.0 // indirect
go.opentelemetry.io/otel/metric v1.21.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.21.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/sqlite v1.29.6 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 9752596

Please sign in to comment.