diff --git a/routers/mux/input.go b/sdk/rondinput/http/input.go similarity index 99% rename from routers/mux/input.go rename to sdk/rondinput/http/input.go index 059e3393..79ae226b 100644 --- a/routers/mux/input.go +++ b/sdk/rondinput/http/input.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rondmux +package rondhttp import ( "bytes" diff --git a/routers/mux/input_test.go b/sdk/rondinput/http/input_test.go similarity index 99% rename from routers/mux/input_test.go rename to sdk/rondinput/http/input_test.go index 67c6783c..71421ed0 100644 --- a/routers/mux/input_test.go +++ b/sdk/rondinput/http/input_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rondmux +package rondhttp import ( "bytes" diff --git a/service/handler.go b/service/handler.go index 7f1a98f9..0b1fb2c8 100644 --- a/service/handler.go +++ b/service/handler.go @@ -24,8 +24,8 @@ import ( "github.com/rond-authz/rond/internal/opatranslator" "github.com/rond-authz/rond/internal/utils" "github.com/rond-authz/rond/openapi" - rondmux "github.com/rond-authz/rond/routers/mux" "github.com/rond-authz/rond/sdk" + rondhttp "github.com/rond-authz/rond/sdk/rondinput/http" "github.com/rond-authz/rond/types" "github.com/gorilla/mux" @@ -112,7 +112,7 @@ func EvaluateRequest( return err } - rondInput := rondmux.NewInput(req, env.ClientTypeHeader, mux.Vars(req)) + rondInput := rondhttp.NewInput(req, env.ClientTypeHeader, mux.Vars(req)) result, err := evaluatorSdk.EvaluateRequestPolicy(req.Context(), rondInput, userInfo) if err != nil { if errors.Is(err, opatranslator.ErrEmptyQuery) && utils.HasApplicationJSONContentType(req.Header) { diff --git a/service/opa_transport.go b/service/opa_transport.go index 7a5793bd..ea079632 100644 --- a/service/opa_transport.go +++ b/service/opa_transport.go @@ -26,8 +26,8 @@ import ( "github.com/rond-authz/rond/core" "github.com/rond-authz/rond/internal/mongoclient" "github.com/rond-authz/rond/internal/utils" - rondmux "github.com/rond-authz/rond/routers/mux" "github.com/rond-authz/rond/sdk" + rondhttp "github.com/rond-authz/rond/sdk/rondinput/http" "github.com/rond-authz/rond/types" "github.com/gorilla/mux" @@ -116,7 +116,7 @@ func (t *OPATransport) RoundTrip(req *http.Request) (resp *http.Response, err er } pathParams := mux.Vars(t.request) - input := rondmux.NewInput(t.request, t.clientHeaderKey, pathParams) + input := rondhttp.NewInput(t.request, t.clientHeaderKey, pathParams) responseBody, err := t.evaluatorSDK.EvaluateResponsePolicy(t.context, input, userInfo, decodedBody) if err != nil { diff --git a/routers/mux/opamiddleware.go b/service/opamiddleware.go similarity index 99% rename from routers/mux/opamiddleware.go rename to service/opamiddleware.go index bdac9022..4ca55ccf 100644 --- a/routers/mux/opamiddleware.go +++ b/service/opamiddleware.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rondmux +package service import ( "errors" diff --git a/routers/mux/opamiddleware_test.go b/service/opamiddleware_test.go similarity index 96% rename from routers/mux/opamiddleware_test.go rename to service/opamiddleware_test.go index 5f483a24..3d132ff1 100644 --- a/routers/mux/opamiddleware_test.go +++ b/service/opamiddleware_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package rondmux +package service import ( "context" @@ -61,7 +61,7 @@ func TestOPAMiddleware(t *testing.T) { todo { true }`, } var openAPISpec *openapi.OpenAPISpec - openAPISpecContent, err := os.ReadFile("../../mocks/simplifiedMock.json") + openAPISpecContent, err := os.ReadFile("../mocks/simplifiedMock.json") require.NoError(t, err) err = json.Unmarshal(openAPISpecContent, &openAPISpec) require.NoError(t, err) @@ -126,7 +126,7 @@ foobar { true }`, } t.Run(`ok - path is known on oas with no permission declared`, func(t *testing.T) { - openAPISpec, err := openapi.LoadOASFile("../../mocks/documentationPathMock.json") + openAPISpec, err := openapi.LoadOASFile("../mocks/documentationPathMock.json") require.NoError(t, err) targetServiceOASPath := "/documentation/json" sdk := getSDK(t, openAPISpec, opaModule) @@ -144,7 +144,7 @@ foobar { true }`, }) t.Run(`ok - path is missing on oas and request is equal to serviceTargetOASPath`, func(t *testing.T) { - openAPISpec, err := openapi.LoadOASFile("../../mocks/simplifiedMock.json") + openAPISpec, err := openapi.LoadOASFile("../mocks/simplifiedMock.json") require.NoError(t, err) targetServiceOASPath := "/documentation/json" sdk := getSDK(t, openAPISpec, opaModule) @@ -162,7 +162,7 @@ foobar { true }`, }) t.Run(`ok - path is NOT known on oas but is proxied anyway`, func(t *testing.T) { - openAPISpec, err := openapi.LoadOASFile("../../mocks/simplifiedMock.json") + openAPISpec, err := openapi.LoadOASFile("../mocks/simplifiedMock.json") require.NoError(t, err) targetServiceOASPath := "/documentation/custom/json" sdk := getSDK(t, openAPISpec, opaModule) @@ -181,7 +181,7 @@ foobar { true }`, }) t.Run(`injects opa instance with correct query`, func(t *testing.T) { - openAPISpec, err := openapi.LoadOASFile("../../mocks/simplifiedMock.json") + openAPISpec, err := openapi.LoadOASFile("../mocks/simplifiedMock.json") require.NoError(t, err) t.Run(`rego package doesn't contain expected policy`, func(t *testing.T) { @@ -299,7 +299,7 @@ very_very_composed_permission_with_eval { true }`, func TestOPAMiddlewareStandaloneIntegration(t *testing.T) { var routesNotToProxy = []string{} - openAPISpec, err := openapi.LoadOASFile("../../mocks/simplifiedMock.json") + openAPISpec, err := openapi.LoadOASFile("../mocks/simplifiedMock.json") require.Nil(t, err) options := &OPAMiddlewareOptions{ IsStandalone: true, diff --git a/service/router.go b/service/router.go index ee8b1929..49b53626 100644 --- a/service/router.go +++ b/service/router.go @@ -32,7 +32,6 @@ import ( "github.com/rond-authz/rond/internal/mongoclient" "github.com/rond-authz/rond/internal/utils" "github.com/rond-authz/rond/openapi" - rondmux "github.com/rond-authz/rond/routers/mux" "github.com/rond-authz/rond/sdk" "github.com/rond-authz/rond/types" @@ -151,7 +150,7 @@ func SetupRouter( } } - evalRouter.Use(rondmux.OPAMiddleware(opaModuleConfig, sdk, routesToNotProxy, env.TargetServiceOASPath, &rondmux.OPAMiddlewareOptions{ + evalRouter.Use(OPAMiddleware(opaModuleConfig, sdk, routesToNotProxy, env.TargetServiceOASPath, &OPAMiddlewareOptions{ IsStandalone: env.Standalone, PathPrefixStandalone: env.PathPrefixStandalone, }))