Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/clients/src/api/vpc/v2/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -40,6 +43,8 @@ import type {
DeleteVPCRequest,
EnableDHCPRequest,
EnableRoutingRequest,
GetAclRequest,
GetAclResponse,
GetPrivateNetworkRequest,
GetRouteRequest,
GetVPCRequest,
Expand All @@ -51,6 +56,8 @@ import type {
ListVPCsResponse,
PrivateNetwork,
Route,
SetAclRequest,
SetAclResponse,
SetSubnetsRequest,
SetSubnetsResponse,
UpdatePrivateNetworkRequest,
Expand Down Expand Up @@ -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<GetAclRequest>) =>
this.client.fetch<GetAclResponse>(
{
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<SetAclRequest>) =>
this.client.fetch<SetAclResponse>(
{
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,
)
}
7 changes: 7 additions & 0 deletions packages/clients/src/api/vpc/v2/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -14,6 +17,8 @@ export type {
DeleteVPCRequest,
EnableDHCPRequest,
EnableRoutingRequest,
GetAclRequest,
GetAclResponse,
GetPrivateNetworkRequest,
GetRouteRequest,
GetVPCRequest,
Expand All @@ -28,6 +33,8 @@ export type {
ListVPCsResponse,
PrivateNetwork,
Route,
SetAclRequest,
SetAclResponse,
SetSubnetsRequest,
SetSubnetsResponse,
Subnet,
Expand Down
74 changes: 74 additions & 0 deletions packages/clients/src/api/vpc/v2/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import {
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
AclRule,
AddSubnetsRequest,
AddSubnetsResponse,
CreatePrivateNetworkRequest,
CreateRouteRequest,
CreateVPCRequest,
DeleteSubnetsRequest,
DeleteSubnetsResponse,
GetAclResponse,
ListPrivateNetworksResponse,
ListSubnetsResponse,
ListVPCsResponse,
PrivateNetwork,
Route,
SetAclRequest,
SetAclResponse,
SetSubnetsRequest,
SetSubnetsResponse,
Subnet,
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -248,6 +298,30 @@ export const marshalDeleteSubnetsRequest = (
subnets: request.subnets,
})

const marshalAclRule = (
request: AclRule,
defaults: DefaultValues,
): Record<string, unknown> => ({
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<string, unknown> => ({
default_policy: request.defaultPolicy,
is_ipv6: request.isIpv6,
rules: request.rules.map(elt => marshalAclRule(elt, defaults)),
})

export const marshalSetSubnetsRequest = (
request: SetSubnetsRequest,
defaults: DefaultValues,
Expand Down
87 changes: 87 additions & 0 deletions packages/clients/src/api/vpc/v2/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions packages/clients/src/api/vpc/v2/validation-rules.gen.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading