diff --git a/packages/clients/src/api/vpc/v2/api.gen.ts b/packages/clients/src/api/vpc/v2/api.gen.ts index 54f37022c..b3cb2f320 100644 --- a/packages/clients/src/api/vpc/v2/api.gen.ts +++ b/packages/clients/src/api/vpc/v2/api.gen.ts @@ -13,17 +13,20 @@ import { marshalCreateRouteRequest, marshalCreateVPCRequest, marshalDeleteSubnetsRequest, + marshalSetAclRequest, marshalSetSubnetsRequest, marshalUpdatePrivateNetworkRequest, marshalUpdateRouteRequest, marshalUpdateVPCRequest, unmarshalAddSubnetsResponse, unmarshalDeleteSubnetsResponse, + unmarshalGetAclResponse, unmarshalListPrivateNetworksResponse, unmarshalListSubnetsResponse, unmarshalListVPCsResponse, unmarshalPrivateNetwork, unmarshalRoute, + unmarshalSetAclResponse, unmarshalSetSubnetsResponse, unmarshalVPC, } from './marshalling.gen' @@ -40,6 +43,8 @@ import type { DeleteVPCRequest, EnableDHCPRequest, EnableRoutingRequest, + GetAclRequest, + GetAclResponse, GetPrivateNetworkRequest, GetRouteRequest, GetVPCRequest, @@ -51,6 +56,8 @@ import type { ListVPCsResponse, PrivateNetwork, Route, + SetAclRequest, + SetAclResponse, SetSubnetsRequest, SetSubnetsResponse, UpdatePrivateNetworkRequest, @@ -479,4 +486,41 @@ export class API extends ParentAPI { method: 'DELETE', path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/routes/${validatePathParam('routeId', request.routeId)}`, }) + + /** + * Get Acl Rules for VPC. Retrieve a list of ACL rules for a VPC, specified by + * its VPC ID. + * + * @param request - The request {@link GetAclRequest} + * @returns A Promise of GetAclResponse + */ + getAcl = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/vpc/${validatePathParam('vpcId', request.vpcId)}/acl-rules`, + urlParams: urlParams(['is_ipv6', request.isIpv6]), + }, + unmarshalGetAclResponse, + ) + + /** + * Set VPC ACL rules. Set the list of ACL rules and the default routing policy + * for a VPC. + * + * @param request - The request {@link SetAclRequest} + * @returns A Promise of SetAclResponse + */ + setAcl = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalSetAclRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/vpc/${validatePathParam('vpcId', request.vpcId)}/acl-rules`, + }, + unmarshalSetAclResponse, + ) } diff --git a/packages/clients/src/api/vpc/v2/index.gen.ts b/packages/clients/src/api/vpc/v2/index.gen.ts index 000a8628c..143ce3987 100644 --- a/packages/clients/src/api/vpc/v2/index.gen.ts +++ b/packages/clients/src/api/vpc/v2/index.gen.ts @@ -2,6 +2,9 @@ // If you have any remark or suggestion do not hesitate to open an issue. export { API } from './api.gen' export type { + AclRule, + AclRuleProtocol, + Action, AddSubnetsRequest, AddSubnetsResponse, CreatePrivateNetworkRequest, @@ -14,6 +17,8 @@ export type { DeleteVPCRequest, EnableDHCPRequest, EnableRoutingRequest, + GetAclRequest, + GetAclResponse, GetPrivateNetworkRequest, GetRouteRequest, GetVPCRequest, @@ -28,6 +33,8 @@ export type { ListVPCsResponse, PrivateNetwork, Route, + SetAclRequest, + SetAclResponse, SetSubnetsRequest, SetSubnetsResponse, Subnet, diff --git a/packages/clients/src/api/vpc/v2/marshalling.gen.ts b/packages/clients/src/api/vpc/v2/marshalling.gen.ts index daa154cb9..524a05d2d 100644 --- a/packages/clients/src/api/vpc/v2/marshalling.gen.ts +++ b/packages/clients/src/api/vpc/v2/marshalling.gen.ts @@ -8,6 +8,7 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + AclRule, AddSubnetsRequest, AddSubnetsResponse, CreatePrivateNetworkRequest, @@ -15,11 +16,14 @@ import type { CreateVPCRequest, DeleteSubnetsRequest, DeleteSubnetsResponse, + GetAclResponse, ListPrivateNetworksResponse, ListSubnetsResponse, ListVPCsResponse, PrivateNetwork, Route, + SetAclRequest, + SetAclResponse, SetSubnetsRequest, SetSubnetsResponse, Subnet, @@ -141,6 +145,39 @@ export const unmarshalDeleteSubnetsResponse = ( } as DeleteSubnetsResponse } +const unmarshalAclRule = (data: unknown): AclRule => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AclRule' failed as data isn't a dictionary.`, + ) + } + + return { + action: data.action, + description: data.description, + destination: data.destination, + dstPortHigh: data.dst_port_high, + dstPortLow: data.dst_port_low, + protocol: data.protocol, + source: data.source, + srcPortHigh: data.src_port_high, + srcPortLow: data.src_port_low, + } as AclRule +} + +export const unmarshalGetAclResponse = (data: unknown): GetAclResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'GetAclResponse' failed as data isn't a dictionary.`, + ) + } + + return { + defaultPolicy: data.default_policy, + rules: unmarshalArrayOfObject(data.rules, unmarshalAclRule), + } as GetAclResponse +} + export const unmarshalListPrivateNetworksResponse = ( data: unknown, ): ListPrivateNetworksResponse => { @@ -187,6 +224,19 @@ export const unmarshalListVPCsResponse = (data: unknown): ListVPCsResponse => { } as ListVPCsResponse } +export const unmarshalSetAclResponse = (data: unknown): SetAclResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SetAclResponse' failed as data isn't a dictionary.`, + ) + } + + return { + defaultPolicy: data.default_policy, + rules: unmarshalArrayOfObject(data.rules, unmarshalAclRule), + } as SetAclResponse +} + export const unmarshalSetSubnetsResponse = ( data: unknown, ): SetSubnetsResponse => { @@ -248,6 +298,30 @@ export const marshalDeleteSubnetsRequest = ( subnets: request.subnets, }) +const marshalAclRule = ( + request: AclRule, + defaults: DefaultValues, +): Record => ({ + action: request.action, + description: request.description, + destination: request.destination, + dst_port_high: request.dstPortHigh, + dst_port_low: request.dstPortLow, + protocol: request.protocol, + source: request.source, + src_port_high: request.srcPortHigh, + src_port_low: request.srcPortLow, +}) + +export const marshalSetAclRequest = ( + request: SetAclRequest, + defaults: DefaultValues, +): Record => ({ + default_policy: request.defaultPolicy, + is_ipv6: request.isIpv6, + rules: request.rules.map(elt => marshalAclRule(elt, defaults)), +}) + export const marshalSetSubnetsRequest = ( request: SetSubnetsRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/vpc/v2/types.gen.ts b/packages/clients/src/api/vpc/v2/types.gen.ts index e33d426d8..8eef6bc9e 100644 --- a/packages/clients/src/api/vpc/v2/types.gen.ts +++ b/packages/clients/src/api/vpc/v2/types.gen.ts @@ -2,6 +2,10 @@ // If you have any remark or suggestion do not hesitate to open an issue. import type { Region as ScwRegion } from '../../../bridge' +export type AclRuleProtocol = 'ANY' | 'TCP' | 'UDP' | 'ICMP' + +export type Action = 'unknown_action' | 'accept' | 'drop' + export type ListPrivateNetworksRequestOrderBy = | 'created_at_asc' | 'created_at_desc' @@ -83,6 +87,45 @@ export interface Route { region: ScwRegion } +export interface AclRule { + /** Protocol to which this rule applies. */ + protocol: AclRuleProtocol + /** + * Source IP range to which this rule applies (CIDR notation with subnet + * mask). + */ + source: string + /** + * Starting port of the source port range to which this rule applies + * (inclusive). + */ + srcPortLow: number + /** + * Ending port of the source port range to which this rule applies + * (inclusive). + */ + srcPortHigh: number + /** + * Destination IP range to which this rule applies (CIDR notation with subnet + * mask). + */ + destination: string + /** + * Starting port of the destination port range to which this rule applies + * (inclusive). + */ + dstPortLow: number + /** + * Ending port of the destination port range to which this rule applies + * (inclusive). + */ + dstPortHigh: number + /** Policy to apply to the packet. */ + action: Action + /** Rule description. */ + description?: string +} + export interface VPC { /** VPC ID. */ id: string @@ -244,6 +287,26 @@ export type EnableRoutingRequest = { vpcId: string } +export type GetAclRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: ScwRegion + /** ID of the Network ACL's VPC. */ + vpcId: string + /** + * Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each + * Network ACL can have rules for only one IP type. + */ + isIpv6: boolean +} + +export interface GetAclResponse { + rules: AclRule[] + defaultPolicy: Action +} + export type GetPrivateNetworkRequest = { /** * Region to target. If none is passed will use default region from the @@ -413,6 +476,30 @@ export interface ListVPCsResponse { totalCount: number } +export type SetAclRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: ScwRegion + /** ID of the Network ACL's VPC. */ + vpcId: string + /** List of Network ACL rules. */ + rules: AclRule[] + /** + * Defines whether this set of ACL rules is for IPv6 (false = IPv4). Each + * Network ACL can have rules for only one IP type. + */ + isIpv6: boolean + /** Action to take for packets which do not match any rules. */ + defaultPolicy: Action +} + +export interface SetAclResponse { + rules: AclRule[] + defaultPolicy: Action +} + export type SetSubnetsRequest = { /** * Region to target. If none is passed will use default region from the diff --git a/packages/clients/src/api/vpc/v2/validation-rules.gen.ts b/packages/clients/src/api/vpc/v2/validation-rules.gen.ts index 86c30e5f9..6cd221d2d 100644 --- a/packages/clients/src/api/vpc/v2/validation-rules.gen.ts +++ b/packages/clients/src/api/vpc/v2/validation-rules.gen.ts @@ -1,6 +1,24 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. +export const AclRule = { + description: { + maxLength: 200, + }, + dstPortHigh: { + lessThanOrEqual: 65536, + }, + dstPortLow: { + lessThanOrEqual: 65536, + }, + srcPortHigh: { + lessThanOrEqual: 65536, + }, + srcPortLow: { + lessThanOrEqual: 65536, + }, +} + export const Route = { description: { maxLength: 200,