Skip to content

Commit 436dfeb

Browse files
authored
feat(iam): add organization security settings methods (#787)
1 parent 327ed2d commit 436dfeb

File tree

8 files changed

+352
-0
lines changed

8 files changed

+352
-0
lines changed

scaleway-async/scaleway_async/iam/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from .types import GetGroupRequest
5555
from .types import GetJWTRequest
5656
from .types import GetLogRequest
57+
from .types import GetOrganizationSecuritySettingsRequest
5758
from .types import GetPolicyRequest
5859
from .types import GetQuotumRequest
5960
from .types import GetSSHKeyRequest
@@ -83,6 +84,7 @@
8384
from .types import ListUsersRequest
8485
from .types import ListUsersResponse
8586
from .types import LockUserRequest
87+
from .types import OrganizationSecuritySettings
8688
from .types import RemoveGroupMemberRequest
8789
from .types import SetGroupMembersRequest
8890
from .types import SetRulesRequest
@@ -91,6 +93,7 @@
9193
from .types import UpdateAPIKeyRequest
9294
from .types import UpdateApplicationRequest
9395
from .types import UpdateGroupRequest
96+
from .types import UpdateOrganizationSecuritySettingsRequest
9497
from .types import UpdatePolicyRequest
9598
from .types import UpdateSSHKeyRequest
9699
from .types import UpdateUserPasswordRequest
@@ -152,6 +155,7 @@
152155
"GetGroupRequest",
153156
"GetJWTRequest",
154157
"GetLogRequest",
158+
"GetOrganizationSecuritySettingsRequest",
155159
"GetPolicyRequest",
156160
"GetQuotumRequest",
157161
"GetSSHKeyRequest",
@@ -181,6 +185,7 @@
181185
"ListUsersRequest",
182186
"ListUsersResponse",
183187
"LockUserRequest",
188+
"OrganizationSecuritySettings",
184189
"RemoveGroupMemberRequest",
185190
"SetGroupMembersRequest",
186191
"SetRulesRequest",
@@ -189,6 +194,7 @@
189194
"UpdateAPIKeyRequest",
190195
"UpdateApplicationRequest",
191196
"UpdateGroupRequest",
197+
"UpdateOrganizationSecuritySettingsRequest",
192198
"UpdatePolicyRequest",
193199
"UpdateSSHKeyRequest",
194200
"UpdateUserPasswordRequest",

scaleway-async/scaleway_async/iam/v1alpha1/api.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
ListSSHKeysResponse,
5555
ListUsersResponse,
5656
Log,
57+
OrganizationSecuritySettings,
5758
PermissionSet,
5859
Policy,
5960
Quotum,
@@ -67,6 +68,7 @@
6768
UpdateAPIKeyRequest,
6869
UpdateApplicationRequest,
6970
UpdateGroupRequest,
71+
UpdateOrganizationSecuritySettingsRequest,
7072
UpdatePolicyRequest,
7173
UpdateSSHKeyRequest,
7274
UpdateUserPasswordRequest,
@@ -96,6 +98,7 @@
9698
unmarshal_ListRulesResponse,
9799
unmarshal_ListSSHKeysResponse,
98100
unmarshal_ListUsersResponse,
101+
unmarshal_OrganizationSecuritySettings,
99102
unmarshal_SetRulesResponse,
100103
marshal_AddGroupMemberRequest,
101104
marshal_AddGroupMembersRequest,
@@ -112,6 +115,7 @@
112115
marshal_UpdateAPIKeyRequest,
113116
marshal_UpdateApplicationRequest,
114117
marshal_UpdateGroupRequest,
118+
marshal_UpdateOrganizationSecuritySettingsRequest,
115119
marshal_UpdatePolicyRequest,
116120
marshal_UpdateSSHKeyRequest,
117121
marshal_UpdateUserPasswordRequest,
@@ -2563,3 +2567,75 @@ async def get_log(
25632567

25642568
self._throw_on_error(res)
25652569
return unmarshal_Log(res.json())
2570+
2571+
async def get_organization_security_settings(
2572+
self,
2573+
*,
2574+
organization_id: Optional[str] = None,
2575+
) -> OrganizationSecuritySettings:
2576+
"""
2577+
Get security settings of an Organization.
2578+
Retrieve information about the security settings of an Organization, specified by the `organization_id` parameter.
2579+
:param organization_id: ID of the Organization.
2580+
:return: :class:`OrganizationSecuritySettings <OrganizationSecuritySettings>`
2581+
2582+
Usage:
2583+
::
2584+
2585+
result = await api.get_organization_security_settings()
2586+
"""
2587+
2588+
param_organization_id = validate_path_param(
2589+
"organization_id", organization_id or self.client.default_organization_id
2590+
)
2591+
2592+
res = self._request(
2593+
"GET",
2594+
f"/iam/v1alpha1/organizations/{param_organization_id}/security-settings",
2595+
)
2596+
2597+
self._throw_on_error(res)
2598+
return unmarshal_OrganizationSecuritySettings(res.json())
2599+
2600+
async def update_organization_security_settings(
2601+
self,
2602+
*,
2603+
organization_id: Optional[str] = None,
2604+
enforce_password_renewal: Optional[bool] = None,
2605+
grace_period_duration: Optional[str] = None,
2606+
login_attempts_before_locked: Optional[int] = None,
2607+
) -> OrganizationSecuritySettings:
2608+
"""
2609+
Update the security settings of an Organization.
2610+
:param organization_id: ID of the Organization.
2611+
:param enforce_password_renewal: Defines whether password renewal is enforced during first login.
2612+
:param grace_period_duration: Duration of the grace period to renew password or enable MFA.
2613+
:param login_attempts_before_locked: Number of login attempts before the account is locked.
2614+
:return: :class:`OrganizationSecuritySettings <OrganizationSecuritySettings>`
2615+
2616+
Usage:
2617+
::
2618+
2619+
result = await api.update_organization_security_settings()
2620+
"""
2621+
2622+
param_organization_id = validate_path_param(
2623+
"organization_id", organization_id or self.client.default_organization_id
2624+
)
2625+
2626+
res = self._request(
2627+
"PATCH",
2628+
f"/iam/v1alpha1/organizations/{param_organization_id}/security-settings",
2629+
body=marshal_UpdateOrganizationSecuritySettingsRequest(
2630+
UpdateOrganizationSecuritySettingsRequest(
2631+
organization_id=organization_id,
2632+
enforce_password_renewal=enforce_password_renewal,
2633+
grace_period_duration=grace_period_duration,
2634+
login_attempts_before_locked=login_attempts_before_locked,
2635+
),
2636+
self.client,
2637+
),
2638+
)
2639+
2640+
self._throw_on_error(res)
2641+
return unmarshal_OrganizationSecuritySettings(res.json())

scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
ListRulesResponse,
3636
ListSSHKeysResponse,
3737
ListUsersResponse,
38+
OrganizationSecuritySettings,
3839
SetRulesResponse,
3940
AddGroupMemberRequest,
4041
AddGroupMembersRequest,
@@ -53,6 +54,7 @@
5354
UpdateAPIKeyRequest,
5455
UpdateApplicationRequest,
5556
UpdateGroupRequest,
57+
UpdateOrganizationSecuritySettingsRequest,
5658
UpdatePolicyRequest,
5759
UpdateSSHKeyRequest,
5860
UpdateUserPasswordRequest,
@@ -993,6 +995,31 @@ def unmarshal_ListUsersResponse(data: Any) -> ListUsersResponse:
993995
return ListUsersResponse(**args)
994996

995997

998+
def unmarshal_OrganizationSecuritySettings(data: Any) -> OrganizationSecuritySettings:
999+
if not isinstance(data, dict):
1000+
raise TypeError(
1001+
"Unmarshalling the type 'OrganizationSecuritySettings' failed as data isn't a dictionary."
1002+
)
1003+
1004+
args: Dict[str, Any] = {}
1005+
1006+
field = data.get("enforce_password_renewal", None)
1007+
if field is not None:
1008+
args["enforce_password_renewal"] = field
1009+
1010+
field = data.get("login_attempts_before_locked", None)
1011+
if field is not None:
1012+
args["login_attempts_before_locked"] = field
1013+
1014+
field = data.get("grace_period_duration", None)
1015+
if field is not None:
1016+
args["grace_period_duration"] = field
1017+
else:
1018+
args["grace_period_duration"] = None
1019+
1020+
return OrganizationSecuritySettings(**args)
1021+
1022+
9961023
def unmarshal_SetRulesResponse(data: Any) -> SetRulesResponse:
9971024
if not isinstance(data, dict):
9981025
raise TypeError(
@@ -1357,6 +1384,24 @@ def marshal_UpdateGroupRequest(
13571384
return output
13581385

13591386

1387+
def marshal_UpdateOrganizationSecuritySettingsRequest(
1388+
request: UpdateOrganizationSecuritySettingsRequest,
1389+
defaults: ProfileDefaults,
1390+
) -> Dict[str, Any]:
1391+
output: Dict[str, Any] = {}
1392+
1393+
if request.enforce_password_renewal is not None:
1394+
output["enforce_password_renewal"] = request.enforce_password_renewal
1395+
1396+
if request.grace_period_duration is not None:
1397+
output["grace_period_duration"] = request.grace_period_duration
1398+
1399+
if request.login_attempts_before_locked is not None:
1400+
output["login_attempts_before_locked"] = request.login_attempts_before_locked
1401+
1402+
return output
1403+
1404+
13601405
def marshal_UpdatePolicyRequest(
13611406
request: UpdatePolicyRequest,
13621407
defaults: ProfileDefaults,

scaleway-async/scaleway_async/iam/v1alpha1/types.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,14 @@ class GetLogRequest:
11121112
"""
11131113

11141114

1115+
@dataclass
1116+
class GetOrganizationSecuritySettingsRequest:
1117+
organization_id: Optional[str]
1118+
"""
1119+
ID of the Organization.
1120+
"""
1121+
1122+
11151123
@dataclass
11161124
class GetPolicyRequest:
11171125
policy_id: str
@@ -1747,6 +1755,24 @@ class LockUserRequest:
17471755
"""
17481756

17491757

1758+
@dataclass
1759+
class OrganizationSecuritySettings:
1760+
enforce_password_renewal: bool
1761+
"""
1762+
Defines whether password renewal is enforced during first login.
1763+
"""
1764+
1765+
login_attempts_before_locked: int
1766+
"""
1767+
Number of login attempts before the account is locked.
1768+
"""
1769+
1770+
grace_period_duration: Optional[str]
1771+
"""
1772+
Duration of the grace period to renew password or enable MFA.
1773+
"""
1774+
1775+
17501776
@dataclass
17511777
class RemoveGroupMemberRequest:
17521778
group_id: str
@@ -1861,6 +1887,29 @@ class UpdateGroupRequest:
18611887
"""
18621888

18631889

1890+
@dataclass
1891+
class UpdateOrganizationSecuritySettingsRequest:
1892+
organization_id: Optional[str]
1893+
"""
1894+
ID of the Organization.
1895+
"""
1896+
1897+
enforce_password_renewal: Optional[bool]
1898+
"""
1899+
Defines whether password renewal is enforced during first login.
1900+
"""
1901+
1902+
grace_period_duration: Optional[str]
1903+
"""
1904+
Duration of the grace period to renew password or enable MFA.
1905+
"""
1906+
1907+
login_attempts_before_locked: Optional[int]
1908+
"""
1909+
Number of login attempts before the account is locked.
1910+
"""
1911+
1912+
18641913
@dataclass
18651914
class UpdatePolicyRequest:
18661915
policy_id: str

scaleway/scaleway/iam/v1alpha1/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
from .types import GetGroupRequest
5555
from .types import GetJWTRequest
5656
from .types import GetLogRequest
57+
from .types import GetOrganizationSecuritySettingsRequest
5758
from .types import GetPolicyRequest
5859
from .types import GetQuotumRequest
5960
from .types import GetSSHKeyRequest
@@ -83,6 +84,7 @@
8384
from .types import ListUsersRequest
8485
from .types import ListUsersResponse
8586
from .types import LockUserRequest
87+
from .types import OrganizationSecuritySettings
8688
from .types import RemoveGroupMemberRequest
8789
from .types import SetGroupMembersRequest
8890
from .types import SetRulesRequest
@@ -91,6 +93,7 @@
9193
from .types import UpdateAPIKeyRequest
9294
from .types import UpdateApplicationRequest
9395
from .types import UpdateGroupRequest
96+
from .types import UpdateOrganizationSecuritySettingsRequest
9497
from .types import UpdatePolicyRequest
9598
from .types import UpdateSSHKeyRequest
9699
from .types import UpdateUserPasswordRequest
@@ -152,6 +155,7 @@
152155
"GetGroupRequest",
153156
"GetJWTRequest",
154157
"GetLogRequest",
158+
"GetOrganizationSecuritySettingsRequest",
155159
"GetPolicyRequest",
156160
"GetQuotumRequest",
157161
"GetSSHKeyRequest",
@@ -181,6 +185,7 @@
181185
"ListUsersRequest",
182186
"ListUsersResponse",
183187
"LockUserRequest",
188+
"OrganizationSecuritySettings",
184189
"RemoveGroupMemberRequest",
185190
"SetGroupMembersRequest",
186191
"SetRulesRequest",
@@ -189,6 +194,7 @@
189194
"UpdateAPIKeyRequest",
190195
"UpdateApplicationRequest",
191196
"UpdateGroupRequest",
197+
"UpdateOrganizationSecuritySettingsRequest",
192198
"UpdatePolicyRequest",
193199
"UpdateSSHKeyRequest",
194200
"UpdateUserPasswordRequest",

0 commit comments

Comments
 (0)