diff --git a/scaleway-async/scaleway_async/iam/v1alpha1/__init__.py b/scaleway-async/scaleway_async/iam/v1alpha1/__init__.py index a50d008a6..96bb733b5 100644 --- a/scaleway-async/scaleway_async/iam/v1alpha1/__init__.py +++ b/scaleway-async/scaleway_async/iam/v1alpha1/__init__.py @@ -54,6 +54,7 @@ from .types import GetGroupRequest from .types import GetJWTRequest from .types import GetLogRequest +from .types import GetOrganizationSecuritySettingsRequest from .types import GetPolicyRequest from .types import GetQuotumRequest from .types import GetSSHKeyRequest @@ -83,6 +84,7 @@ from .types import ListUsersRequest from .types import ListUsersResponse from .types import LockUserRequest +from .types import OrganizationSecuritySettings from .types import RemoveGroupMemberRequest from .types import SetGroupMembersRequest from .types import SetRulesRequest @@ -91,6 +93,7 @@ from .types import UpdateAPIKeyRequest from .types import UpdateApplicationRequest from .types import UpdateGroupRequest +from .types import UpdateOrganizationSecuritySettingsRequest from .types import UpdatePolicyRequest from .types import UpdateSSHKeyRequest from .types import UpdateUserPasswordRequest @@ -152,6 +155,7 @@ "GetGroupRequest", "GetJWTRequest", "GetLogRequest", + "GetOrganizationSecuritySettingsRequest", "GetPolicyRequest", "GetQuotumRequest", "GetSSHKeyRequest", @@ -181,6 +185,7 @@ "ListUsersRequest", "ListUsersResponse", "LockUserRequest", + "OrganizationSecuritySettings", "RemoveGroupMemberRequest", "SetGroupMembersRequest", "SetRulesRequest", @@ -189,6 +194,7 @@ "UpdateAPIKeyRequest", "UpdateApplicationRequest", "UpdateGroupRequest", + "UpdateOrganizationSecuritySettingsRequest", "UpdatePolicyRequest", "UpdateSSHKeyRequest", "UpdateUserPasswordRequest", diff --git a/scaleway-async/scaleway_async/iam/v1alpha1/api.py b/scaleway-async/scaleway_async/iam/v1alpha1/api.py index 5c1f94b3c..cd526513d 100644 --- a/scaleway-async/scaleway_async/iam/v1alpha1/api.py +++ b/scaleway-async/scaleway_async/iam/v1alpha1/api.py @@ -54,6 +54,7 @@ ListSSHKeysResponse, ListUsersResponse, Log, + OrganizationSecuritySettings, PermissionSet, Policy, Quotum, @@ -67,6 +68,7 @@ UpdateAPIKeyRequest, UpdateApplicationRequest, UpdateGroupRequest, + UpdateOrganizationSecuritySettingsRequest, UpdatePolicyRequest, UpdateSSHKeyRequest, UpdateUserPasswordRequest, @@ -96,6 +98,7 @@ unmarshal_ListRulesResponse, unmarshal_ListSSHKeysResponse, unmarshal_ListUsersResponse, + unmarshal_OrganizationSecuritySettings, unmarshal_SetRulesResponse, marshal_AddGroupMemberRequest, marshal_AddGroupMembersRequest, @@ -112,6 +115,7 @@ marshal_UpdateAPIKeyRequest, marshal_UpdateApplicationRequest, marshal_UpdateGroupRequest, + marshal_UpdateOrganizationSecuritySettingsRequest, marshal_UpdatePolicyRequest, marshal_UpdateSSHKeyRequest, marshal_UpdateUserPasswordRequest, @@ -2563,3 +2567,75 @@ async def get_log( self._throw_on_error(res) return unmarshal_Log(res.json()) + + async def get_organization_security_settings( + self, + *, + organization_id: Optional[str] = None, + ) -> OrganizationSecuritySettings: + """ + Get security settings of an Organization. + Retrieve information about the security settings of an Organization, specified by the `organization_id` parameter. + :param organization_id: ID of the Organization. + :return: :class:`OrganizationSecuritySettings ` + + Usage: + :: + + result = await api.get_organization_security_settings() + """ + + param_organization_id = validate_path_param( + "organization_id", organization_id or self.client.default_organization_id + ) + + res = self._request( + "GET", + f"/iam/v1alpha1/organizations/{param_organization_id}/security-settings", + ) + + self._throw_on_error(res) + return unmarshal_OrganizationSecuritySettings(res.json()) + + async def update_organization_security_settings( + self, + *, + organization_id: Optional[str] = None, + enforce_password_renewal: Optional[bool] = None, + grace_period_duration: Optional[str] = None, + login_attempts_before_locked: Optional[int] = None, + ) -> OrganizationSecuritySettings: + """ + Update the security settings of an Organization. + :param organization_id: ID of the Organization. + :param enforce_password_renewal: Defines whether password renewal is enforced during first login. + :param grace_period_duration: Duration of the grace period to renew password or enable MFA. + :param login_attempts_before_locked: Number of login attempts before the account is locked. + :return: :class:`OrganizationSecuritySettings ` + + Usage: + :: + + result = await api.update_organization_security_settings() + """ + + param_organization_id = validate_path_param( + "organization_id", organization_id or self.client.default_organization_id + ) + + res = self._request( + "PATCH", + f"/iam/v1alpha1/organizations/{param_organization_id}/security-settings", + body=marshal_UpdateOrganizationSecuritySettingsRequest( + UpdateOrganizationSecuritySettingsRequest( + organization_id=organization_id, + enforce_password_renewal=enforce_password_renewal, + grace_period_duration=grace_period_duration, + login_attempts_before_locked=login_attempts_before_locked, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_OrganizationSecuritySettings(res.json()) diff --git a/scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py b/scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py index bd5301e54..b1e436613 100644 --- a/scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py +++ b/scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py @@ -35,6 +35,7 @@ ListRulesResponse, ListSSHKeysResponse, ListUsersResponse, + OrganizationSecuritySettings, SetRulesResponse, AddGroupMemberRequest, AddGroupMembersRequest, @@ -53,6 +54,7 @@ UpdateAPIKeyRequest, UpdateApplicationRequest, UpdateGroupRequest, + UpdateOrganizationSecuritySettingsRequest, UpdatePolicyRequest, UpdateSSHKeyRequest, UpdateUserPasswordRequest, @@ -993,6 +995,31 @@ def unmarshal_ListUsersResponse(data: Any) -> ListUsersResponse: return ListUsersResponse(**args) +def unmarshal_OrganizationSecuritySettings(data: Any) -> OrganizationSecuritySettings: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'OrganizationSecuritySettings' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("enforce_password_renewal", None) + if field is not None: + args["enforce_password_renewal"] = field + + field = data.get("login_attempts_before_locked", None) + if field is not None: + args["login_attempts_before_locked"] = field + + field = data.get("grace_period_duration", None) + if field is not None: + args["grace_period_duration"] = field + else: + args["grace_period_duration"] = None + + return OrganizationSecuritySettings(**args) + + def unmarshal_SetRulesResponse(data: Any) -> SetRulesResponse: if not isinstance(data, dict): raise TypeError( @@ -1357,6 +1384,24 @@ def marshal_UpdateGroupRequest( return output +def marshal_UpdateOrganizationSecuritySettingsRequest( + request: UpdateOrganizationSecuritySettingsRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.enforce_password_renewal is not None: + output["enforce_password_renewal"] = request.enforce_password_renewal + + if request.grace_period_duration is not None: + output["grace_period_duration"] = request.grace_period_duration + + if request.login_attempts_before_locked is not None: + output["login_attempts_before_locked"] = request.login_attempts_before_locked + + return output + + def marshal_UpdatePolicyRequest( request: UpdatePolicyRequest, defaults: ProfileDefaults, diff --git a/scaleway-async/scaleway_async/iam/v1alpha1/types.py b/scaleway-async/scaleway_async/iam/v1alpha1/types.py index bc5bec114..930ec6342 100644 --- a/scaleway-async/scaleway_async/iam/v1alpha1/types.py +++ b/scaleway-async/scaleway_async/iam/v1alpha1/types.py @@ -1112,6 +1112,14 @@ class GetLogRequest: """ +@dataclass +class GetOrganizationSecuritySettingsRequest: + organization_id: Optional[str] + """ + ID of the Organization. + """ + + @dataclass class GetPolicyRequest: policy_id: str @@ -1747,6 +1755,24 @@ class LockUserRequest: """ +@dataclass +class OrganizationSecuritySettings: + enforce_password_renewal: bool + """ + Defines whether password renewal is enforced during first login. + """ + + login_attempts_before_locked: int + """ + Number of login attempts before the account is locked. + """ + + grace_period_duration: Optional[str] + """ + Duration of the grace period to renew password or enable MFA. + """ + + @dataclass class RemoveGroupMemberRequest: group_id: str @@ -1861,6 +1887,29 @@ class UpdateGroupRequest: """ +@dataclass +class UpdateOrganizationSecuritySettingsRequest: + organization_id: Optional[str] + """ + ID of the Organization. + """ + + enforce_password_renewal: Optional[bool] + """ + Defines whether password renewal is enforced during first login. + """ + + grace_period_duration: Optional[str] + """ + Duration of the grace period to renew password or enable MFA. + """ + + login_attempts_before_locked: Optional[int] + """ + Number of login attempts before the account is locked. + """ + + @dataclass class UpdatePolicyRequest: policy_id: str diff --git a/scaleway/scaleway/iam/v1alpha1/__init__.py b/scaleway/scaleway/iam/v1alpha1/__init__.py index a50d008a6..96bb733b5 100644 --- a/scaleway/scaleway/iam/v1alpha1/__init__.py +++ b/scaleway/scaleway/iam/v1alpha1/__init__.py @@ -54,6 +54,7 @@ from .types import GetGroupRequest from .types import GetJWTRequest from .types import GetLogRequest +from .types import GetOrganizationSecuritySettingsRequest from .types import GetPolicyRequest from .types import GetQuotumRequest from .types import GetSSHKeyRequest @@ -83,6 +84,7 @@ from .types import ListUsersRequest from .types import ListUsersResponse from .types import LockUserRequest +from .types import OrganizationSecuritySettings from .types import RemoveGroupMemberRequest from .types import SetGroupMembersRequest from .types import SetRulesRequest @@ -91,6 +93,7 @@ from .types import UpdateAPIKeyRequest from .types import UpdateApplicationRequest from .types import UpdateGroupRequest +from .types import UpdateOrganizationSecuritySettingsRequest from .types import UpdatePolicyRequest from .types import UpdateSSHKeyRequest from .types import UpdateUserPasswordRequest @@ -152,6 +155,7 @@ "GetGroupRequest", "GetJWTRequest", "GetLogRequest", + "GetOrganizationSecuritySettingsRequest", "GetPolicyRequest", "GetQuotumRequest", "GetSSHKeyRequest", @@ -181,6 +185,7 @@ "ListUsersRequest", "ListUsersResponse", "LockUserRequest", + "OrganizationSecuritySettings", "RemoveGroupMemberRequest", "SetGroupMembersRequest", "SetRulesRequest", @@ -189,6 +194,7 @@ "UpdateAPIKeyRequest", "UpdateApplicationRequest", "UpdateGroupRequest", + "UpdateOrganizationSecuritySettingsRequest", "UpdatePolicyRequest", "UpdateSSHKeyRequest", "UpdateUserPasswordRequest", diff --git a/scaleway/scaleway/iam/v1alpha1/api.py b/scaleway/scaleway/iam/v1alpha1/api.py index f60a9ae04..e30779c3d 100644 --- a/scaleway/scaleway/iam/v1alpha1/api.py +++ b/scaleway/scaleway/iam/v1alpha1/api.py @@ -54,6 +54,7 @@ ListSSHKeysResponse, ListUsersResponse, Log, + OrganizationSecuritySettings, PermissionSet, Policy, Quotum, @@ -67,6 +68,7 @@ UpdateAPIKeyRequest, UpdateApplicationRequest, UpdateGroupRequest, + UpdateOrganizationSecuritySettingsRequest, UpdatePolicyRequest, UpdateSSHKeyRequest, UpdateUserPasswordRequest, @@ -96,6 +98,7 @@ unmarshal_ListRulesResponse, unmarshal_ListSSHKeysResponse, unmarshal_ListUsersResponse, + unmarshal_OrganizationSecuritySettings, unmarshal_SetRulesResponse, marshal_AddGroupMemberRequest, marshal_AddGroupMembersRequest, @@ -112,6 +115,7 @@ marshal_UpdateAPIKeyRequest, marshal_UpdateApplicationRequest, marshal_UpdateGroupRequest, + marshal_UpdateOrganizationSecuritySettingsRequest, marshal_UpdatePolicyRequest, marshal_UpdateSSHKeyRequest, marshal_UpdateUserPasswordRequest, @@ -2563,3 +2567,75 @@ def get_log( self._throw_on_error(res) return unmarshal_Log(res.json()) + + def get_organization_security_settings( + self, + *, + organization_id: Optional[str] = None, + ) -> OrganizationSecuritySettings: + """ + Get security settings of an Organization. + Retrieve information about the security settings of an Organization, specified by the `organization_id` parameter. + :param organization_id: ID of the Organization. + :return: :class:`OrganizationSecuritySettings ` + + Usage: + :: + + result = api.get_organization_security_settings() + """ + + param_organization_id = validate_path_param( + "organization_id", organization_id or self.client.default_organization_id + ) + + res = self._request( + "GET", + f"/iam/v1alpha1/organizations/{param_organization_id}/security-settings", + ) + + self._throw_on_error(res) + return unmarshal_OrganizationSecuritySettings(res.json()) + + def update_organization_security_settings( + self, + *, + organization_id: Optional[str] = None, + enforce_password_renewal: Optional[bool] = None, + grace_period_duration: Optional[str] = None, + login_attempts_before_locked: Optional[int] = None, + ) -> OrganizationSecuritySettings: + """ + Update the security settings of an Organization. + :param organization_id: ID of the Organization. + :param enforce_password_renewal: Defines whether password renewal is enforced during first login. + :param grace_period_duration: Duration of the grace period to renew password or enable MFA. + :param login_attempts_before_locked: Number of login attempts before the account is locked. + :return: :class:`OrganizationSecuritySettings ` + + Usage: + :: + + result = api.update_organization_security_settings() + """ + + param_organization_id = validate_path_param( + "organization_id", organization_id or self.client.default_organization_id + ) + + res = self._request( + "PATCH", + f"/iam/v1alpha1/organizations/{param_organization_id}/security-settings", + body=marshal_UpdateOrganizationSecuritySettingsRequest( + UpdateOrganizationSecuritySettingsRequest( + organization_id=organization_id, + enforce_password_renewal=enforce_password_renewal, + grace_period_duration=grace_period_duration, + login_attempts_before_locked=login_attempts_before_locked, + ), + self.client, + ), + ) + + self._throw_on_error(res) + return unmarshal_OrganizationSecuritySettings(res.json()) diff --git a/scaleway/scaleway/iam/v1alpha1/marshalling.py b/scaleway/scaleway/iam/v1alpha1/marshalling.py index bd5301e54..b1e436613 100644 --- a/scaleway/scaleway/iam/v1alpha1/marshalling.py +++ b/scaleway/scaleway/iam/v1alpha1/marshalling.py @@ -35,6 +35,7 @@ ListRulesResponse, ListSSHKeysResponse, ListUsersResponse, + OrganizationSecuritySettings, SetRulesResponse, AddGroupMemberRequest, AddGroupMembersRequest, @@ -53,6 +54,7 @@ UpdateAPIKeyRequest, UpdateApplicationRequest, UpdateGroupRequest, + UpdateOrganizationSecuritySettingsRequest, UpdatePolicyRequest, UpdateSSHKeyRequest, UpdateUserPasswordRequest, @@ -993,6 +995,31 @@ def unmarshal_ListUsersResponse(data: Any) -> ListUsersResponse: return ListUsersResponse(**args) +def unmarshal_OrganizationSecuritySettings(data: Any) -> OrganizationSecuritySettings: + if not isinstance(data, dict): + raise TypeError( + "Unmarshalling the type 'OrganizationSecuritySettings' failed as data isn't a dictionary." + ) + + args: Dict[str, Any] = {} + + field = data.get("enforce_password_renewal", None) + if field is not None: + args["enforce_password_renewal"] = field + + field = data.get("login_attempts_before_locked", None) + if field is not None: + args["login_attempts_before_locked"] = field + + field = data.get("grace_period_duration", None) + if field is not None: + args["grace_period_duration"] = field + else: + args["grace_period_duration"] = None + + return OrganizationSecuritySettings(**args) + + def unmarshal_SetRulesResponse(data: Any) -> SetRulesResponse: if not isinstance(data, dict): raise TypeError( @@ -1357,6 +1384,24 @@ def marshal_UpdateGroupRequest( return output +def marshal_UpdateOrganizationSecuritySettingsRequest( + request: UpdateOrganizationSecuritySettingsRequest, + defaults: ProfileDefaults, +) -> Dict[str, Any]: + output: Dict[str, Any] = {} + + if request.enforce_password_renewal is not None: + output["enforce_password_renewal"] = request.enforce_password_renewal + + if request.grace_period_duration is not None: + output["grace_period_duration"] = request.grace_period_duration + + if request.login_attempts_before_locked is not None: + output["login_attempts_before_locked"] = request.login_attempts_before_locked + + return output + + def marshal_UpdatePolicyRequest( request: UpdatePolicyRequest, defaults: ProfileDefaults, diff --git a/scaleway/scaleway/iam/v1alpha1/types.py b/scaleway/scaleway/iam/v1alpha1/types.py index bc5bec114..930ec6342 100644 --- a/scaleway/scaleway/iam/v1alpha1/types.py +++ b/scaleway/scaleway/iam/v1alpha1/types.py @@ -1112,6 +1112,14 @@ class GetLogRequest: """ +@dataclass +class GetOrganizationSecuritySettingsRequest: + organization_id: Optional[str] + """ + ID of the Organization. + """ + + @dataclass class GetPolicyRequest: policy_id: str @@ -1747,6 +1755,24 @@ class LockUserRequest: """ +@dataclass +class OrganizationSecuritySettings: + enforce_password_renewal: bool + """ + Defines whether password renewal is enforced during first login. + """ + + login_attempts_before_locked: int + """ + Number of login attempts before the account is locked. + """ + + grace_period_duration: Optional[str] + """ + Duration of the grace period to renew password or enable MFA. + """ + + @dataclass class RemoveGroupMemberRequest: group_id: str @@ -1861,6 +1887,29 @@ class UpdateGroupRequest: """ +@dataclass +class UpdateOrganizationSecuritySettingsRequest: + organization_id: Optional[str] + """ + ID of the Organization. + """ + + enforce_password_renewal: Optional[bool] + """ + Defines whether password renewal is enforced during first login. + """ + + grace_period_duration: Optional[str] + """ + Duration of the grace period to renew password or enable MFA. + """ + + login_attempts_before_locked: Optional[int] + """ + Number of login attempts before the account is locked. + """ + + @dataclass class UpdatePolicyRequest: policy_id: str