Skip to content

Commit af62360

Browse files
committed
Merge branch 'refactor-api-keys-service' of github.com:giancarloromeo/osparc-simcore into odeimaiz-refactor/api-keys-service
2 parents 5e8c177 + 90295ec commit af62360

File tree

3 files changed

+54
-45
lines changed
  • packages/models-library/src/models_library/api_schemas_webserver
  • services/web/server

3 files changed

+54
-45
lines changed

packages/models-library/src/models_library/api_schemas_webserver/auth.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from typing import Annotated, Any
33

44
from models_library.basic_types import IDStr
5-
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, SecretStr
5+
from pydantic import AliasGenerator, BaseModel, ConfigDict, Field, HttpUrl, SecretStr
66
from pydantic.alias_generators import to_camel
77

88
from ..emails import LowerCaseEmailStr
@@ -61,7 +61,9 @@ class ApiKeyCreateRequest(BaseModel):
6161
)
6262

6363
model_config = ConfigDict(
64-
alias_generator=to_camel,
64+
alias_generator=AliasGenerator(
65+
validation_alias=to_camel,
66+
),
6567
from_attributes=True,
6668
json_schema_extra={
6769
"examples": [
@@ -88,7 +90,9 @@ class ApiKeyCreateResponse(ApiKeyCreateRequest):
8890
api_secret: str
8991

9092
model_config = ConfigDict(
91-
alias_generator=to_camel,
93+
alias_generator=AliasGenerator(
94+
serialization_alias=to_camel,
95+
),
9296
from_attributes=True,
9397
json_schema_extra={
9498
"examples": [
@@ -125,7 +129,9 @@ class ApiKeyGet(BaseModel):
125129
display_name: Annotated[str, Field(..., min_length=3)]
126130

127131
model_config = ConfigDict(
128-
alias_generator=to_camel,
132+
alias_generator=AliasGenerator(
133+
serialization_alias=to_camel,
134+
),
129135
from_attributes=True,
130136
json_schema_extra={
131137
"examples": [

services/web/server/src/simcore_service_webserver/api/v0/openapi.yaml

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6731,10 +6731,10 @@ components:
67316731
title: Announcement
67326732
ApiKeyCreateRequest:
67336733
properties:
6734-
display_name:
6734+
displayName:
67356735
type: string
67366736
minLength: 3
6737-
title: Display Name
6737+
title: Displayname
67386738
expiration:
67396739
anyOf:
67406740
- type: string
@@ -6745,14 +6745,14 @@ components:
67456745
it does not expire.
67466746
type: object
67476747
required:
6748-
- display_name
6748+
- displayName
67496749
title: ApiKeyCreateRequest
67506750
ApiKeyCreateResponse:
67516751
properties:
6752-
display_name:
6752+
displayName:
67536753
type: string
67546754
minLength: 3
6755-
title: Display Name
6755+
title: Displayname
67566756
expiration:
67576757
anyOf:
67586758
- type: string
@@ -6766,25 +6766,22 @@ components:
67666766
maxLength: 100
67676767
minLength: 1
67686768
title: Id
6769-
api_base_url:
6769+
apiBaseUrl:
67706770
type: string
6771-
maxLength: 2083
6772-
minLength: 1
6773-
format: uri
6774-
title: Api Base Url
6775-
api_key:
6771+
title: Apibaseurl
6772+
apiKey:
67766773
type: string
6777-
title: Api Key
6778-
api_secret:
6774+
title: Apikey
6775+
apiSecret:
67796776
type: string
6780-
title: Api Secret
6777+
title: Apisecret
67816778
type: object
67826779
required:
6783-
- display_name
6780+
- displayName
67846781
- id
6785-
- api_base_url
6786-
- api_key
6787-
- api_secret
6782+
- apiBaseUrl
6783+
- apiKey
6784+
- apiSecret
67886785
title: ApiKeyCreateResponse
67896786
ApiKeyGet:
67906787
properties:
@@ -6793,14 +6790,14 @@ components:
67936790
maxLength: 100
67946791
minLength: 1
67956792
title: Id
6796-
display_name:
6793+
displayName:
67976794
type: string
67986795
minLength: 3
6799-
title: Display Name
6796+
title: Displayname
68006797
type: object
68016798
required:
68026799
- id
6803-
- display_name
6800+
- displayName
68046801
title: ApiKeyGet
68056802
AppStatusCheck:
68066803
properties:
@@ -7613,40 +7610,46 @@ components:
76137610
additionalProperties: false
76147611
type: object
76157612
title: EmptyModel
7616-
Envelope_ApiKeyCreateResponse_:
7613+
Envelope_AnyUrl_:
76177614
properties:
76187615
data:
76197616
anyOf:
7620-
- $ref: '#/components/schemas/ApiKeyCreateResponse'
7617+
- type: string
76217618
- type: 'null'
7622-
title: Envelope[ApiKeyCreateResponse]
7623-
Envelope_ApiKeyGet_:
7619+
title: Data
7620+
error:
7621+
anyOf:
7622+
- {}
7623+
- type: 'null'
7624+
title: Error
7625+
type: object
7626+
title: Envelope[AnyUrl]
7627+
Envelope_ApiKeyCreateResponse_:
76247628
properties:
76257629
data:
76267630
anyOf:
7627-
- $ref: '#/components/schemas/ApiKeyGet'
7631+
- $ref: '#/components/schemas/ApiKeyCreateResponse'
76287632
- type: 'null'
76297633
error:
76307634
anyOf:
76317635
- {}
76327636
- type: 'null'
76337637
title: Error
76347638
type: object
7635-
title: Envelope[ApiKeyGet]
7636-
Envelope_AnyUrl_:
7639+
title: Envelope[ApiKeyCreateResponse]
7640+
Envelope_ApiKeyGet_:
76377641
properties:
76387642
data:
76397643
anyOf:
7640-
- type: string
7644+
- $ref: '#/components/schemas/ApiKeyGet'
76417645
- type: 'null'
7642-
title: Data
76437646
error:
76447647
anyOf:
76457648
- {}
76467649
- type: 'null'
76477650
title: Error
76487651
type: object
7649-
title: Envelope[AnyUrl]
7652+
title: Envelope[ApiKeyGet]
76507653
Envelope_AppStatusCheck_:
76517654
properties:
76527655
data:

services/web/server/tests/unit/with_dbs/01/test_api_keys.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,18 @@ async def test_create_api_key(
9999
disable_gc_manual_guest_users: None,
100100
):
101101
display_name = "foo"
102-
resp = await client.post("/v0/auth/api-keys", json={"display_name": display_name})
102+
resp = await client.post("/v0/auth/api-keys", json={"displayName": display_name})
103103

104104
data, errors = await assert_status(resp, expected)
105105

106106
if not errors:
107-
assert data["display_name"] == display_name
108-
assert "api_key" in data
109-
assert "api_secret" in data
107+
assert data["displayName"] == display_name
108+
assert "apiKey" in data
109+
assert "apiSecret" in data
110110

111111
resp = await client.get("/v0/auth/api-keys")
112112
data, _ = await assert_status(resp, expected)
113-
assert [d["display_name"] for d in data] == [display_name]
113+
assert [d["displayName"] for d in data] == [display_name]
114114

115115

116116
@pytest.mark.parametrize(
@@ -150,19 +150,19 @@ async def test_create_api_key_with_expiration(
150150
expiration_interval = timedelta(seconds=1)
151151
resp = await client.post(
152152
"/v0/auth/api-keys",
153-
json={"display_name": "foo", "expiration": expiration_interval.seconds},
153+
json={"displayName": "foo", "expiration": expiration_interval.seconds},
154154
)
155155

156156
data, errors = await assert_status(resp, expected)
157157
if not errors:
158-
assert data["display_name"] == "foo"
159-
assert "api_key" in data
160-
assert "api_secret" in data
158+
assert data["displayName"] == "foo"
159+
assert "apiKey" in data
160+
assert "apiSecret" in data
161161

162162
# list created api-key
163163
resp = await client.get("/v0/auth/api-keys")
164164
data, _ = await assert_status(resp, expected)
165-
assert [d["display_name"] for d in data] == ["foo"]
165+
assert [d["displayName"] for d in data] == ["foo"]
166166

167167
# wait for api-key for it to expire and force-run scheduled task
168168
await asyncio.sleep(expiration_interval.seconds)

0 commit comments

Comments
 (0)