Skip to content

Commit

Permalink
feat(iam): add organization security settings methods (#1640)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Dec 9, 2024
1 parent 62bf1f1 commit fba0e93
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
49 changes: 49 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
marshalUpdateAPIKeyRequest,
marshalUpdateApplicationRequest,
marshalUpdateGroupRequest,
marshalUpdateOrganizationSecuritySettingsRequest,
marshalUpdatePolicyRequest,
marshalUpdateSSHKeyRequest,
marshalUpdateUserPasswordRequest,
Expand All @@ -45,6 +46,7 @@ import {
unmarshalListSSHKeysResponse,
unmarshalListUsersResponse,
unmarshalLog,
unmarshalOrganizationSecuritySettings,
unmarshalPolicy,
unmarshalQuotum,
unmarshalSSHKey,
Expand Down Expand Up @@ -77,6 +79,7 @@ import type {
GetGroupRequest,
GetJWTRequest,
GetLogRequest,
GetOrganizationSecuritySettingsRequest,
GetPolicyRequest,
GetQuotumRequest,
GetSSHKeyRequest,
Expand Down Expand Up @@ -109,6 +112,7 @@ import type {
ListUsersResponse,
LockUserRequest,
Log,
OrganizationSecuritySettings,
Policy,
Quotum,
RemoveGroupMemberRequest,
Expand All @@ -120,6 +124,7 @@ import type {
UpdateAPIKeyRequest,
UpdateApplicationRequest,
UpdateGroupRequest,
UpdateOrganizationSecuritySettingsRequest,
UpdatePolicyRequest,
UpdateSSHKeyRequest,
UpdateUserPasswordRequest,
Expand Down Expand Up @@ -1276,4 +1281,48 @@ export class API extends ParentAPI {
},
unmarshalLog,
)

/**
* Get security settings of an Organization. Retrieve information about the
* security settings of an Organization, specified by the `organization_id`
* parameter.
*
* @param request - The request {@link GetOrganizationSecuritySettingsRequest}
* @returns A Promise of OrganizationSecuritySettings
*/
getOrganizationSecuritySettings = (
request: Readonly<GetOrganizationSecuritySettingsRequest> = {},
) =>
this.client.fetch<OrganizationSecuritySettings>(
{
method: 'GET',
path: `/iam/v1alpha1/organizations/${validatePathParam('organizationId', request.organizationId ?? this.client.settings.defaultOrganizationId)}/security-settings`,
},
unmarshalOrganizationSecuritySettings,
)

/**
* Update the security settings of an Organization.
*
* @param request - The request
* {@link UpdateOrganizationSecuritySettingsRequest}
* @returns A Promise of OrganizationSecuritySettings
*/
updateOrganizationSecuritySettings = (
request: Readonly<UpdateOrganizationSecuritySettingsRequest> = {},
) =>
this.client.fetch<OrganizationSecuritySettings>(
{
body: JSON.stringify(
marshalUpdateOrganizationSecuritySettingsRequest(
request,
this.client.settings,
),
),
headers: jsonContentHeaders,
method: 'PATCH',
path: `/iam/v1alpha1/organizations/${validatePathParam('organizationId', request.organizationId ?? this.client.settings.defaultOrganizationId)}/security-settings`,
},
unmarshalOrganizationSecuritySettings,
)
}
3 changes: 3 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type {
GetGroupRequest,
GetJWTRequest,
GetLogRequest,
GetOrganizationSecuritySettingsRequest,
GetPolicyRequest,
GetQuotumRequest,
GetSSHKeyRequest,
Expand Down Expand Up @@ -75,6 +76,7 @@ export type {
Log,
LogAction,
LogResourceType,
OrganizationSecuritySettings,
PermissionSet,
PermissionSetScopeType,
Policy,
Expand All @@ -90,6 +92,7 @@ export type {
UpdateAPIKeyRequest,
UpdateApplicationRequest,
UpdateGroupRequest,
UpdateOrganizationSecuritySettingsRequest,
UpdatePolicyRequest,
UpdateSSHKeyRequest,
UpdateUserPasswordRequest,
Expand Down
27 changes: 27 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type {
ListSSHKeysResponse,
ListUsersResponse,
Log,
OrganizationSecuritySettings,
PermissionSet,
Policy,
Quotum,
Expand All @@ -51,6 +52,7 @@ import type {
UpdateAPIKeyRequest,
UpdateApplicationRequest,
UpdateGroupRequest,
UpdateOrganizationSecuritySettingsRequest,
UpdatePolicyRequest,
UpdateSSHKeyRequest,
UpdateUserPasswordRequest,
Expand Down Expand Up @@ -503,6 +505,22 @@ export const unmarshalListUsersResponse = (
} as ListUsersResponse
}

export const unmarshalOrganizationSecuritySettings = (
data: unknown,
): OrganizationSecuritySettings => {
if (!isJSONObject(data)) {
throw new TypeError(
`Unmarshalling the type 'OrganizationSecuritySettings' failed as data isn't a dictionary.`,
)
}

return {
enforcePasswordRenewal: data.enforce_password_renewal,
gracePeriodDuration: data.grace_period_duration,
loginAttemptsBeforeLocked: data.login_attempts_before_locked,
} as OrganizationSecuritySettings
}

export const unmarshalSetRulesResponse = (data: unknown): SetRulesResponse => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -696,6 +714,15 @@ export const marshalUpdateGroupRequest = (
tags: request.tags,
})

export const marshalUpdateOrganizationSecuritySettingsRequest = (
request: UpdateOrganizationSecuritySettingsRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
enforce_password_renewal: request.enforcePasswordRenewal,
grace_period_duration: request.gracePeriodDuration,
login_attempts_before_locked: request.loginAttemptsBeforeLocked,
})

export const marshalUpdatePolicyRequest = (
request: UpdatePolicyRequest,
defaults: DefaultValues,
Expand Down
25 changes: 25 additions & 0 deletions packages/clients/src/api/iam/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,11 @@ export type GetLogRequest = {
logId: string
}

export type GetOrganizationSecuritySettingsRequest = {
/** ID of the Organization. */
organizationId?: string
}

export type GetPolicyRequest = {
/** Id of policy to search. */
policyId: string
Expand Down Expand Up @@ -988,6 +993,15 @@ export type LockUserRequest = {
userId: string
}

export interface OrganizationSecuritySettings {
/** Defines whether password renewal is enforced during first login. */
enforcePasswordRenewal: boolean
/** Duration of the grace period to renew password or enable MFA. */
gracePeriodDuration?: string
/** Number of login attempts before the account is locked. */
loginAttemptsBeforeLocked: number
}

export type RemoveGroupMemberRequest = {
/** ID of the group. */
groupId: string
Expand Down Expand Up @@ -1062,6 +1076,17 @@ export type UpdateGroupRequest = {
tags?: string[]
}

export type UpdateOrganizationSecuritySettingsRequest = {
/** ID of the Organization. */
organizationId?: string
/** Defines whether password renewal is enforced during first login. */
enforcePasswordRenewal?: boolean
/** Duration of the grace period to renew password or enable MFA. */
gracePeriodDuration?: string
/** Number of login attempts before the account is locked. */
loginAttemptsBeforeLocked?: number
}

export type UpdatePolicyRequest = {
/** Id of policy to update. */
policyId: string
Expand Down

0 comments on commit fba0e93

Please sign in to comment.