Skip to content

feat(iam): add list user grace periods method #759

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
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import BearerType
from .types import GracePeriodType
from .types import ListAPIKeysRequestOrderBy
from .types import ListApplicationsRequestOrderBy
from .types import ListGroupsRequestOrderBy
Expand All @@ -21,6 +22,7 @@
from .types import CreateUserRequestMember
from .types import APIKey
from .types import Application
from .types import GracePeriod
from .types import Group
from .types import Log
from .types import PermissionSet
Expand Down Expand Up @@ -60,6 +62,8 @@
from .types import ListAPIKeysResponse
from .types import ListApplicationsRequest
from .types import ListApplicationsResponse
from .types import ListGracePeriodsRequest
from .types import ListGracePeriodsResponse
from .types import ListGroupsRequest
from .types import ListGroupsResponse
from .types import ListJWTsRequest
Expand Down Expand Up @@ -95,6 +99,7 @@

__all__ = [
"BearerType",
"GracePeriodType",
"ListAPIKeysRequestOrderBy",
"ListApplicationsRequestOrderBy",
"ListGroupsRequestOrderBy",
Expand All @@ -115,6 +120,7 @@
"CreateUserRequestMember",
"APIKey",
"Application",
"GracePeriod",
"Group",
"Log",
"PermissionSet",
Expand Down Expand Up @@ -154,6 +160,8 @@
"ListAPIKeysResponse",
"ListApplicationsRequest",
"ListApplicationsResponse",
"ListGracePeriodsRequest",
"ListGracePeriodsResponse",
"ListGroupsRequest",
"ListGroupsResponse",
"ListJWTsRequest",
Expand Down
34 changes: 32 additions & 2 deletions scaleway-async/scaleway_async/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
JWT,
ListAPIKeysResponse,
ListApplicationsResponse,
ListGracePeriodsResponse,
ListGroupsResponse,
ListJWTsResponse,
ListLogsResponse,
Expand Down Expand Up @@ -85,6 +86,7 @@
unmarshal_EncodedJWT,
unmarshal_ListAPIKeysResponse,
unmarshal_ListApplicationsResponse,
unmarshal_ListGracePeriodsResponse,
unmarshal_ListGroupsResponse,
unmarshal_ListJWTsResponse,
unmarshal_ListLogsResponse,
Expand Down Expand Up @@ -629,7 +631,7 @@ async def lock_user(
"""
Lock a user.
Lock a user. Note that a locked user cannot log in or use API keys until the locked status is removed.
:param user_id:
:param user_id: ID of the user to lock.
:return: :class:`User <User>`

Usage:
Expand Down Expand Up @@ -658,7 +660,7 @@ async def unlock_user(
) -> User:
"""
Unlock a user.
:param user_id:
:param user_id: ID of the user to unlock.
:return: :class:`User <User>`

Usage:
Expand All @@ -680,6 +682,34 @@ async def unlock_user(
self._throw_on_error(res)
return unmarshal_User(res.json())

async def list_grace_periods(
self,
*,
user_id: Optional[str] = None,
) -> ListGracePeriodsResponse:
"""
List grace periods of a user.
List the grace periods of a user.
:param user_id: ID of the user to list grace periods for.
:return: :class:`ListGracePeriodsResponse <ListGracePeriodsResponse>`

Usage:
::

result = await api.list_grace_periods()
"""

res = self._request(
"GET",
"/iam/v1alpha1/grace-periods",
params={
"user_id": user_id,
},
)

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

async def list_applications(
self,
*,
Expand Down
46 changes: 46 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
EncodedJWT,
ListAPIKeysResponse,
ListApplicationsResponse,
GracePeriod,
ListGracePeriodsResponse,
ListGroupsResponse,
ListJWTsResponse,
ListLogsResponse,
Expand Down Expand Up @@ -682,6 +684,50 @@ def unmarshal_ListApplicationsResponse(data: Any) -> ListApplicationsResponse:
return ListApplicationsResponse(**args)


def unmarshal_GracePeriod(data: Any) -> GracePeriod:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'GracePeriod' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("type", None)
if field is not None:
args["type_"] = field

field = data.get("created_at", None)
if field is not None:
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["created_at"] = None

field = data.get("expires_at", None)
if field is not None:
args["expires_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["expires_at"] = None

return GracePeriod(**args)


def unmarshal_ListGracePeriodsResponse(data: Any) -> ListGracePeriodsResponse:
if not isinstance(data, dict):
raise TypeError(
"Unmarshalling the type 'ListGracePeriodsResponse' failed as data isn't a dictionary."
)

args: Dict[str, Any] = {}

field = data.get("grace_periods", None)
if field is not None:
args["grace_periods"] = (
[unmarshal_GracePeriod(v) for v in field] if field is not None else None
)

return ListGracePeriodsResponse(**args)


def unmarshal_ListGroupsResponse(data: Any) -> ListGroupsResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down
49 changes: 49 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ def __str__(self) -> str:
return str(self.value)


class GracePeriodType(str, Enum, metaclass=StrEnumMeta):
UNKNOWN_GRACE_PERIOD_TYPE = "unknown_grace_period_type"
UPDATE_PASSWORD = "update_password"
SET_MFA = "set_mfa"

def __str__(self) -> str:
return str(self.value)


class ListAPIKeysRequestOrderBy(str, Enum, metaclass=StrEnumMeta):
CREATED_AT_ASC = "created_at_asc"
CREATED_AT_DESC = "created_at_desc"
Expand Down Expand Up @@ -390,6 +399,24 @@ class Application:
"""


@dataclass
class GracePeriod:
type_: GracePeriodType
"""
Type of grace period.
"""

created_at: Optional[datetime]
"""
Date and time the grace period was created.
"""

expires_at: Optional[datetime]
"""
Date and time the grace period expires.
"""


@dataclass
class Group:
id: str
Expand Down Expand Up @@ -1253,6 +1280,22 @@ class ListApplicationsResponse:
"""


@dataclass
class ListGracePeriodsRequest:
user_id: Optional[str]
"""
ID of the user to list grace periods for.
"""


@dataclass
class ListGracePeriodsResponse:
grace_periods: List[GracePeriod]
"""
List of grace periods.
"""


@dataclass
class ListGroupsRequest:
order_by: Optional[ListGroupsRequestOrderBy]
Expand Down Expand Up @@ -1699,6 +1742,9 @@ class ListUsersResponse:
@dataclass
class LockUserRequest:
user_id: str
"""
ID of the user to lock.
"""


@dataclass
Expand Down Expand Up @@ -1746,6 +1792,9 @@ class SetRulesResponse:
@dataclass
class UnlockUserRequest:
user_id: str
"""
ID of the user to unlock.
"""


@dataclass
Expand Down
8 changes: 8 additions & 0 deletions scaleway/scaleway/iam/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This file was automatically generated. DO NOT EDIT.
# If you have any remark or suggestion do not hesitate to open an issue.
from .types import BearerType
from .types import GracePeriodType
from .types import ListAPIKeysRequestOrderBy
from .types import ListApplicationsRequestOrderBy
from .types import ListGroupsRequestOrderBy
Expand All @@ -21,6 +22,7 @@
from .types import CreateUserRequestMember
from .types import APIKey
from .types import Application
from .types import GracePeriod
from .types import Group
from .types import Log
from .types import PermissionSet
Expand Down Expand Up @@ -60,6 +62,8 @@
from .types import ListAPIKeysResponse
from .types import ListApplicationsRequest
from .types import ListApplicationsResponse
from .types import ListGracePeriodsRequest
from .types import ListGracePeriodsResponse
from .types import ListGroupsRequest
from .types import ListGroupsResponse
from .types import ListJWTsRequest
Expand Down Expand Up @@ -95,6 +99,7 @@

__all__ = [
"BearerType",
"GracePeriodType",
"ListAPIKeysRequestOrderBy",
"ListApplicationsRequestOrderBy",
"ListGroupsRequestOrderBy",
Expand All @@ -115,6 +120,7 @@
"CreateUserRequestMember",
"APIKey",
"Application",
"GracePeriod",
"Group",
"Log",
"PermissionSet",
Expand Down Expand Up @@ -154,6 +160,8 @@
"ListAPIKeysResponse",
"ListApplicationsRequest",
"ListApplicationsResponse",
"ListGracePeriodsRequest",
"ListGracePeriodsResponse",
"ListGroupsRequest",
"ListGroupsResponse",
"ListJWTsRequest",
Expand Down
34 changes: 32 additions & 2 deletions scaleway/scaleway/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
JWT,
ListAPIKeysResponse,
ListApplicationsResponse,
ListGracePeriodsResponse,
ListGroupsResponse,
ListJWTsResponse,
ListLogsResponse,
Expand Down Expand Up @@ -85,6 +86,7 @@
unmarshal_EncodedJWT,
unmarshal_ListAPIKeysResponse,
unmarshal_ListApplicationsResponse,
unmarshal_ListGracePeriodsResponse,
unmarshal_ListGroupsResponse,
unmarshal_ListJWTsResponse,
unmarshal_ListLogsResponse,
Expand Down Expand Up @@ -629,7 +631,7 @@ def lock_user(
"""
Lock a user.
Lock a user. Note that a locked user cannot log in or use API keys until the locked status is removed.
:param user_id:
:param user_id: ID of the user to lock.
:return: :class:`User <User>`

Usage:
Expand Down Expand Up @@ -658,7 +660,7 @@ def unlock_user(
) -> User:
"""
Unlock a user.
:param user_id:
:param user_id: ID of the user to unlock.
:return: :class:`User <User>`

Usage:
Expand All @@ -680,6 +682,34 @@ def unlock_user(
self._throw_on_error(res)
return unmarshal_User(res.json())

def list_grace_periods(
self,
*,
user_id: Optional[str] = None,
) -> ListGracePeriodsResponse:
"""
List grace periods of a user.
List the grace periods of a user.
:param user_id: ID of the user to list grace periods for.
:return: :class:`ListGracePeriodsResponse <ListGracePeriodsResponse>`

Usage:
::

result = api.list_grace_periods()
"""

res = self._request(
"GET",
"/iam/v1alpha1/grace-periods",
params={
"user_id": user_id,
},
)

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

def list_applications(
self,
*,
Expand Down
Loading