Skip to content

Commit

Permalink
feat: update generated APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot committed Mar 15, 2024
1 parent f00ca20 commit 15ceffb
Show file tree
Hide file tree
Showing 8 changed files with 288 additions and 36 deletions.
2 changes: 2 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .types import UserType
from .types import APIKey
from .types import Application
from .types import EncodedJWT
from .types import Group
from .types import JWT
from .types import ListAPIKeysResponse
Expand Down Expand Up @@ -61,6 +62,7 @@
"UserType",
"APIKey",
"Application",
"EncodedJWT",
"Group",
"JWT",
"ListAPIKeysResponse",
Expand Down
40 changes: 40 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
LogResourceType,
APIKey,
Application,
EncodedJWT,
Group,
JWT,
ListAPIKeysResponse,
Expand Down Expand Up @@ -67,13 +68,15 @@
SetRulesRequest,
CreateAPIKeyRequest,
UpdateAPIKeyRequest,
CreateJWTRequest,
)
from .marshalling import (
marshal_AddGroupMemberRequest,
marshal_AddGroupMembersRequest,
marshal_CreateAPIKeyRequest,
marshal_CreateApplicationRequest,
marshal_CreateGroupRequest,
marshal_CreateJWTRequest,
marshal_CreatePolicyRequest,
marshal_CreateSSHKeyRequest,
marshal_CreateUserRequest,
Expand All @@ -95,6 +98,7 @@
unmarshal_Quotum,
unmarshal_SSHKey,
unmarshal_User,
unmarshal_EncodedJWT,
unmarshal_ListAPIKeysResponse,
unmarshal_ListApplicationsResponse,
unmarshal_ListGroupsResponse,
Expand Down Expand Up @@ -2154,6 +2158,42 @@ async def list_jw_ts_all(
},
)

async def create_jwt(
self,
*,
user_id: str,
referrer: str,
) -> EncodedJWT:
"""
Create a JWT.
:param user_id: ID of the user the JWT will be created for.
:param referrer: Referrer of the JWT.
:return: :class:`EncodedJWT <EncodedJWT>`
Usage:
::
result = await api.create_jwt(
user_id="example",
referrer="example",
)
"""

