Skip to content

Commit d3b5993

Browse files
authored
Apikeyid (#168)
* add current api key property * version * version * version * remove -q * install wheel package * clarfications * fix
1 parent 8706db3 commit d3b5993

13 files changed

Lines changed: 40 additions & 4 deletions

File tree

.github/workflows/test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ jobs:
2828
with:
2929
python-version: ${{ matrix.python-version }}
3030
- name: Install dependencies
31-
run: make install-test
31+
run: |
32+
# corregir https://github.com/cuenca-mx/agave/issues/169
33+
pip install -qU pip setuptools wheel
34+
make install-test
3235
- name: Run tests
3336
run: pytest
3437

agave/chalice/rest_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ def current_user_id(self):
3838
def current_platform_id(self):
3939
return self.current_request.platform_id
4040

41+
@property
42+
def current_api_key_id(self):
43+
return self.current_request.api_key_id
44+
4145
def user_id_filter_required(self):
4246
"""
4347
This method is required to be implemented with your own business logic.

agave/fastapi/rest_api.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ def current_user_id(self) -> str:
4242
def current_platform_id(self) -> str:
4343
return context['platform_id']
4444

45+
@property
46+
def current_api_key_id(self) -> str:
47+
return context['api_key_id']
48+
4549
def user_id_filter_required(self) -> bool:
4650
return context['user_id_filter_required']
4751

agave/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.3.3'
1+
__version__ = '1.4.0'

examples/chalice/blueprints/authed.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33

44
from chalice import Blueprint
55

6-
from ...config import TEST_DEFAULT_PLATFORM_ID, TEST_DEFAULT_USER_ID
6+
from ...config import (
7+
TEST_DEFAULT_API_KEY_ID,
8+
TEST_DEFAULT_PLATFORM_ID,
9+
TEST_DEFAULT_USER_ID,
10+
)
711

812

913
class AuthedBlueprint(Blueprint):
@@ -32,6 +36,7 @@ def authed_handler(*args, **kwargs):
3236
# before execute `user_handler` function.
3337
self.current_request.user_id = TEST_DEFAULT_USER_ID
3438
self.current_request.platform_id = TEST_DEFAULT_PLATFORM_ID
39+
self.current_request.api_key_id = TEST_DEFAULT_API_KEY_ID
3540
return user_handler(*args, **kwargs)
3641

3742
self._register_handler( # type: ignore

examples/chalice/resources/accounts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def create(request: AccountRequest) -> Response:
2323
name=request.name,
2424
user_id=app.current_user_id,
2525
platform_id=app.current_platform_id,
26+
api_key_id=app.current_api_key_id,
2627
)
2728
account.save()
2829
return Response(account.to_dict(), status_code=201)

examples/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
TEST_DEFAULT_USER_ID = 'US123456789'
22
TEST_DEFAULT_PLATFORM_ID = 'PT123456'
3+
TEST_DEFAULT_API_KEY_ID = 'AK123456789'
34
TEST_SECOND_USER_ID = 'US987654321'
45
TEST_SECOND_PLATFORM_ID = 'PT987654321'
6+
TEST_SECOND_API_KEY_ID = 'AK987654321'

examples/fastapi/middlewares/authed.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
from starlette_context import _request_scope_context_storage
55
from starlette_context.middleware import ContextMiddleware
66

7-
from ...config import TEST_DEFAULT_PLATFORM_ID, TEST_DEFAULT_USER_ID
7+
from ...config import (
8+
TEST_DEFAULT_API_KEY_ID,
9+
TEST_DEFAULT_PLATFORM_ID,
10+
TEST_DEFAULT_USER_ID,
11+
)
812

913

1014
class AuthedMiddleware(ContextMiddleware):
@@ -38,6 +42,7 @@ async def authenticate(self):
3842
dict(
3943
user_id=TEST_DEFAULT_USER_ID,
4044
platform_id=TEST_DEFAULT_PLATFORM_ID,
45+
api_key_id=TEST_DEFAULT_API_KEY_ID,
4146
)
4247
)
4348

examples/fastapi/resources/accounts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ async def create(request: AccountRequest) -> Response:
3030
name=request.name,
3131
user_id=app.current_user_id,
3232
platform_id=app.current_platform_id,
33+
api_key_id=app.current_api_key_id,
3334
)
3435
await account.async_save()
3536
return Response(content=account.to_dict(), status_code=201)

examples/models/accounts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ class Account(BaseModel, AsyncDocument):
99
name = StringField(required=True)
1010
user_id = StringField(required=True)
1111
platform_id = StringField(required=True)
12+
api_key_id = StringField(required=True)
1213
created_at = DateTimeField()
1314
deactivated_at = DateTimeField()

0 commit comments

Comments
 (0)