Skip to content

feat(iam): add listing of user connections #887

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
Mar 6, 2025
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
10 changes: 10 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from .types import UserStatus
from .types import UserType
from .types import QuotumLimit
from .types import ListUserConnectionsResponseConnectionConnectedOrganization
from .types import ListUserConnectionsResponseConnectionConnectedUser
from .types import JWT
from .types import RuleSpecs
from .types import CreateUserRequestMember
Expand All @@ -32,6 +34,7 @@
from .types import Quotum
from .types import Rule
from .types import SSHKey
from .types import ListUserConnectionsResponseConnection
from .types import User
from .types import AddGroupMemberRequest
from .types import AddGroupMembersRequest
Expand Down Expand Up @@ -85,6 +88,8 @@
from .types import ListRulesResponse
from .types import ListSSHKeysRequest
from .types import ListSSHKeysResponse
from .types import ListUserConnectionsRequest
from .types import ListUserConnectionsResponse
from .types import ListUsersRequest
from .types import ListUsersResponse
from .types import LockUserRequest
Expand Down Expand Up @@ -128,6 +133,8 @@
"UserStatus",
"UserType",
"QuotumLimit",
"ListUserConnectionsResponseConnectionConnectedOrganization",
"ListUserConnectionsResponseConnectionConnectedUser",
"JWT",
"RuleSpecs",
"CreateUserRequestMember",
Expand All @@ -141,6 +148,7 @@
"Quotum",
"Rule",
"SSHKey",
"ListUserConnectionsResponseConnection",
"User",
"AddGroupMemberRequest",
"AddGroupMembersRequest",
Expand Down Expand Up @@ -194,6 +202,8 @@
"ListRulesResponse",
"ListSSHKeysRequest",
"ListSSHKeysResponse",
"ListUserConnectionsRequest",
"ListUserConnectionsResponse",
"ListUsersRequest",
"ListUsersResponse",
"LockUserRequest",
Expand Down
29 changes: 29 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ListQuotaResponse,
ListRulesResponse,
ListSSHKeysResponse,
ListUserConnectionsResponse,
ListUsersResponse,
Log,
MFAOTP,
Expand Down Expand Up @@ -101,6 +102,7 @@
unmarshal_ListQuotaResponse,
unmarshal_ListRulesResponse,
unmarshal_ListSSHKeysResponse,
unmarshal_ListUserConnectionsResponse,
unmarshal_ListUsersResponse,
unmarshal_MFAOTP,
unmarshal_OrganizationSecuritySettings,
Expand Down Expand Up @@ -851,6 +853,33 @@ async def list_grace_periods(
self._throw_on_error(res)
return unmarshal_ListGracePeriodsResponse(res.json())

async def list_user_connections(
self,
*,
user_id: str,
) -> ListUserConnectionsResponse:
"""
:param user_id: ID of the user to list connections for.
:return: :class:`ListUserConnectionsResponse <ListUserConnectionsResponse>`

Usage:
::

result = await api.list_user_connections(
user_id="example",
)
"""

param_user_id = validate_path_param("user_id", user_id)

res = self._request(
"GET",
f"/iam/v1alpha1/users/{param_user_id}/connections",
)

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

async def list_applications(
self,
*,
Expand Down
102 changes: 102 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
Rule,
ListRulesResponse,
ListSSHKeysResponse,
ListUserConnectionsResponseConnectionConnectedOrganization,
ListUserConnectionsResponseConnectionConnectedUser,
ListUserConnectionsResponseConnection,
ListUserConnectionsResponse,
ListUsersResponse,
MFAOTP,
OrganizationSecuritySettings,
Expand Down Expand Up @@ -1030,6 +1034,104 @@ def unmarshal_ListSSHKeysResponse(data: Any) -> ListSSHKeysResponse:
return ListSSHKeysResponse(**args)


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

args: Dict[str, Any] = {}

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

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

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

return ListUserConnectionsResponseConnectionConnectedOrganization(**args)


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

args: Dict[str, Any] = {}

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

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

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

return ListUserConnectionsResponseConnectionConnectedUser(**args)


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

args: Dict[str, Any] = {}

field = data.get("organization", None)
if field is not None:
args["organization"] = (
unmarshal_ListUserConnectionsResponseConnectionConnectedOrganization(field)
)
else:
args["organization"] = None

field = data.get("user", None)
if field is not None:
args["user"] = unmarshal_ListUserConnectionsResponseConnectionConnectedUser(
field
)
else:
args["user"] = None

return ListUserConnectionsResponseConnection(**args)


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

args: Dict[str, Any] = {}

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

return ListUserConnectionsResponse(**args)


def unmarshal_ListUsersResponse(data: Any) -> ListUsersResponse:
if not isinstance(data, dict):
raise TypeError(
Expand Down
47 changes: 47 additions & 0 deletions scaleway-async/scaleway_async/iam/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,24 @@ class QuotumLimit:
unlimited: Optional[bool]


@dataclass
class ListUserConnectionsResponseConnectionConnectedOrganization:
id: str

name: str

locked: bool


@dataclass
class ListUserConnectionsResponseConnectionConnectedUser:
id: str

username: str

type_: UserType


@dataclass
class JWT:
jti: str
Expand Down Expand Up @@ -774,6 +792,19 @@ class SSHKey:
"""


@dataclass
class ListUserConnectionsResponseConnection:
organization: Optional[ListUserConnectionsResponseConnectionConnectedOrganization]
"""
Information about the connected organization.
"""

user: Optional[ListUserConnectionsResponseConnectionConnectedUser]
"""
Information about the connected user.
"""


@dataclass
class User:
id: str
Expand Down Expand Up @@ -1750,6 +1781,22 @@ class ListSSHKeysResponse:
"""


@dataclass
class ListUserConnectionsRequest:
user_id: str
"""
ID of the user to list connections for.
"""


@dataclass
class ListUserConnectionsResponse:
connections: List[ListUserConnectionsResponseConnection]
"""
List of connections.
"""


@dataclass
class ListUsersRequest:
order_by: Optional[ListUsersRequestOrderBy]
Expand Down
10 changes: 10 additions & 0 deletions scaleway/scaleway/iam/v1alpha1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
from .types import UserStatus
from .types import UserType
from .types import QuotumLimit
from .types import ListUserConnectionsResponseConnectionConnectedOrganization
from .types import ListUserConnectionsResponseConnectionConnectedUser
from .types import JWT
from .types import RuleSpecs
from .types import CreateUserRequestMember
Expand All @@ -32,6 +34,7 @@
from .types import Quotum
from .types import Rule
from .types import SSHKey
from .types import ListUserConnectionsResponseConnection
from .types import User
from .types import AddGroupMemberRequest
from .types import AddGroupMembersRequest
Expand Down Expand Up @@ -85,6 +88,8 @@
from .types import ListRulesResponse
from .types import ListSSHKeysRequest
from .types import ListSSHKeysResponse
from .types import ListUserConnectionsRequest
from .types import ListUserConnectionsResponse
from .types import ListUsersRequest
from .types import ListUsersResponse
from .types import LockUserRequest
Expand Down Expand Up @@ -128,6 +133,8 @@
"UserStatus",
"UserType",
"QuotumLimit",
"ListUserConnectionsResponseConnectionConnectedOrganization",
"ListUserConnectionsResponseConnectionConnectedUser",
"JWT",
"RuleSpecs",
"CreateUserRequestMember",
Expand All @@ -141,6 +148,7 @@
"Quotum",
"Rule",
"SSHKey",
"ListUserConnectionsResponseConnection",
"User",
"AddGroupMemberRequest",
"AddGroupMembersRequest",
Expand Down Expand Up @@ -194,6 +202,8 @@
"ListRulesResponse",
"ListSSHKeysRequest",
"ListSSHKeysResponse",
"ListUserConnectionsRequest",
"ListUserConnectionsResponse",
"ListUsersRequest",
"ListUsersResponse",
"LockUserRequest",
Expand Down
29 changes: 29 additions & 0 deletions scaleway/scaleway/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
ListQuotaResponse,
ListRulesResponse,
ListSSHKeysResponse,
ListUserConnectionsResponse,
ListUsersResponse,
Log,
MFAOTP,
Expand Down Expand Up @@ -101,6 +102,7 @@
unmarshal_ListQuotaResponse,
unmarshal_ListRulesResponse,
unmarshal_ListSSHKeysResponse,
unmarshal_ListUserConnectionsResponse,
unmarshal_ListUsersResponse,
unmarshal_MFAOTP,
unmarshal_OrganizationSecuritySettings,
Expand Down Expand Up @@ -851,6 +853,33 @@ def list_grace_periods(
self._throw_on_error(res)
return unmarshal_ListGracePeriodsResponse(res.json())

def list_user_connections(
self,
*,
user_id: str,
) -> ListUserConnectionsResponse:
"""
:param user_id: ID of the user to list connections for.
:return: :class:`ListUserConnectionsResponse <ListUserConnectionsResponse>`

Usage:
::

result = api.list_user_connections(
user_id="example",
)
"""

param_user_id = validate_path_param("user_id", user_id)

res = self._request(
"GET",
f"/iam/v1alpha1/users/{param_user_id}/connections",
)

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

def list_applications(
self,
*,
Expand Down
Loading