From 9414f2fca8eeb24cffb9dad18abad636839258e5 Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Mon, 20 Nov 2023 09:53:30 +0100 Subject: [PATCH] feat(instance): replace update utils (image, snapshot, security group) by generated routes --- .../clients/src/api/instance/v1/api.gen.ts | 128 +++++++++++-- .../clients/src/api/instance/v1/api.utils.ts | 176 ------------------ .../clients/src/api/instance/v1/index.gen.ts | 9 + .../src/api/instance/v1/marshalling.gen.ts | 130 +++++++++++++ .../clients/src/api/instance/v1/types.gen.ts | 131 +++++++++++-- .../src/api/instance/v1/types.private.gen.ts | 2 +- .../src/api/instance/v1/types.utils.ts | 86 +-------- 7 files changed, 377 insertions(+), 285 deletions(-) diff --git a/packages/clients/src/api/instance/v1/api.gen.ts b/packages/clients/src/api/instance/v1/api.gen.ts index 59d97171e..ae69ec251 100644 --- a/packages/clients/src/api/instance/v1/api.gen.ts +++ b/packages/clients/src/api/instance/v1/api.gen.ts @@ -31,11 +31,15 @@ import { marshalSetSecurityGroupRulesRequest, marshalSetServerRequest, marshalSetSnapshotRequest, + marshalUpdateImageRequest, marshalUpdateIpRequest, marshalUpdatePlacementGroupRequest, marshalUpdatePlacementGroupServersRequest, marshalUpdatePrivateNICRequest, + marshalUpdateSecurityGroupRequest, + marshalUpdateSecurityGroupRuleRequest, marshalUpdateServerRequest, + marshalUpdateSnapshotRequest, marshalUpdateVolumeRequest, unmarshalAttachServerVolumeResponse, unmarshalCreateImageResponse, @@ -87,10 +91,14 @@ import { unmarshalSetSecurityGroupRulesResponse, unmarshalSetServerResponse, unmarshalSetSnapshotResponse, + unmarshalUpdateImageResponse, unmarshalUpdateIpResponse, unmarshalUpdatePlacementGroupResponse, unmarshalUpdatePlacementGroupServersResponse, + unmarshalUpdateSecurityGroupResponse, + unmarshalUpdateSecurityGroupRuleResponse, unmarshalUpdateServerResponse, + unmarshalUpdateSnapshotResponse, unmarshalUpdateVolumeResponse, } from './marshalling.gen' import type { @@ -196,6 +204,8 @@ import type { SetPlacementGroupServersResponse, SetSecurityGroupRulesRequest, SetSecurityGroupRulesResponse, + UpdateImageRequest, + UpdateImageResponse, UpdateIpRequest, UpdateIpResponse, UpdatePlacementGroupRequest, @@ -203,8 +213,14 @@ import type { UpdatePlacementGroupServersRequest, UpdatePlacementGroupServersResponse, UpdatePrivateNICRequest, + UpdateSecurityGroupRequest, + UpdateSecurityGroupResponse, + UpdateSecurityGroupRuleRequest, + UpdateSecurityGroupRuleResponse, UpdateServerRequest, UpdateServerResponse, + UpdateSnapshotRequest, + UpdateSnapshotResponse, UpdateVolumeRequest, UpdateVolumeResponse, } from './types.gen' @@ -534,12 +550,6 @@ export class API extends ParentAPI { )}/user_data/${validatePathParam('key', request.key)}`, }) - /** - * Attach a volume to a server. - * - * @param request - The request {@link AttachServerVolumeRequest} - * @returns A Promise of AttachServerVolumeResponse - */ attachServerVolume = (request: Readonly) => this.client.fetch( { @@ -559,12 +569,6 @@ export class API extends ParentAPI { unmarshalAttachServerVolumeResponse, ) - /** - * Detach a volume from a server. - * - * @param request - The request {@link DetachServerVolumeRequest} - * @returns A Promise of DetachServerVolumeResponse - */ detachServerVolume = (request: Readonly) => this.client.fetch( { @@ -672,6 +676,28 @@ export class API extends ParentAPI { unmarshalSetImageResponse, ) + /** + * Update image. Update the properties of an image. + * + * @param request - The request {@link UpdateImageRequest} + * @returns A Promise of UpdateImageResponse + */ + updateImage = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateImageRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/images/${validatePathParam('imageId', request.imageId)}`, + }, + unmarshalUpdateImageResponse, + ) + /** * Delete an Instance image. Delete the image with the specified ID. * @@ -777,6 +803,28 @@ export class API extends ParentAPI { unmarshalSetSnapshotResponse, ) + /** + * Update a snapshot. Update the properties of a snapshot. + * + * @param request - The request {@link UpdateSnapshotRequest} + * @returns A Promise of UpdateSnapshotResponse + */ + updateSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, + }, + unmarshalUpdateSnapshotResponse, + ) + /** * Delete a snapshot. Delete the snapshot with the specified ID. * @@ -1051,6 +1099,31 @@ export class API extends ParentAPI { unmarshalSetSecurityGroupResponse, ) + /** + * Update a security group. Update the properties of security group. + * + * @param request - The request {@link UpdateSecurityGroupRequest} + * @returns A Promise of UpdateSecurityGroupResponse + */ + updateSecurityGroup = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateSecurityGroupRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/security_groups/${validatePathParam( + 'securityGroupId', + request.securityGroupId, + )}`, + }, + unmarshalUpdateSecurityGroupResponse, + ) + /** * Get default rules. Lists the default rules applied to all the security * groups. @@ -1227,6 +1300,37 @@ export class API extends ParentAPI { unmarshalSetSecurityGroupRuleResponse, ) + /** + * Update security group rule. Update the properties of a rule from a + * specified security group. + * + * @param request - The request {@link UpdateSecurityGroupRuleRequest} + * @returns A Promise of UpdateSecurityGroupRuleResponse + */ + updateSecurityGroupRule = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateSecurityGroupRuleRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/instance/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/security_groups/${validatePathParam( + 'securityGroupId', + request.securityGroupId, + )}/rules/${validatePathParam( + 'securityGroupRuleId', + request.securityGroupRuleId, + )}`, + }, + unmarshalUpdateSecurityGroupRuleResponse, + ) + protected pageOfListPlacementGroups = ( request: Readonly = {}, ) => diff --git a/packages/clients/src/api/instance/v1/api.utils.ts b/packages/clients/src/api/instance/v1/api.utils.ts index 881f1e71f..d7653f468 100644 --- a/packages/clients/src/api/instance/v1/api.utils.ts +++ b/packages/clients/src/api/instance/v1/api.utils.ts @@ -12,8 +12,6 @@ import { SNAPSHOT_TRANSIENT_STATUSES, VOLUME_TRANSIENT_STATUSES, } from './content.gen' -import { unmarshalSetImageResponse } from './marshalling.gen' -import { marshalSetImageRequestWithID } from './marshalling.utils' import type { CreateServerRequest, GetImageRequest, @@ -31,10 +29,6 @@ import type { Volume, VolumeServerTemplate, } from './types.gen' -import type { - SetImageResponse, - SetSecurityGroupRuleRequest, -} from './types.private.gen' import type { AttachVolumeRequest, AttachVolumeResponse, @@ -42,14 +36,6 @@ import type { DetachVolumeResponse, GetServerUserDataRequest, SetServerUserDataRequest, - UpdateImageRequest, - UpdateImageResponse, - UpdateSecurityGroupRequest, - UpdateSecurityGroupResponse, - UpdateSecurityGroupRuleRequest, - UpdateSecurityGroupRuleResponse, - UpdateSnapshotRequest, - UpdateSnapshotResponse, } from './types.utils' const validateNotUndefined = (obj: T | undefined): T => { @@ -204,133 +190,6 @@ export class InstanceV1UtilsAPI extends API { options?.timeout, ) - /** - * Updates a snapshot. - * - * @param request - The request {@link UpdateSnapshotRequest} - * @returns A Promise of UpdateSnapshotResponse - */ - updateSnapshot = ( - request: Readonly, - ): Promise => - this.getSnapshot(request) - .then(res => validateNotUndefined(res.snapshot)) - .then(snapshot => - this._setSnapshot({ - ...snapshot, - name: request.name ?? snapshot.name, - snapshotId: snapshot.id, - }), - ) - .then(res => ({ snapshot: res.snapshot })) - - /** - * Updates a security group. - * - * @param request - The request {@link UpdateSecurityGroupRequest} - * @returns A Promise of UpdateSecurityGroupResponse - */ - updateSecurityGroup = ( - request: UpdateSecurityGroupRequest, - ): Promise => - this.getSecurityGroup({ - securityGroupId: request.securityGroupId, - zone: request.zone, - }) - .then(res => validateNotUndefined(res.securityGroup)) - .then(securityGroup => - this._setSecurityGroup({ - creationDate: securityGroup.creationDate, - description: request.description ?? securityGroup.description, - enableDefaultSecurity: - request.enableDefaultSecurity ?? - securityGroup.enableDefaultSecurity, - id: securityGroup.id, - inboundDefaultPolicy: - request.inboundDefaultPolicy ?? securityGroup.inboundDefaultPolicy, - modificationDate: securityGroup.modificationDate, - name: request.name ?? securityGroup.name, - organization: securityGroup.organization, - organizationDefault: - request.organizationDefault ?? securityGroup.organizationDefault, - outboundDefaultPolicy: - request.outboundDefaultPolicy ?? - securityGroup.outboundDefaultPolicy, - project: securityGroup.project, - projectDefault: - request.projectDefault ?? securityGroup.projectDefault, - servers: securityGroup.servers, - stateful: request.stateful ?? securityGroup.stateful, - zone: request.zone, - }), - ) - .then(res => ({ securityGroup: res.securityGroup })) - - /** - * Updates a security group rule. - * - * @param request - The request {@link UpdateSecurityGroupRuleRequest} - * @returns A Promise of UpdateSecurityGroupRuleResponse - */ - updateSecurityGroupRule = ( - request: UpdateSecurityGroupRuleRequest, - ): Promise => - this.getSecurityGroupRule({ - securityGroupId: request.securityGroupId, - securityGroupRuleId: request.securityGroupRuleId, - zone: request.zone, - }) - .then(res => validateNotUndefined(res.rule)) - .then(rule => { - let sReq: SetSecurityGroupRuleRequest = { - action: request.action ?? rule.action, - destPortFrom: rule.destPortFrom, - destPortTo: rule.destPortTo, - direction: request.direction ?? rule.direction, - editable: rule.editable, - id: request.securityGroupRuleId, - ipRange: request.ipRange ?? rule.ipRange, - position: request.position ?? rule.position, - protocol: request.protocol ?? rule.protocol, - securityGroupId: request.securityGroupId, - securityGroupRuleId: request.securityGroupRuleId, - } - if (request.destPortFrom) { - sReq = { - ...sReq, - destPortFrom: - request.destPortFrom > 0 ? request.destPortFrom : undefined, - } - } - if (request.destPortTo) { - sReq = { - ...sReq, - destPortTo: request.destPortTo > 0 ? request.destPortTo : undefined, - } - } - if ( - sReq.destPortFrom && - sReq.destPortTo && - sReq.destPortFrom === sReq.destPortTo - ) { - sReq = { - ...sReq, - destPortTo: undefined, - } - } - // When we use ICMP protocol portFrom and portTo should be set to nil - if (request.protocol === 'ICMP') { - sReq = { - ...sReq, - destPortFrom: undefined, - destPortTo: undefined, - } - } - - return this._setSecurityGroupRule(sReq) - }) - .then(res => ({ rule: res.rule })) - /** * Updates a server. * @@ -478,41 +337,6 @@ export class InstanceV1UtilsAPI extends API { } as UpdateServerRequest).then(obj => obj as DetachVolumeResponse) } - /** - * Updates an image. - * - * @param request - The request {@link UpdateImageRequest} - * @returns A Promise of UpdateImageResponse - */ - updateImage = ( - request: Readonly, - ): Promise => - this.getImage({ zone: request.zone, imageId: request.imageId }) - .then(res => validateNotUndefined(res.image)) - .then(image => ({ - ...image, - name: request.name ?? image.name, - tags: request.tags ?? image.tags, - id: image.id, - })) - .then(imageReq => - this.client.fetch( - { - body: JSON.stringify( - marshalSetImageRequestWithID(imageReq, this.client.settings), - ), - headers: { 'Content-Type': 'application/json; charset=utf-8' }, - method: 'PUT', - path: `/instance/v1/zones/${validatePathParam( - 'zone', - imageReq.zone, - )}/images/${validatePathParam('id', imageReq.id)}`, - }, - unmarshalSetImageResponse, - ), - ) - .then(res => ({ image: res.image })) - /** * Get the content of a user data on a server for the given key. * diff --git a/packages/clients/src/api/instance/v1/index.gen.ts b/packages/clients/src/api/instance/v1/index.gen.ts index 297adaa30..883be8999 100644 --- a/packages/clients/src/api/instance/v1/index.gen.ts +++ b/packages/clients/src/api/instance/v1/index.gen.ts @@ -157,6 +157,8 @@ export type { SnapshotVolumeType, Task, TaskStatus, + UpdateImageRequest, + UpdateImageResponse, UpdateIpRequest, UpdateIpResponse, UpdatePlacementGroupRequest, @@ -164,11 +166,18 @@ export type { UpdatePlacementGroupServersRequest, UpdatePlacementGroupServersResponse, UpdatePrivateNICRequest, + UpdateSecurityGroupRequest, + UpdateSecurityGroupResponse, + UpdateSecurityGroupRuleRequest, + UpdateSecurityGroupRuleResponse, UpdateServerRequest, UpdateServerResponse, + UpdateSnapshotRequest, + UpdateSnapshotResponse, UpdateVolumeRequest, UpdateVolumeResponse, Volume, + VolumeImageUpdateTemplate, VolumeServer, VolumeServerState, VolumeServerTemplate, diff --git a/packages/clients/src/api/instance/v1/marshalling.gen.ts b/packages/clients/src/api/instance/v1/marshalling.gen.ts index 01ca0f59c..237fa3bfe 100644 --- a/packages/clients/src/api/instance/v1/marshalling.gen.ts +++ b/packages/clients/src/api/instance/v1/marshalling.gen.ts @@ -102,6 +102,8 @@ import type { Snapshot, SnapshotBaseVolume, Task, + UpdateImageRequest, + UpdateImageResponse, UpdateIpRequest, UpdateIpResponse, UpdatePlacementGroupRequest, @@ -109,11 +111,18 @@ import type { UpdatePlacementGroupServersRequest, UpdatePlacementGroupServersResponse, UpdatePrivateNICRequest, + UpdateSecurityGroupRequest, + UpdateSecurityGroupResponse, + UpdateSecurityGroupRuleRequest, + UpdateSecurityGroupRuleResponse, UpdateServerRequest, UpdateServerResponse, + UpdateSnapshotRequest, + UpdateSnapshotResponse, UpdateVolumeRequest, UpdateVolumeResponse, Volume, + VolumeImageUpdateTemplate, VolumeServer, VolumeServerTemplate, VolumeSummary, @@ -1494,6 +1503,20 @@ export const unmarshalSetSnapshotResponse = ( } as SetSnapshotResponse } +export const unmarshalUpdateImageResponse = ( + data: unknown, +): UpdateImageResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'UpdateImageResponse' failed as data isn't a dictionary.`, + ) + } + + return { + image: data.image ? unmarshalImage(data.image) : undefined, + } as UpdateImageResponse +} + export const unmarshalUpdateIpResponse = (data: unknown): UpdateIpResponse => { if (!isJSONObject(data)) { throw new TypeError( @@ -1539,6 +1562,36 @@ export const unmarshalUpdatePlacementGroupServersResponse = ( } as UpdatePlacementGroupServersResponse } +export const unmarshalUpdateSecurityGroupResponse = ( + data: unknown, +): UpdateSecurityGroupResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'UpdateSecurityGroupResponse' failed as data isn't a dictionary.`, + ) + } + + return { + securityGroup: data.security_group + ? unmarshalSecurityGroup(data.security_group) + : undefined, + } as UpdateSecurityGroupResponse +} + +export const unmarshalUpdateSecurityGroupRuleResponse = ( + data: unknown, +): UpdateSecurityGroupRuleResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'UpdateSecurityGroupRuleResponse' failed as data isn't a dictionary.`, + ) + } + + return { + rule: data.rule ? unmarshalSecurityGroupRule(data.rule) : undefined, + } as UpdateSecurityGroupRuleResponse +} + export const unmarshalUpdateServerResponse = ( data: unknown, ): UpdateServerResponse => { @@ -1553,6 +1606,20 @@ export const unmarshalUpdateServerResponse = ( } as UpdateServerResponse } +export const unmarshalUpdateSnapshotResponse = ( + data: unknown, +): UpdateSnapshotResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'UpdateSnapshotResponse' failed as data isn't a dictionary.`, + ) + } + + return { + snapshot: data.snapshot ? unmarshalSnapshot(data.snapshot) : undefined, + } as UpdateSnapshotResponse +} + export const unmarshalUpdateVolumeResponse = ( data: unknown, ): UpdateVolumeResponse => { @@ -2275,6 +2342,33 @@ export const marshalSetSnapshotRequest = ( volume_type: request.volumeType, }) +const marshalVolumeImageUpdateTemplate = ( + request: VolumeImageUpdateTemplate, + defaults: DefaultValues, +): Record => ({ + id: request.id, +}) + +export const marshalUpdateImageRequest = ( + request: UpdateImageRequest, + defaults: DefaultValues, +): Record => ({ + arch: request.arch, + extra_volumes: + request.extraVolumes !== undefined + ? Object.entries(request.extraVolumes).reduce( + (acc, [key, value]) => ({ + ...acc, + [key]: marshalVolumeImageUpdateTemplate(value, defaults), + }), + {}, + ) + : undefined, + name: request.name, + public: request.public, + tags: request.tags, +}) + export const marshalUpdateIpRequest = ( request: UpdateIpRequest, defaults: DefaultValues, @@ -2309,6 +2403,34 @@ export const marshalUpdatePrivateNICRequest = ( tags: request.tags, }) +export const marshalUpdateSecurityGroupRequest = ( + request: UpdateSecurityGroupRequest, + defaults: DefaultValues, +): Record => ({ + description: request.description, + enable_default_security: request.enableDefaultSecurity, + inbound_default_policy: request.inboundDefaultPolicy, + name: request.name, + organization_default: request.organizationDefault, + outbound_default_policy: request.outboundDefaultPolicy, + project_default: request.projectDefault, + stateful: request.stateful, + tags: request.tags, +}) + +export const marshalUpdateSecurityGroupRuleRequest = ( + request: UpdateSecurityGroupRuleRequest, + defaults: DefaultValues, +): Record => ({ + action: request.action, + dest_port_from: request.destPortFrom, + dest_port_to: request.destPortTo, + direction: request.direction, + ip_range: request.ipRange, + position: request.position, + protocol: request.protocol, +}) + const marshalSecurityGroupTemplate = ( request: SecurityGroupTemplate, defaults: DefaultValues, @@ -2349,6 +2471,14 @@ export const marshalUpdateServerRequest = ( : undefined, }) +export const marshalUpdateSnapshotRequest = ( + request: UpdateSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + tags: request.tags, +}) + export const marshalUpdateVolumeRequest = ( request: UpdateVolumeRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/instance/v1/types.gen.ts b/packages/clients/src/api/instance/v1/types.gen.ts index 238e8e28e..ca02e8e6f 100644 --- a/packages/clients/src/api/instance/v1/types.gen.ts +++ b/packages/clients/src/api/instance/v1/types.gen.ts @@ -35,15 +35,27 @@ export type PlacementGroupPolicyType = 'max_availability' | 'low_latency' export type PrivateNICState = 'available' | 'syncing' | 'syncing_error' -export type SecurityGroupPolicy = 'accept' | 'drop' +export type SecurityGroupPolicy = 'unknown_policy' | 'accept' | 'drop' -export type SecurityGroupRuleAction = 'accept' | 'drop' +export type SecurityGroupRuleAction = 'unknown_action' | 'accept' | 'drop' -export type SecurityGroupRuleDirection = 'inbound' | 'outbound' +export type SecurityGroupRuleDirection = + | 'unknown_direction' + | 'inbound' + | 'outbound' -export type SecurityGroupRuleProtocol = 'TCP' | 'UDP' | 'ICMP' | 'ANY' +export type SecurityGroupRuleProtocol = + | 'unknown_protocol' + | 'TCP' + | 'UDP' + | 'ICMP' + | 'ANY' -export type SecurityGroupState = 'available' | 'syncing' | 'syncing_error' +export type SecurityGroupState = + | 'unknown_state' + | 'available' + | 'syncing' + | 'syncing_error' export type ServerAction = | 'poweron' @@ -719,6 +731,11 @@ export interface SetSecurityGroupRulesRequestRule { zone?: Zone } +export interface VolumeImageUpdateTemplate { + /** UUID of the snapshot. */ + id: string +} + export interface SecurityGroupTemplate { id: string name: string @@ -751,13 +768,9 @@ export type ApplyBlockMigrationRequest = { export type AttachServerVolumeRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone - /** UUID of the Instance. */ serverId: string - /** UUID of the Volume to attach. */ volumeId: string - /** Type of the volume to attach. */ volumeType?: AttachServerVolumeRequestVolumeType - /** Force the Instance to boot on this volume. */ boot?: boolean } @@ -1167,9 +1180,7 @@ export type DeleteVolumeRequest = { export type DetachServerVolumeRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone - /** UUID of the Instance. */ serverId: string - /** UUID of the Volume to detach. */ volumeId: string } @@ -1817,6 +1828,30 @@ export interface SetSecurityGroupRulesResponse { rules: SecurityGroupRule[] } +export type UpdateImageRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the image. */ + imageId: string + /** Name of the image. */ + name?: string + /** Architecture of the image. */ + arch?: Arch + /** + * Additional snapshots of the image, with extra_volumeKey being the position + * of the snapshot in the image. + */ + extraVolumes?: Record + /** Tags of the image. */ + tags?: string[] + /** True to set the image as public. */ + public?: boolean +} + +export interface UpdateImageResponse { + image?: Image +} + export type UpdateIpRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone @@ -1879,6 +1914,65 @@ export type UpdatePrivateNICRequest = { tags?: string[] } +export type UpdateSecurityGroupRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the security group. */ + securityGroupId: string + /** Name of the security group. */ + name?: string + /** Description of the security group. */ + description?: string + /** + * True to block SMTP on IPv4 and IPv6. This feature is read only, please open + * a support ticket if you need to make it configurable. + */ + enableDefaultSecurity?: boolean + /** Default inbound policy. */ + inboundDefaultPolicy?: SecurityGroupPolicy + /** Tags of the security group. */ + tags?: string[] + /** @deprecated Please use project_default instead. */ + organizationDefault?: boolean + /** True use this security group for future Instances created in this project. */ + projectDefault?: boolean + /** Default outbound policy. */ + outboundDefaultPolicy?: SecurityGroupPolicy + /** True to set the security group as stateful. */ + stateful?: boolean +} + +export interface UpdateSecurityGroupResponse { + securityGroup?: SecurityGroup +} + +export type UpdateSecurityGroupRuleRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the security group. */ + securityGroupId: string + /** UUID of the rule. */ + securityGroupRuleId: string + /** Protocol family this rule applies to. */ + protocol?: SecurityGroupRuleProtocol + /** Direction the rule applies to. */ + direction?: SecurityGroupRuleDirection + /** Action to apply when the rule matches a packet. */ + action?: SecurityGroupRuleAction + /** Range of IP addresses these rules apply to. */ + ipRange?: string + /** Beginning of the range of ports this rule applies to (inclusive). */ + destPortFrom?: number + /** End of the range of ports this rule applies to (inclusive). */ + destPortTo?: number + /** Position of this rule in the security group rules list. */ + position?: number +} + +export interface UpdateSecurityGroupRuleResponse { + rule?: SecurityGroupRule +} + export type UpdateServerRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone @@ -1924,6 +2018,21 @@ export interface UpdateServerResponse { server?: Server } +export type UpdateSnapshotRequest = { + /** Zone to target. If none is passed will use default zone from the config. */ + zone?: Zone + /** UUID of the snapshot. */ + snapshotId: string + /** Name of the snapshot. */ + name?: string + /** Tags of the snapshot. */ + tags?: string[] +} + +export interface UpdateSnapshotResponse { + snapshot?: Snapshot +} + export type UpdateVolumeRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone diff --git a/packages/clients/src/api/instance/v1/types.private.gen.ts b/packages/clients/src/api/instance/v1/types.private.gen.ts index 025365a55..c747e7b22 100644 --- a/packages/clients/src/api/instance/v1/types.private.gen.ts +++ b/packages/clients/src/api/instance/v1/types.private.gen.ts @@ -37,7 +37,7 @@ export interface SetImageResponse { export type SetSecurityGroupRequest = { /** Zone to target. If none is passed will use default zone from the config. */ zone?: Zone - /** ID of the security group (will be ignored). */ + /** UUID of the security group. */ id: string /** Name of the security group. */ name: string diff --git a/packages/clients/src/api/instance/v1/types.utils.ts b/packages/clients/src/api/instance/v1/types.utils.ts index a9924af4f..d4a8f22e6 100644 --- a/packages/clients/src/api/instance/v1/types.utils.ts +++ b/packages/clients/src/api/instance/v1/types.utils.ts @@ -1,77 +1,5 @@ import type { Zone } from '../../../scw/locality' -import type { - Image, - SecurityGroup, - SecurityGroupPolicy, - SecurityGroupRule, - SecurityGroupRuleAction, - SecurityGroupRuleDirection, - SecurityGroupRuleProtocol, - Server, - Snapshot, -} from './types.gen' - -export type UpdateSnapshotRequest = { - /** Zone to target. If none is passed will use default zone from the config */ - zone?: Zone - /** UUID of the snapshot you want to update */ - snapshotId: string - /** Name of the snapshot */ - name?: string -} - -export interface UpdateSnapshotResponse { - snapshot?: Snapshot -} - -/** UpdateSecurityGroupRequest contains the parameters to update a security group */ -export type UpdateSecurityGroupRequest = { - /** Zone to target. If none is passed will use default zone from the config */ - zone?: Zone - securityGroupId: string - name?: string - description?: string - inboundDefaultPolicy?: SecurityGroupPolicy - outboundDefaultPolicy?: SecurityGroupPolicy - stateful?: boolean - organizationDefault?: boolean - projectDefault?: boolean - enableDefaultSecurity?: boolean -} - -export interface UpdateSecurityGroupResponse { - securityGroup?: SecurityGroup -} - -/** - * UpdateSecurityGroupRuleRequest contains the parameters to update a security - * group rule - */ -export type UpdateSecurityGroupRuleRequest = { - /** Zone to target. If none is passed will use default zone from the config */ - zone?: Zone - securityGroupId: string - securityGroupRuleId: string - protocol?: SecurityGroupRuleProtocol - direction?: SecurityGroupRuleDirection - action?: SecurityGroupRuleAction - ipRange?: string - position?: number - /** - * If set to 0, DestPortFrom will be removed. See - * SecurityGroupRule.DestPortFrom for more information - */ - destPortFrom?: number - /** - * If set to 0, DestPortTo will be removed. See SecurityGroupRule.DestPortTo - * for more information - */ - destPortTo?: number -} - -export interface UpdateSecurityGroupRuleResponse { - rule?: SecurityGroupRule -} +import type { Server } from './types.gen' export type AttachVolumeRequest = { zone?: Zone @@ -94,18 +22,6 @@ export interface DetachVolumeResponse { server?: Server } -export type UpdateImageRequest = { - /** Zone to target. If none is passed will use default zone from the config */ - zone?: Zone - imageId: string - name?: string - tags?: string[] -} - -export interface UpdateImageResponse { - image?: Image -} - export type GetServerUserDataRequest = { /** Zone to target. If none is passed will use default zone from the config */ zone?: Zone