-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new IsService from toolkit (#2473)
- Loading branch information
1 parent
7e1b238
commit ff182dd
Showing
9 changed files
with
146 additions
and
158 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,24 +1,9 @@ | ||
import jwt | ||
from pythonit_toolkit.headers import SERVICE_JWT_HEADER | ||
from pythonit_toolkit.pastaporto.tokens import decode_service_to_service_token | ||
from starlette.requests import Request | ||
from pythonit_toolkit.api.permissions import IsService as BaseIsService | ||
|
||
from users.settings import SERVICE_TO_SERVICE_SECRET | ||
|
||
|
||
def is_service(request: Request) -> bool: | ||
token = request.headers.get(SERVICE_JWT_HEADER) | ||
secret = str(SERVICE_TO_SERVICE_SECRET) | ||
|
||
try: | ||
decode_service_to_service_token( | ||
token, secret, issuer="gateway", audience="users-service" | ||
) | ||
return True | ||
except ( | ||
jwt.DecodeError, | ||
jwt.InvalidIssuerError, | ||
jwt.ExpiredSignatureError, | ||
jwt.InvalidAudienceError, | ||
): | ||
return False | ||
def IsService(allowed_callers: list[str]): | ||
return BaseIsService( | ||
allowed_callers, str(SERVICE_TO_SERVICE_SECRET), "users-backend" | ||
) |
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,38 +1,41 @@ | ||
from asgi_lifespan import LifespanManager | ||
from httpx import AsyncClient | ||
from main import app | ||
from pythonit_toolkit.api.graphql_test_client import GraphQLClient | ||
from ward import Scope, fixture | ||
|
||
from main import app | ||
from users.settings import PASTAPORTO_SECRET, SERVICE_TO_SERVICE_SECRET | ||
from ward import fixture | ||
|
||
|
||
@fixture(scope=Scope.Global) | ||
async def client(): | ||
async with AsyncClient(app=app, base_url="http://testserver") as async_client: | ||
yield async_client | ||
|
||
|
||
@fixture | ||
async def testclient(): | ||
async def testclient(client=client): | ||
async with LifespanManager(app): | ||
async with AsyncClient(app=app, base_url="http://testserver") as client: | ||
yield client | ||
yield client | ||
|
||
|
||
@fixture() | ||
async def graphql_client(testclient=testclient): | ||
async with testclient: | ||
yield GraphQLClient(testclient, pastaporto_secret=PASTAPORTO_SECRET) | ||
yield GraphQLClient(testclient, pastaporto_secret=PASTAPORTO_SECRET) | ||
|
||
|
||
@fixture() | ||
async def admin_graphql_client(testclient=testclient): | ||
async with testclient: | ||
yield GraphQLClient( | ||
testclient, admin_endpoint=True, pastaporto_secret=PASTAPORTO_SECRET | ||
) | ||
yield GraphQLClient( | ||
testclient, admin_endpoint=True, pastaporto_secret=PASTAPORTO_SECRET | ||
) | ||
|
||
|
||
@fixture() | ||
async def internalapi_graphql_client(testclient=testclient): | ||
async with testclient: | ||
yield GraphQLClient( | ||
testclient, | ||
internal_api_endpoint=True, | ||
pastaporto_secret=PASTAPORTO_SECRET, | ||
service_to_service_secret=SERVICE_TO_SERVICE_SECRET, | ||
) | ||
yield GraphQLClient( | ||
testclient, | ||
internal_api_endpoint=True, | ||
pastaporto_secret=PASTAPORTO_SECRET, | ||
service_to_service_secret=SERVICE_TO_SERVICE_SECRET, | ||
) |