Skip to content

Commit

Permalink
feat(vpc): add custom routes CRUD (#1358)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Jul 5, 2024
1 parent 03d3ff5 commit fa10fb2
Show file tree
Hide file tree
Showing 5 changed files with 217 additions and 0 deletions.
73 changes: 73 additions & 0 deletions packages/clients/src/api/vpc/v2/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,39 @@ import type { Region } from '../../../bridge'
import {
marshalAddSubnetsRequest,
marshalCreatePrivateNetworkRequest,
marshalCreateRouteRequest,
marshalCreateVPCRequest,
marshalDeleteSubnetsRequest,
marshalMigrateZonalPrivateNetworksRequest,
marshalSetSubnetsRequest,
marshalUpdatePrivateNetworkRequest,
marshalUpdateRouteRequest,
marshalUpdateVPCRequest,
unmarshalAddSubnetsResponse,
unmarshalDeleteSubnetsResponse,
unmarshalListPrivateNetworksResponse,
unmarshalListSubnetsResponse,
unmarshalListVPCsResponse,
unmarshalPrivateNetwork,
unmarshalRoute,
unmarshalSetSubnetsResponse,
unmarshalVPC,
} from './marshalling.gen'
import type {
AddSubnetsRequest,
AddSubnetsResponse,
CreatePrivateNetworkRequest,
CreateRouteRequest,
CreateVPCRequest,
DeletePrivateNetworkRequest,
DeleteRouteRequest,
DeleteSubnetsRequest,
DeleteSubnetsResponse,
DeleteVPCRequest,
EnableDHCPRequest,
EnableRoutingRequest,
GetPrivateNetworkRequest,
GetRouteRequest,
GetVPCRequest,
ListPrivateNetworksRequest,
ListPrivateNetworksResponse,
Expand All @@ -46,9 +52,11 @@ import type {
ListVPCsResponse,
MigrateZonalPrivateNetworksRequest,
PrivateNetwork,
Route,
SetSubnetsRequest,
SetSubnetsResponse,
UpdatePrivateNetworkRequest,
UpdateRouteRequest,
UpdateVPCRequest,
VPC,
} from './types.gen'
Expand Down Expand Up @@ -428,4 +436,69 @@ export class API extends ParentAPI {
},
unmarshalDeleteSubnetsResponse,
)

/**
* Create a Route. Create a new custom Route.
*
* @param request - The request {@link CreateRouteRequest}
* @returns A Promise of Route
*/
createRoute = (request: Readonly<CreateRouteRequest>) =>
this.client.fetch<Route>(
{
body: JSON.stringify(
marshalCreateRouteRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/routes`,
},
unmarshalRoute,
)

/**
* Get a Route. Retrieve details of an existing Route, specified by its Route
* ID.
*
* @param request - The request {@link GetRouteRequest}
* @returns A Promise of Route
*/
getRoute = (request: Readonly<GetRouteRequest>) =>
this.client.fetch<Route>(
{
method: 'GET',
path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/routes/${validatePathParam('routeId', request.routeId)}`,
},
unmarshalRoute,
)

/**
* Update Route. Update parameters of the specified Route.
*
* @param request - The request {@link UpdateRouteRequest}
* @returns A Promise of Route
*/
updateRoute = (request: Readonly<UpdateRouteRequest>) =>
this.client.fetch<Route>(
{
body: JSON.stringify(
marshalUpdateRouteRequest(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'PATCH',
path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/routes/${validatePathParam('routeId', request.routeId)}`,
},
unmarshalRoute,
)

/**
* Delete a Route. Delete a Route specified by its Route ID.
*
* @param request - The request {@link DeleteRouteRequest}
*/
deleteRoute = (request: Readonly<DeleteRouteRequest>) =>
this.client.fetch<void>({
method: 'DELETE',
path: `/vpc/v2/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/routes/${validatePathParam('routeId', request.routeId)}`,
})
}
6 changes: 6 additions & 0 deletions packages/clients/src/api/vpc/v2/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@ export type {
AddSubnetsRequest,
AddSubnetsResponse,
CreatePrivateNetworkRequest,
CreateRouteRequest,
CreateVPCRequest,
DeletePrivateNetworkRequest,
DeleteRouteRequest,
DeleteSubnetsRequest,
DeleteSubnetsResponse,
DeleteVPCRequest,
EnableDHCPRequest,
EnableRoutingRequest,
GetPrivateNetworkRequest,
GetRouteRequest,
GetVPCRequest,
ListPrivateNetworksRequest,
ListPrivateNetworksRequestOrderBy,
Expand All @@ -25,10 +28,13 @@ export type {
ListVPCsResponse,
MigrateZonalPrivateNetworksRequest,
PrivateNetwork,
Route,
SetSubnetsRequest,
SetSubnetsResponse,
Subnet,
UpdatePrivateNetworkRequest,
UpdateRouteRequest,
UpdateVPCRequest,
VPC,
} from './types.gen'
export * as ValidationRules from './validation-rules.gen'
47 changes: 47 additions & 0 deletions packages/clients/src/api/vpc/v2/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type {
AddSubnetsRequest,
AddSubnetsResponse,
CreatePrivateNetworkRequest,
CreateRouteRequest,
CreateVPCRequest,
DeleteSubnetsRequest,
DeleteSubnetsResponse,
Expand All @@ -20,10 +21,12 @@ import type {
ListVPCsResponse,
MigrateZonalPrivateNetworksRequest,
PrivateNetwork,
Route,
SetSubnetsRequest,
SetSubnetsResponse,
Subnet,
UpdatePrivateNetworkRequest,
UpdateRouteRequest,
UpdateVPCRequest,
VPC,
} from './types.gen'
Expand Down Expand Up @@ -68,6 +71,27 @@ export const unmarshalPrivateNetwork = (data: unknown): PrivateNetwork => {
} as PrivateNetwork
}

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

return {
createdAt: unmarshalDate(data.created_at),
description: data.description,
destination: data.destination,
id: data.id,
nexthopPrivateNetworkId: data.nexthop_private_network_id,
nexthopResourceId: data.nexthop_resource_id,
region: data.region,
tags: data.tags,
updatedAt: unmarshalDate(data.updated_at),
vpcId: data.vpc_id,
} as Route
}

export const unmarshalVPC = (data: unknown): VPC => {
if (!isJSONObject(data)) {
throw new TypeError(
Expand Down Expand Up @@ -196,6 +220,18 @@ export const marshalCreatePrivateNetworkRequest = (
vpc_id: request.vpcId,
})

export const marshalCreateRouteRequest = (
request: CreateRouteRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
description: request.description,
destination: request.destination,
nexthop_private_network_id: request.nexthopPrivateNetworkId,
nexthop_resource_id: request.nexthopResourceId,
tags: request.tags,
vpc_id: request.vpcId,
})

export const marshalCreateVPCRequest = (
request: CreateVPCRequest,
defaults: DefaultValues,
Expand Down Expand Up @@ -247,6 +283,17 @@ export const marshalUpdatePrivateNetworkRequest = (
tags: request.tags,
})

export const marshalUpdateRouteRequest = (
request: UpdateRouteRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
description: request.description,
destination: request.destination,
nexthop_private_network_id: request.nexthopPrivateNetworkId,
nexthop_resource_id: request.nexthopResourceId,
tags: request.tags,
})

export const marshalUpdateVPCRequest = (
request: UpdateVPCRequest,
defaults: DefaultValues,
Expand Down
83 changes: 83 additions & 0 deletions packages/clients/src/api/vpc/v2/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,29 @@ export interface PrivateNetwork {
dhcpEnabled: boolean
}

export interface Route {
/** Route ID. */
id: string
/** Route description. */
description: string
/** Tags of the Route. */
tags: string[]
/** VPC the Route belongs to. */
vpcId: string
/** Destination of the Route. */
destination: string
/** ID of the nexthop resource. */
nexthopResourceId?: string
/** ID of the nexthop private network. */
nexthopPrivateNetworkId?: string
/** Date the Route was created. */
createdAt?: Date
/** Date the Route was last modified. */
updatedAt?: Date
/** Region of the Route. */
region: Region
}

export interface VPC {
/** VPC ID. */
id: string
Expand Down Expand Up @@ -117,6 +140,26 @@ export type CreatePrivateNetworkRequest = {
vpcId?: string
}

export type CreateRouteRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Route description. */
description: string
/** Tags of the Route. */
tags?: string[]
/** VPC the Route belongs to. */
vpcId: string
/** Destination of the Route. */
destination: string
/** ID of the nexthop resource. */
nexthopResourceId?: string
/** ID of the nexthop private network. */
nexthopPrivateNetworkId?: string
}

export type CreateVPCRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand All @@ -143,6 +186,16 @@ export type DeletePrivateNetworkRequest = {
privateNetworkId: string
}

export type DeleteRouteRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Route ID. */
routeId: string
}

export type DeleteSubnetsRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down Expand Up @@ -198,6 +251,16 @@ export type GetPrivateNetworkRequest = {
privateNetworkId: string
}

export type GetRouteRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Route ID. */
routeId: string
}

export type GetVPCRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down Expand Up @@ -403,6 +466,26 @@ export type UpdatePrivateNetworkRequest = {
tags?: string[]
}

export type UpdateRouteRequest = {
/**
* Region to target. If none is passed will use default region from the
* config.
*/
region?: Region
/** Route ID. */
routeId: string
/** Route description. */
description?: string
/** Tags of the Route. */
tags?: string[]
/** Destination of the Route. */
destination?: string
/** ID of the nexthop resource. */
nexthopResourceId?: string
/** ID of the nexthop private network. */
nexthopPrivateNetworkId?: string
}

export type UpdateVPCRequest = {
/**
* Region to target. If none is passed will use default region from the
Expand Down
8 changes: 8 additions & 0 deletions packages/clients/src/api/vpc/v2/validation-rules.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file was automatically generated. DO NOT EDIT.
// If you have any remark or suggestion do not hesitate to open an issue.

export const Route = {
description: {
maxLength: 200,
},
}

0 comments on commit fa10fb2

Please sign in to comment.