-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from eko/compiled-api
Added /v1/compiled API allowing to retrieve compiled policies data
- Loading branch information
Showing
9 changed files
with
318 additions
and
14 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
@compiled | ||
Feature: compiled | ||
Test compiled-policies APIs | ||
|
||
Scenario: List compiled policies | ||
Given I authenticate with username "admin" and password "changeme" | ||
And I send "POST" request to "/v1/principals" with payload: | ||
""" | ||
{ | ||
"id": "my-principal", | ||
"attributes": [ | ||
{"key": "email", "value": "[email protected]"} | ||
] | ||
} | ||
""" | ||
And the response code should be 200 | ||
And I send "POST" request to "/v1/resources" with payload: | ||
""" | ||
{ | ||
"id": "post.123", | ||
"kind": "post", | ||
"value": "123", | ||
"attributes": [ | ||
{"key": "owner_email", "value": "[email protected]"} | ||
] | ||
} | ||
""" | ||
And the response code should be 200 | ||
And I send "POST" request to "/v1/policies" with payload: | ||
""" | ||
{ | ||
"id": "my-post-policy", | ||
"resources": [ | ||
"post.*" | ||
], | ||
"actions": ["update", "delete"], | ||
"attribute_rules": [ | ||
"principal.email == resource.owner_email" | ||
] | ||
} | ||
""" | ||
And the response code should be 200 | ||
And I wait "500ms" | ||
When I send "GET" request to "/v1/compiled?filter=policy_id:contains:my-post-policy&sort=action_id:asc" | ||
Then the response code should be 200 | ||
And the response should match json: | ||
""" | ||
{ | ||
"data": [ | ||
{ | ||
"action_id": "delete", | ||
"created_at": "2100-01-01T01:00:00Z", | ||
"policy_id": "my-post-policy", | ||
"principal_id": "my-principal", | ||
"resource_kind": "post", | ||
"resource_value": "123", | ||
"updated_at": "2100-01-01T01:00:00Z", | ||
"version": 4102448400 | ||
}, | ||
{ | ||
"action_id": "update", | ||
"created_at": "2100-01-01T01:00:00Z", | ||
"policy_id": "my-post-policy", | ||
"principal_id": "my-principal", | ||
"resource_kind": "post", | ||
"resource_value": "123", | ||
"updated_at": "2100-01-01T01:00:00Z", | ||
"version": 4102448400 | ||
} | ||
], | ||
"page": 0, | ||
"size": 100, | ||
"total": 2 | ||
} | ||
""" |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package handler | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/eko/authz/backend/internal/entity/manager" | ||
"github.com/eko/authz/backend/internal/entity/repository" | ||
"github.com/eko/authz/backend/internal/http/handler/model" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
// Retrieve compiled policies | ||
// | ||
// @security Authentication | ||
// @Summary Retrieve compiled policies | ||
// @Tags Policy | ||
// @Produce json | ||
// @Success 200 {object} []model.CompiledPolicy | ||
// @Failure 404 {object} model.ErrorResponse | ||
// @Failure 500 {object} model.ErrorResponse | ||
// @Router /v1/policies/{identifier}/matches [Get] | ||
func CompiledList( | ||
compiledManager manager.CompiledPolicy, | ||
) fiber.Handler { | ||
return func(c *fiber.Ctx) error { | ||
page, size, err := paginate(c) | ||
if err != nil { | ||
return returnError(c, http.StatusInternalServerError, err) | ||
} | ||
|
||
// List policies | ||
compiledPolicies, total, err := compiledManager.GetRepository().Find( | ||
repository.WithPage(page), | ||
repository.WithSize(size), | ||
repository.WithFilter(httpFilterToORM(c)), | ||
repository.WithSort(httpSortToORM(c)), | ||
) | ||
if err != nil { | ||
return returnError(c, http.StatusInternalServerError, err) | ||
} | ||
|
||
return c.JSON(model.NewPaginated(compiledPolicies, total, page, size)) | ||
} | ||
} |
Oops, something went wrong.