Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[API+SDK] Add option to query permissions from the client (#1161)
- Loading branch information
Showing
10 changed files
with
114 additions
and
29 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
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,21 @@ | ||
import fastapi | ||
|
||
import mlrun.api.api.deps | ||
import mlrun.api.schemas | ||
import mlrun.api.utils.clients.opa | ||
|
||
router = fastapi.APIRouter() | ||
|
||
|
||
@router.post("/authorization/verifications") | ||
def verify_authorization( | ||
authorization_verification_input: mlrun.api.schemas.AuthorizationVerificationInput, | ||
auth_verifier: mlrun.api.api.deps.AuthVerifier = fastapi.Depends( | ||
mlrun.api.api.deps.AuthVerifier | ||
), | ||
): | ||
mlrun.api.utils.clients.opa.Client().query_permissions( | ||
authorization_verification_input.resource, | ||
authorization_verification_input.action, | ||
auth_verifier.auth_info, | ||
) |
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
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,27 @@ | ||
import http | ||
|
||
import fastapi.testclient | ||
import sqlalchemy.orm | ||
|
||
import mlrun.api.schemas | ||
import mlrun.api.utils.clients.opa | ||
|
||
|
||
def test_verify_authorization( | ||
db: sqlalchemy.orm.Session, client: fastapi.testclient.TestClient | ||
) -> None: | ||
authorization_verification_input = mlrun.api.schemas.AuthorizationVerificationInput( | ||
resource="/some-resource", action=mlrun.api.schemas.AuthorizationAction.create | ||
) | ||
|
||
def _mock_successful_query_permissions(resource, action, *args): | ||
assert authorization_verification_input.resource == resource | ||
assert authorization_verification_input.action == action | ||
|
||
mlrun.api.utils.clients.opa.Client().query_permissions = ( | ||
_mock_successful_query_permissions | ||
) | ||
response = client.post( | ||
"/api/authorization/verifications", json=authorization_verification_input.dict() | ||
) | ||
assert response.status_code == http.HTTPStatus.OK.value |