From a6e1bf5ab2d1819bfaa2703fbe10f37c5962a8c7 Mon Sep 17 00:00:00 2001 From: Scaleway Bot Date: Mon, 4 Nov 2024 08:30:57 +0100 Subject: [PATCH] feat(k8s): expose ACL routes in SDK (#1546) Co-authored-by: Laure-di <62625835+Laure-di@users.noreply.github.com> --- packages/clients/src/api/k8s/v1/api.gen.ts | 88 +++++++++++++++ packages/clients/src/api/k8s/v1/index.gen.ts | 9 ++ .../clients/src/api/k8s/v1/marshalling.gen.ts | 96 +++++++++++++++++ packages/clients/src/api/k8s/v1/types.gen.ts | 101 ++++++++++++++++++ .../src/api/k8s/v1/validation-rules.gen.ts | 6 ++ 5 files changed, 300 insertions(+) diff --git a/packages/clients/src/api/k8s/v1/api.gen.ts b/packages/clients/src/api/k8s/v1/api.gen.ts index 33c27d610..a94528766 100644 --- a/packages/clients/src/api/k8s/v1/api.gen.ts +++ b/packages/clients/src/api/k8s/v1/api.gen.ts @@ -14,16 +14,20 @@ import { POOL_TRANSIENT_STATUSES, } from './content.gen' import { + marshalAddClusterACLRulesRequest, marshalCreateClusterRequest, marshalCreatePoolRequest, + marshalSetClusterACLRulesRequest, marshalSetClusterTypeRequest, marshalUpdateClusterRequest, marshalUpdatePoolRequest, marshalUpgradeClusterRequest, marshalUpgradePoolRequest, + unmarshalAddClusterACLRulesResponse, unmarshalCluster, unmarshalExternalNode, unmarshalExternalNodeAuth, + unmarshalListClusterACLRulesResponse, unmarshalListClusterAvailableTypesResponse, unmarshalListClusterAvailableVersionsResponse, unmarshalListClusterTypesResponse, @@ -34,14 +38,18 @@ import { unmarshalNode, unmarshalNodeMetadata, unmarshalPool, + unmarshalSetClusterACLRulesResponse, unmarshalVersion, } from './marshalling.gen' import type { + AddClusterACLRulesRequest, + AddClusterACLRulesResponse, AuthExternalNodeRequest, Cluster, CreateClusterRequest, CreateExternalNodeRequest, CreatePoolRequest, + DeleteACLRuleRequest, DeleteClusterRequest, DeleteNodeRequest, DeletePoolRequest, @@ -53,6 +61,8 @@ import type { GetNodeRequest, GetPoolRequest, GetVersionRequest, + ListClusterACLRulesRequest, + ListClusterACLRulesResponse, ListClusterAvailableTypesRequest, ListClusterAvailableTypesResponse, ListClusterAvailableVersionsRequest, @@ -74,6 +84,8 @@ import type { RebootNodeRequest, ReplaceNodeRequest, ResetClusterAdminTokenRequest, + SetClusterACLRulesRequest, + SetClusterACLRulesResponse, SetClusterTypeRequest, UpdateClusterRequest, UpdatePoolRequest, @@ -351,6 +363,82 @@ export class API extends ParentAPI { unmarshalCluster, ) + protected pageOfListClusterACLRules = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/clusters/${validatePathParam('clusterId', request.clusterId)}/acls`, + urlParams: urlParams( + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListClusterACLRulesResponse, + ) + + /** + * List ACLs. List ACLs for a specific cluster. + * + * @param request - The request {@link ListClusterACLRulesRequest} + * @returns A Promise of ListClusterACLRulesResponse + */ + listClusterACLRules = (request: Readonly) => + enrichForPagination('rules', this.pageOfListClusterACLRules, request) + + /** + * Add new ACLs. Add new ACL rules for a specific cluster. + * + * @param request - The request {@link AddClusterACLRulesRequest} + * @returns A Promise of AddClusterACLRulesResponse + */ + addClusterACLRules = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalAddClusterACLRulesRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/clusters/${validatePathParam('clusterId', request.clusterId)}/acls`, + }, + unmarshalAddClusterACLRulesResponse, + ) + + /** + * Set new ACLs. Set new ACL rules for a specific cluster. + * + * @param request - The request {@link SetClusterACLRulesRequest} + * @returns A Promise of SetClusterACLRulesResponse + */ + setClusterACLRules = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalSetClusterACLRulesRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/clusters/${validatePathParam('clusterId', request.clusterId)}/acls`, + }, + unmarshalSetClusterACLRulesResponse, + ) + + /** + * Delete an existing ACL. + * + * @param request - The request {@link DeleteACLRuleRequest} + */ + deleteACLRule = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/k8s/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/acls/${validatePathParam('aclId', request.aclId)}`, + }) + protected pageOfListPools = (request: Readonly) => this.client.fetch( { diff --git a/packages/clients/src/api/k8s/v1/index.gen.ts b/packages/clients/src/api/k8s/v1/index.gen.ts index ec1458359..3bd20f928 100644 --- a/packages/clients/src/api/k8s/v1/index.gen.ts +++ b/packages/clients/src/api/k8s/v1/index.gen.ts @@ -3,6 +3,10 @@ export { API } from './api.gen' export * from './content.gen' export type { + ACLRule, + ACLRuleRequest, + AddClusterACLRulesRequest, + AddClusterACLRulesResponse, AuthExternalNodeRequest, AutoscalerEstimator, AutoscalerExpander, @@ -24,6 +28,7 @@ export type { CreateExternalNodeRequest, CreatePoolRequest, CreatePoolRequestUpgradePolicy, + DeleteACLRuleRequest, DeleteClusterRequest, DeleteNodeRequest, DeletePoolRequest, @@ -36,6 +41,8 @@ export type { GetNodeRequest, GetPoolRequest, GetVersionRequest, + ListClusterACLRulesRequest, + ListClusterACLRulesResponse, ListClusterAvailableTypesRequest, ListClusterAvailableTypesResponse, ListClusterAvailableVersionsRequest, @@ -68,6 +75,8 @@ export type { ReplaceNodeRequest, ResetClusterAdminTokenRequest, Runtime, + SetClusterACLRulesRequest, + SetClusterACLRulesResponse, SetClusterTypeRequest, UpdateClusterRequest, UpdateClusterRequestAutoUpgrade, diff --git a/packages/clients/src/api/k8s/v1/marshalling.gen.ts b/packages/clients/src/api/k8s/v1/marshalling.gen.ts index 3d72ef141..d0bb64f8e 100644 --- a/packages/clients/src/api/k8s/v1/marshalling.gen.ts +++ b/packages/clients/src/api/k8s/v1/marshalling.gen.ts @@ -9,6 +9,10 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + ACLRule, + ACLRuleRequest, + AddClusterACLRulesRequest, + AddClusterACLRulesResponse, Cluster, ClusterAutoUpgrade, ClusterAutoscalerConfig, @@ -25,6 +29,7 @@ import type { ExternalNode, ExternalNodeAuth, ExternalNodeCoreV1Taint, + ListClusterACLRulesResponse, ListClusterAvailableTypesResponse, ListClusterAvailableVersionsResponse, ListClusterTypesResponse, @@ -38,6 +43,8 @@ import type { NodeMetadataCoreV1Taint, Pool, PoolUpgradePolicy, + SetClusterACLRulesRequest, + SetClusterACLRulesResponse, SetClusterTypeRequest, UpdateClusterRequest, UpdateClusterRequestAutoUpgrade, @@ -257,6 +264,35 @@ export const unmarshalNode = (data: unknown): Node => { } as Node } +const unmarshalACLRule = (data: unknown): ACLRule => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ACLRule' failed as data isn't a dictionary.`, + ) + } + + return { + description: data.description, + id: data.id, + ip: data.ip, + scalewayRanges: data.scaleway_ranges, + } as ACLRule +} + +export const unmarshalAddClusterACLRulesResponse = ( + data: unknown, +): AddClusterACLRulesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AddClusterACLRulesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + rules: unmarshalArrayOfObject(data.rules, unmarshalACLRule), + } as AddClusterACLRulesResponse +} + const unmarshalExternalNodeCoreV1Taint = ( data: unknown, ): ExternalNodeCoreV1Taint => { @@ -313,6 +349,21 @@ export const unmarshalExternalNodeAuth = (data: unknown): ExternalNodeAuth => { } as ExternalNodeAuth } +export const unmarshalListClusterACLRulesResponse = ( + data: unknown, +): ListClusterACLRulesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListClusterACLRulesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + rules: unmarshalArrayOfObject(data.rules, unmarshalACLRule), + totalCount: data.total_count, + } as ListClusterACLRulesResponse +} + const unmarshalClusterType = (data: unknown): ClusterType => { if (!isJSONObject(data)) { throw new TypeError( @@ -487,6 +538,41 @@ export const unmarshalNodeMetadata = (data: unknown): NodeMetadata => { } as NodeMetadata } +export const unmarshalSetClusterACLRulesResponse = ( + data: unknown, +): SetClusterACLRulesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SetClusterACLRulesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + rules: unmarshalArrayOfObject(data.rules, unmarshalACLRule), + } as SetClusterACLRulesResponse +} + +const marshalACLRuleRequest = ( + request: ACLRuleRequest, + defaults: DefaultValues, +): Record => ({ + description: request.description, + ...resolveOneOf([ + { param: 'ip', value: request.ip }, + { param: 'scaleway_ranges', value: request.scalewayRanges }, + ]), +}) + +export const marshalAddClusterACLRulesRequest = ( + request: AddClusterACLRulesRequest, + defaults: DefaultValues, +): Record => ({ + acls: + request.acls !== undefined + ? request.acls.map(elt => marshalACLRuleRequest(elt, defaults)) + : undefined, +}) + const marshalMaintenanceWindow = ( request: MaintenanceWindow, defaults: DefaultValues, @@ -657,6 +743,16 @@ export const marshalCreatePoolRequest = ( zone: request.zone ?? defaults.defaultZone, }) +export const marshalSetClusterACLRulesRequest = ( + request: SetClusterACLRulesRequest, + defaults: DefaultValues, +): Record => ({ + acls: + request.acls !== undefined + ? request.acls.map(elt => marshalACLRuleRequest(elt, defaults)) + : undefined, +}) + export const marshalSetClusterTypeRequest = ( request: SetClusterTypeRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/k8s/v1/types.gen.ts b/packages/clients/src/api/k8s/v1/types.gen.ts index 752a428c5..393f4f8f8 100644 --- a/packages/clients/src/api/k8s/v1/types.gen.ts +++ b/packages/clients/src/api/k8s/v1/types.gen.ts @@ -284,6 +284,42 @@ export interface Pool { region: Region } +export interface ACLRuleRequest { + /** + * IP subnet to allow. + * + * One-of ('allowed'): at most one of 'ip', 'scalewayRanges' could be set. + */ + ip?: string + /** + * Only one rule with this field set to true can be added. + * + * One-of ('allowed'): at most one of 'ip', 'scalewayRanges' could be set. + */ + scalewayRanges?: boolean + /** Description of the ACL. */ + description: string +} + +export interface ACLRule { + /** ID of the ACL rule. */ + id: string + /** + * IP subnet to allow. + * + * One-of ('allowed'): at most one of 'ip', 'scalewayRanges' could be set. + */ + ip?: string + /** + * Only one rule with this field set to true can be added. + * + * One-of ('allowed'): at most one of 'ip', 'scalewayRanges' could be set. + */ + scalewayRanges?: boolean + /** Description of the ACL. */ + description: string +} + export interface CreateClusterRequestAutoUpgrade { /** Defines whether auto upgrade is enabled for the cluster. */ enable: boolean @@ -691,6 +727,23 @@ export interface UpdatePoolRequestUpgradePolicy { maxSurge?: number } +export type AddClusterACLRulesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the cluster whose ACLs will be added. */ + clusterId: string + /** ACLs to add. */ + acls?: ACLRuleRequest[] +} + +export interface AddClusterACLRulesResponse { + /** ACLs that were added. */ + rules: ACLRule[] +} + export type AuthExternalNodeRequest = { /** * Region to target. If none is passed will use default region from the @@ -851,6 +904,16 @@ export type CreatePoolRequest = { publicIpDisabled: boolean } +export type DeleteACLRuleRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the ACL rule to delete. */ + aclId: string +} + export type DeleteClusterRequest = { /** * Region to target. If none is passed will use default region from the @@ -975,6 +1038,27 @@ export type GetVersionRequest = { versionName: string } +export type ListClusterACLRulesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the cluster whose ACLs will be listed. */ + clusterId: string + /** Page number for the returned ACLs. */ + page?: number + /** Maximum number of ACLs per page. */ + pageSize?: number +} + +export interface ListClusterACLRulesResponse { + /** Total number of ACLs that exist for the cluster. */ + totalCount: number + /** Paginated returned ACLs. */ + rules: ACLRule[] +} + export type ListClusterAvailableTypesRequest = { /** * Region to target. If none is passed will use default region from the @@ -1200,6 +1284,23 @@ export type ResetClusterAdminTokenRequest = { clusterId: string } +export type SetClusterACLRulesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** ID of the cluster whose ACLs will be set. */ + clusterId: string + /** ACLs to set. */ + acls?: ACLRuleRequest[] +} + +export interface SetClusterACLRulesResponse { + /** ACLs that were set. */ + rules: ACLRule[] +} + export type SetClusterTypeRequest = { /** * Region to target. If none is passed will use default region from the diff --git a/packages/clients/src/api/k8s/v1/validation-rules.gen.ts b/packages/clients/src/api/k8s/v1/validation-rules.gen.ts index 4d3510f9e..7f50c647b 100644 --- a/packages/clients/src/api/k8s/v1/validation-rules.gen.ts +++ b/packages/clients/src/api/k8s/v1/validation-rules.gen.ts @@ -1,6 +1,12 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. +export const ACLRuleRequest = { + description: { + maxLength: 2000, + }, +} + export const CreateClusterRequest = { description: { maxLength: 4096,