-
Notifications
You must be signed in to change notification settings - Fork 32
♻️ Refactor API-keys service #6843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
giancarloromeo
merged 82 commits into
ITISFoundation:master
from
giancarloromeo:refactor-api-keys-service
Dec 10, 2024
Merged
Changes from 74 commits
Commits
Show all changes
82 commits
Select commit
Hold shift + click to select a range
4439836
rename rest handler module
giancarloromeo 2b3fb09
begin refactor
giancarloromeo 7d0f37c
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 8aac0bf
refactor delete
giancarloromeo 6579e4c
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 6852510
add id
giancarloromeo d10edfb
use list comprehension
giancarloromeo 26e33f9
add base_url
giancarloromeo 71c334c
services/webserver api version: 0.46.0 → 0.47.0
giancarloromeo 9b30844
update openapi-spec
giancarloromeo 25e96b0
continue refactor
giancarloromeo 3e6b3a9
fix query param name
giancarloromeo cd416cc
refactor rpc
giancarloromeo de81e9c
refactor exception handling
giancarloromeo 08183d6
update API spec
giancarloromeo a566850
Merge branch 'master' into refactor-api-keys-service
giancarloromeo fc73d01
fix exceptions handlers import
giancarloromeo 03aa944
fix api_base_url generation
giancarloromeo 1c5ced2
connect related issue
giancarloromeo d0b14e8
add test
giancarloromeo 777a9d6
fix test
giancarloromeo 5761e24
fix rpc
giancarloromeo 8814283
continue refactoring
giancarloromeo b2394c5
continue refactoring
giancarloromeo cde1e0e
fix column name
giancarloromeo 1e1b80c
continue refactoring
giancarloromeo bae24fc
fix typecheck
giancarloromeo 442635f
continue refactoring
giancarloromeo 834507a
fix rpc get key
giancarloromeo 0fd1e5d
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 56caa82
update openapi spec
giancarloromeo 4f09be2
fix typecheck
giancarloromeo cb7c873
remove errors
giancarloromeo a7e028a
use ID str
giancarloromeo a4ff6b3
rename symbols
giancarloromeo e29a971
continue refactoring
giancarloromeo 4809a02
fix sonar
giancarloromeo 4cad0bb
Merge branch 'master' into refactor-api-keys-service
giancarloromeo ad36509
fix director v2
giancarloromeo f7cfe72
Merge branch 'refactor-api-keys-service' of github.com:giancarloromeo…
giancarloromeo 91390d4
fix test
giancarloromeo 2ca2ba6
fix test
giancarloromeo 387a197
fix typecheck
giancarloromeo 29ea1c9
Merge branch 'master' into refactor-api-keys-service
giancarloromeo a5873b7
fix import
giancarloromeo ce3ed0a
rename
giancarloromeo e10dd19
separate models
giancarloromeo 0758689
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 5b64d0c
get and delete
odeimaiz 90295ec
camelCase
giancarloromeo 5e8c177
api_base_url
odeimaiz af62360
Merge branch 'refactor-api-keys-service' of github.com:giancarloromeo…
odeimaiz 198b3ce
camelCase
odeimaiz b58eef0
minor
odeimaiz 0fdb6f4
update examples
giancarloromeo 54f08fb
update examples
giancarloromeo cbb0278
add example
giancarloromeo 9b937d0
Copy Base Url
odeimaiz 5b22949
update example
giancarloromeo c10aec8
Merge pull request #3 from odeimaiz/odeimaiz-refactor/api-keys-service
giancarloromeo ff78470
silent sonar
giancarloromeo eceb799
Merge branch 'refactor-api-keys-service' of github.com:giancarloromeo…
giancarloromeo 9d4d02a
update test
giancarloromeo c530793
fix field name
giancarloromeo c8b30ca
fix schema models
giancarloromeo e7bba25
models
giancarloromeo 1271776
models
giancarloromeo c39f166
models
giancarloromeo d36fb00
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 6884100
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 5c8df32
comment
giancarloromeo 71b64db
Merge remote-tracking branch 'upstream/master' into refactor-api-keys…
giancarloromeo 08e4cd5
add issue ref
giancarloromeo 5dfe8e3
fix imports
giancarloromeo de1c021
fix test
giancarloromeo f6fee9a
Merge branch 'master' into refactor-api-keys-service
giancarloromeo 7857796
refactor rpc
giancarloromeo c773a50
Merge remote-tracking branch 'upstream/master' into refactor-api-keys…
giancarloromeo b55efd0
fix imports
giancarloromeo 277e0f9
fix package
giancarloromeo 59762a4
fix package
giancarloromeo d9dd232
Merge branch 'master' into refactor-api-keys-service
giancarloromeo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,60 @@ | ||
| from typing import Annotated | ||
|
|
||
| from fastapi import APIRouter, Depends, status | ||
| from models_library.api_schemas_webserver.auth import ( | ||
| ApiKeyCreateRequest, | ||
| ApiKeyCreateResponse, | ||
| ApiKeyGet, | ||
| ) | ||
| from models_library.generics import Envelope | ||
| from models_library.rest_error import EnvelopedError | ||
| from simcore_service_webserver._meta import API_VTAG | ||
| from simcore_service_webserver.api_keys._exceptions_handlers import _TO_HTTP_ERROR_MAP | ||
| from simcore_service_webserver.api_keys._rest import ApiKeysPathParams | ||
|
|
||
| router = APIRouter( | ||
| prefix=f"/{API_VTAG}", | ||
| tags=["auth"], | ||
| responses={ | ||
| i.status_code: {"model": EnvelopedError} for i in _TO_HTTP_ERROR_MAP.values() | ||
| }, | ||
| ) | ||
|
|
||
|
|
||
| @router.post( | ||
| "/auth/api-keys", | ||
| operation_id="create_api_key", | ||
| status_code=status.HTTP_201_CREATED, | ||
| response_model=Envelope[ApiKeyCreateResponse], | ||
| ) | ||
| async def create_api_key(_body: ApiKeyCreateRequest): | ||
| """creates API keys to access public API""" | ||
|
|
||
|
|
||
| @router.get( | ||
| "/auth/api-keys", | ||
| operation_id="list_api_keys", | ||
| response_model=Envelope[list[ApiKeyGet]], | ||
| status_code=status.HTTP_200_OK, | ||
| ) | ||
| async def list_api_keys(): | ||
| """lists API keys by this user""" | ||
|
|
||
|
|
||
| @router.get( | ||
| "/auth/api-keys/{api_key_id}", | ||
| operation_id="get_api_key", | ||
| response_model=Envelope[ApiKeyGet], | ||
| status_code=status.HTTP_200_OK, | ||
| ) | ||
| async def get_api_key(_path: Annotated[ApiKeysPathParams, Depends()]): | ||
| """returns the API Key with the given ID""" | ||
|
|
||
|
|
||
| @router.delete( | ||
| "/auth/api-keys/{api_key_id}", | ||
| operation_id="delete_api_key", | ||
| status_code=status.HTTP_204_NO_CONTENT, | ||
| ) | ||
| async def delete_api_key(_path: Annotated[ApiKeysPathParams, Depends()]): | ||
| """deletes the API key with the given ID""" |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| # | ||
| # core --- | ||
| "_auth", | ||
| "_auth_api_keys", | ||
| "_groups", | ||
| "_tags", | ||
| "_tags_groups", # after _tags | ||
|
|
||
This file contains hidden or 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
35 changes: 35 additions & 0 deletions
35
packages/models-library/src/models_library/rpc_auth_api_keys.py
This file contains hidden or 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,35 @@ | ||
| import datetime as dt | ||
| from typing import Annotated | ||
|
|
||
| from models_library.basic_types import IDStr | ||
| from pydantic import BaseModel, ConfigDict, Field | ||
|
|
||
|
|
||
| class ApiKeyCreate(BaseModel): | ||
| display_name: Annotated[str, Field(..., min_length=3)] | ||
| expiration: dt.timedelta | None = None | ||
|
|
||
| model_config = ConfigDict( | ||
| from_attributes=True, | ||
| ) | ||
|
|
||
|
|
||
| class ApiKeyGet(BaseModel): | ||
| id: IDStr | ||
| display_name: Annotated[str, Field(..., min_length=3)] | ||
| api_key: str | None = None | ||
giancarloromeo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| api_secret: str | None = None | ||
|
|
||
| model_config = ConfigDict( | ||
| from_attributes=True, | ||
| json_schema_extra={ | ||
| "examples": [ | ||
| { | ||
| "id": "42", | ||
| "display_name": "test-api-forever", | ||
| "api_key": "key", | ||
| "api_secret": "secret", | ||
| }, | ||
| ] | ||
| }, | ||
| ) | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.