Skip to content
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
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 @@ -17,6 +17,7 @@
from .types import UserStatus
from .types import UserType
from .types import RuleSpecs
from .types import CreateUserRequestMember
from .types import JWT
from .types import APIKey
from .types import Application
Expand Down Expand Up @@ -107,6 +108,7 @@
"UserStatus",
"UserType",
"RuleSpecs",
"CreateUserRequestMember",
"JWT",
"APIKey",
"Application",
Expand Down
16 changes: 10 additions & 6 deletions scaleway-async/scaleway_async/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
CreatePolicyRequest,
CreateSSHKeyRequest,
CreateUserRequest,
CreateUserRequestMember,
EncodedJWT,
Group,
JWT,
Expand Down Expand Up @@ -534,34 +535,37 @@ async def delete_user(
async def create_user(
self,
*,
email: str,
organization_id: Optional[str] = None,
email: Optional[str] = None,
tags: Optional[List[str]] = None,
member: Optional[CreateUserRequestMember] = None,
) -> User:
"""
Create a new user.
Create a new user. You must define the `organization_id` and the `email` in your request.
:param email: Email of the user.
:param organization_id: ID of the Organization.
:param email: Email of the user.
One-Of ('type'): at most one of 'email', 'member' could be set.
:param tags: Tags associated with the user.
:param member: A new IAM Member to create.
One-Of ('type'): at most one of 'email', 'member' could be set.
:return: :class:`User <User>`

Usage:
::

result = await api.create_user(
email="example",
)
result = await api.create_user()
"""

res = self._request(
"POST",
"/iam/v1alpha1/users",
body=marshal_CreateUserRequest(
CreateUserRequest(
email=email,
organization_id=organization_id,
tags=tags,
email=email,
member=member,
),
self.client,
),
Expand Down
59 changes: 45 additions & 14 deletions scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
RuleSpecs,
CreatePolicyRequest,
CreateSSHKeyRequest,
CreateUserRequestMember,
CreateUserRequest,
RemoveGroupMemberRequest,
SetGroupMembersRequest,
Expand Down Expand Up @@ -512,10 +513,26 @@ def unmarshal_User(data: Any) -> User:
if field is not None:
args["email"] = field

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

field = data.get("organization_id", None)
if field is not None:
args["organization_id"] = 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("updated_at", None)
if field is not None:
args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["updated_at"] = None

field = data.get("deletable", None)
if field is not None:
args["deletable"] = field
Expand All @@ -528,12 +545,6 @@ def unmarshal_User(data: Any) -> User:
if field is not None:
args["status"] = 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("mfa", None)
if field is not None:
args["mfa"] = field
Expand All @@ -546,12 +557,6 @@ def unmarshal_User(data: Any) -> User:
if field is not None:
args["tags"] = field

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

field = data.get("last_login_at", None)
if field is not None:
args["last_login_at"] = (
Expand Down Expand Up @@ -1118,15 +1123,41 @@ def marshal_CreateSSHKeyRequest(
return output


def marshal_CreateUserRequest(
request: CreateUserRequest,
def marshal_CreateUserRequestMember(
request: CreateUserRequestMember,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}

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

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

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

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

return output


def marshal_CreateUserRequest(
request: CreateUserRequest,
defaults: ProfileDefaults,
) -> Dict[str, Any]:
output: Dict[str, Any] = {}
output.update(
resolve_one_of(
[
OneOfPossibility("email", request.email),
OneOfPossibility("member", request.member),
]
),
)

if request.organization_id is not None:
output["organization_id"] = (
request.organization_id or defaults.default_organization_id
Expand Down
58 changes: 43 additions & 15 deletions scaleway-async/scaleway_async/iam/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ class UserType(str, Enum, metaclass=StrEnumMeta):
UNKNOWN_TYPE = "unknown_type"
GUEST = "guest"
OWNER = "owner"
MEMBER = "member"

def __str__(self) -> str:
return str(self.value)
Expand All @@ -198,6 +199,29 @@ class RuleSpecs:
organization_id: Optional[str]


@dataclass
class CreateUserRequestMember:
email: str
"""
Email of the user to create.
"""

send_password_email: bool
"""
Whether or not to send an email containing the member's password.
"""

username: str
"""
The member's username.
"""

password: str
"""
The member's password.
"""


@dataclass
class JWT:
jti: str
Expand Down Expand Up @@ -647,11 +671,26 @@ class User:
Email of user.
"""

username: str
"""
User identifier unique to the Organization.
"""

organization_id: str
"""
ID of the Organization.
"""

created_at: Optional[datetime]
"""
Date user was created.
"""

updated_at: Optional[datetime]
"""
Date of last user update.
"""

deletable: bool
"""
Deletion status of user. Owners cannot be deleted.
Expand All @@ -667,11 +706,6 @@ class User:
Status of user invitation.
"""

created_at: Optional[datetime]
"""
Date user was created.
"""

mfa: bool
"""
Defines whether MFA is enabled.
Expand All @@ -687,11 +721,6 @@ class User:
Tags associated with the user.
"""

updated_at: Optional[datetime]
"""
Date of last user update.
"""

last_login_at: Optional[datetime]
"""
Date of the last login.
Expand Down Expand Up @@ -875,11 +904,6 @@ class CreateSSHKeyRequest:

@dataclass
class CreateUserRequest:
email: str
"""
Email of the user.
"""

organization_id: Optional[str]
"""
ID of the Organization.
Expand All @@ -890,6 +914,10 @@ class CreateUserRequest:
Tags associated with the user.
"""

email: Optional[str]

member: Optional[CreateUserRequestMember]


@dataclass
class DeleteAPIKeyRequest:
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 @@ -17,6 +17,7 @@
from .types import UserStatus
from .types import UserType
from .types import RuleSpecs
from .types import CreateUserRequestMember
from .types import JWT
from .types import APIKey
from .types import Application
Expand Down Expand Up @@ -107,6 +108,7 @@
"UserStatus",
"UserType",
"RuleSpecs",
"CreateUserRequestMember",
"JWT",
"APIKey",
"Application",
Expand Down
16 changes: 10 additions & 6 deletions scaleway/scaleway/iam/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
CreatePolicyRequest,
CreateSSHKeyRequest,
CreateUserRequest,
CreateUserRequestMember,
EncodedJWT,
Group,
JWT,
Expand Down Expand Up @@ -534,34 +535,37 @@ def delete_user(
def create_user(
self,
*,
email: str,
organization_id: Optional[str] = None,
email: Optional[str] = None,
tags: Optional[List[str]] = None,
member: Optional[CreateUserRequestMember] = None,
) -> User:
"""
Create a new user.
Create a new user. You must define the `organization_id` and the `email` in your request.
:param email: Email of the user.
:param organization_id: ID of the Organization.
:param email: Email of the user.
One-Of ('type'): at most one of 'email', 'member' could be set.
:param tags: Tags associated with the user.
:param member: A new IAM Member to create.
One-Of ('type'): at most one of 'email', 'member' could be set.
:return: :class:`User <User>`

Usage:
::

result = api.create_user(
email="example",
)
result = api.create_user()
"""

res = self._request(
"POST",
"/iam/v1alpha1/users",
body=marshal_CreateUserRequest(
CreateUserRequest(
email=email,
organization_id=organization_id,
tags=tags,
email=email,
member=member,
),
self.client,
),
Expand Down
Loading