Skip to content

Commit

Permalink
move filest in service
Browse files Browse the repository at this point in the history
  • Loading branch information
davidebianchi committed Jul 5, 2023
1 parent 2980f2b commit 3dbcf2a
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion routers/mux/input.go → sdk/rondinput/http/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package rondmux
package rondhttp

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package rondmux
package rondhttp

import (
"bytes"
Expand Down
4 changes: 2 additions & 2 deletions service/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions service/opa_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion routers/mux/opamiddleware.go → service/opamiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package rondmux
package service

import (
"errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package rondmux
package service

import (
"context"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions service/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
}))
Expand Down

0 comments on commit 3dbcf2a

Please sign in to comment.