res = self._request(
"POST",
f"/iam/v1alpha1/jwts",
body=marshal_CreateJWTRequest(
CreateJWTRequest(
user_id=user_id,
referrer=referrer,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_EncodedJWT(res.json())

async def get_jwt(
self,
*,
Expand Down
85 changes: 67 additions & 18 deletions scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .types import (
APIKey,
Application,
EncodedJWT,
Group,
JWT,
ListAPIKeysResponse,
Expand Down Expand Up @@ -51,6 +52,7 @@
SetRulesRequest,
CreateAPIKeyRequest,
UpdateAPIKeyRequest,
CreateJWTRequest,
)


Expand Down Expand Up @@ -466,6 +468,26 @@ def unmarshal_User(data: Any) -> User:
return User(**args)


def unmarshal_EncodedJWT(data: Any) -> EncodedJWT:
if type(data) is not dict:
raise TypeError(
f"Unmarshalling the type 'EncodedJWT' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("jwt", None)
args["jwt"] = unmarshal_JWT(field) if field is not None else None

field = data.get("renew_token", None)
args["renew_token"] = field

field = data.get("token", None)
args["token"] = field

return EncodedJWT(**args)


def unmarshal_ListAPIKeysResponse(data: Any) -> ListAPIKeysResponse:
if type(data) is not dict:
raise TypeError(
Expand Down Expand Up @@ -691,9 +713,11 @@ def marshal_RuleSpecs(
),
OneOfPossibility(
"organization_id",
request.organization_id
if request.organization_id is not None
else None,
(
request.organization_id
if request.organization_id is not None
else None
),
defaults.default_organization_id,
),
]
Expand All @@ -719,9 +743,11 @@ def marshal_AddGroupMemberRequest(
),
OneOfPossibility(
"application_id",
request.application_id
if request.application_id is not None
else None,
(
request.application_id
if request.application_id is not None
else None
),
),
]
),
Expand Down Expand Up @@ -755,9 +781,11 @@ def marshal_CreateAPIKeyRequest(
[
OneOfPossibility(
"application_id",
request.application_id
if request.application_id is not None
else None,
(
request.application_id
if request.application_id is not None
else None
),
),
OneOfPossibility(
"user_id", request.user_id if request.user_id is not None else None
Expand Down Expand Up @@ -824,6 +852,21 @@ def marshal_CreateGroupRequest(
return output


def marshal_CreateJWTRequest(
request: CreateJWTRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

if request.referrer is not None:
output["referrer"] = request.referrer

if request.user_id is not None:
output["user_id"] = request.user_id

return output


def marshal_CreatePolicyRequest(
request: CreatePolicyRequest,
defaults: ProfileDefaults,
Expand All @@ -841,9 +884,11 @@ def marshal_CreatePolicyRequest(
),
OneOfPossibility(
"application_id",
request.application_id
if request.application_id is not None
else None,
(
request.application_id
if request.application_id is not None
else None
),
),
OneOfPossibility(
"no_principal",
Expand Down Expand Up @@ -924,9 +969,11 @@ def marshal_RemoveGroupMemberRequest(
),
OneOfPossibility(
"application_id",
request.application_id
if request.application_id is not None
else None,
(
request.application_id
if request.application_id is not None
else None
),
),
]
),
Expand Down Expand Up @@ -1033,9 +1080,11 @@ def marshal_UpdatePolicyRequest(
),
OneOfPossibility(
"application_id",
request.application_id
if request.application_id is not None
else None,
(
request.application_id
if request.application_id is not None
else None
),
),
OneOfPossibility(
"no_principal",
Expand Down
35 changes: 35 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,28 @@ class Application:
"""


@dataclass
class EncodedJWT:
"""
Encoded jwt.
"""

jwt: Optional[JWT]
"""
The renewed JWT.
"""

token: str
"""
The encoded token of the renewed JWT.
"""

renew_token: str
"""
The encoded renew token. This token is necessary to renew the JWT.
"""


@dataclass
class Group:
"""
Expand Down Expand Up @@ -1886,6 +1908,19 @@ class ListJWTsRequest:
"""


@dataclass
class CreateJWTRequest:
user_id: str
"""
ID of the user the JWT will be created for.
"""

referrer: str
"""
Referrer of the JWT.
"""


@dataclass
class GetJWTRequest:
jti: str
Expand Down
2 changes: 2 additions & 0 deletions scaleway/scaleway/iam/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from .types import UserType
from .types import APIKey
from .types import Application
from .types import EncodedJWT
from .types import Group
from .types import JWT
from .types import ListAPIKeysResponse
Expand Down Expand Up @@ -61,6 +62,7 @@
"UserType",
"APIKey",
"Application",
"EncodedJWT",
"Group",
"JWT",
"ListAPIKeysResponse",
Expand Down
40 changes: 40 additions & 0 deletions scaleway/scaleway/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
LogResourceType,
APIKey,
Application,
EncodedJWT,
Group,
JWT,
ListAPIKeysResponse,
Expand Down Expand Up @@ -67,13 +68,15 @@
SetRulesRequest,
CreateAPIKeyRequest,
UpdateAPIKeyRequest,
CreateJWTRequest,
)
from .marshalling import (
marshal_AddGroupMemberRequest,
marshal_AddGroupMembersRequest,
marshal_CreateAPIKeyRequest,
marshal_CreateApplicationRequest,
marshal_CreateGroupRequest,
marshal_CreateJWTRequest,
marshal_CreatePolicyRequest,
marshal_CreateSSHKeyRequest,
marshal_CreateUserRequest,
Expand All @@ -95,6 +98,7 @@
unmarshal_Quotum,
unmarshal_SSHKey,
unmarshal_User,
unmarshal_EncodedJWT,
unmarshal_ListAPIKeysResponse,
unmarshal_ListApplicationsResponse,
unmarshal_ListGroupsResponse,
Expand Down Expand Up @@ -2154,6 +2158,42 @@ def list_jw_ts_all(
},
)

def create_jwt(
self,
*,
user_id: str,
referrer: str,
) -> EncodedJWT:
"""
Create a JWT.
:param user_id: ID of the user the JWT will be created for.
:param referrer: Referrer of the JWT.
:return: :class:`EncodedJWT <EncodedJWT>`
Usage:
::
result = api.create_jwt(
user_id="example",
referrer="example",
)
"""

res = self._request(
"POST",
f"/iam/v1alpha1/jwts",
body=marshal_CreateJWTRequest(
CreateJWTRequest(
user_id=user_id,
referrer=referrer,
),
self.client,
),
)

self._throw_on_error(res)
return unmarshal_EncodedJWT(res.json())

def get_jwt(
self,
*,
Expand Down
Loading

0 comments on commit 15ceffb

Please sign in to comment.