Skip to content

Commit 915f755

Browse files
scaleway-botyfodil
andauthored
feat(ipam): add v1 API (#938)
Co-authored-by: Yacine FODIL <[email protected]>
1 parent 8a1c1ee commit 915f755

File tree

7 files changed

+545
-0
lines changed

7 files changed

+545
-0
lines changed

packages/clients/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export * as Function from './function'
1212
export * as IAM from './iam'
1313
export * as Instance from './instance'
1414
export * as IOT from './iot'
15+
export * as IPAM from './ipam'
1516
export * as IPFS from './ipfs'
1617
export * as K8S from './k8s'
1718
export * as LB from './lb'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * as v1 from './v1/index.gen'
Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
API as ParentAPI,
5+
enrichForPagination,
6+
resolveOneOf,
7+
urlParams,
8+
validatePathParam,
9+
} from '../../../bridge'
10+
import type { Region } from '../../../bridge'
11+
import {
12+
marshalBookIPRequest,
13+
marshalUpdateIPRequest,
14+
unmarshalIP,
15+
unmarshalListIPsResponse,
16+
} from './marshalling.gen'
17+
import type {
18+
BookIPRequest,
19+
GetIPRequest,
20+
IP,
21+
ListIPsRequest,
22+
ListIPsResponse,
23+
ReleaseIPRequest,
24+
UpdateIPRequest,
25+
} from './types.gen'
26+
27+
const jsonContentHeaders = {
28+
'Content-Type': 'application/json; charset=utf-8',
29+
}
30+
31+
/**
32+
* IPAM API.
33+
*
34+
* This API allows you to manage IP addresses with Scaleway's IP Address
35+
* Management tool. IPAM API.
36+
*/
37+
export class API extends ParentAPI {
38+
/** Lists the available regions of the API. */
39+
public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw']
40+
41+
/**
42+
* Book a new IP. Book a new IP from the specified source. Currently IPs can
43+
* only be booked from a Private Network.
44+
*
45+
* @param request - The request {@link BookIPRequest}
46+
* @returns A Promise of IP
47+
*/
48+
bookIP = (request: Readonly<BookIPRequest>) =>
49+
this.client.fetch<IP>(
50+
{
51+
body: JSON.stringify(
52+
marshalBookIPRequest(request, this.client.settings),
53+
),
54+
headers: jsonContentHeaders,
55+
method: 'POST',
56+
path: `/ipam/v1/regions/${validatePathParam(
57+
'region',
58+
request.region ?? this.client.settings.defaultRegion,
59+
)}/ips`,
60+
},
61+
unmarshalIP,
62+
)
63+
64+
/**
65+
* Release an IP. Release an IP not currently attached to a resource, and
66+
* returns it to the available IP pool.
67+
*
68+
* @param request - The request {@link ReleaseIPRequest}
69+
*/
70+
releaseIP = (request: Readonly<ReleaseIPRequest>) =>
71+
this.client.fetch<void>({
72+
body: '{}',
73+
headers: jsonContentHeaders,
74+
method: 'DELETE',
75+
path: `/ipam/v1/regions/${validatePathParam(
76+
'region',
77+
request.region ?? this.client.settings.defaultRegion,
78+
)}/ips/${validatePathParam('ipId', request.ipId)}`,
79+
})
80+
81+
/**
82+
* Get an IP. Retrieve details of an existing IP, specified by its IP ID.
83+
*
84+
* @param request - The request {@link GetIPRequest}
85+
* @returns A Promise of IP
86+
*/
87+
getIP = (request: Readonly<GetIPRequest>) =>
88+
this.client.fetch<IP>(
89+
{
90+
method: 'GET',
91+
path: `/ipam/v1/regions/${validatePathParam(
92+
'region',
93+
request.region ?? this.client.settings.defaultRegion,
94+
)}/ips/${validatePathParam('ipId', request.ipId)}`,
95+
},
96+
unmarshalIP,
97+
)
98+
99+
/**
100+
* Update an IP. Update parameters including tags of the specified IP.
101+
*
102+
* @param request - The request {@link UpdateIPRequest}
103+
* @returns A Promise of IP
104+
*/
105+
updateIP = (request: Readonly<UpdateIPRequest>) =>
106+
this.client.fetch<IP>(
107+
{
108+
body: JSON.stringify(
109+
marshalUpdateIPRequest(request, this.client.settings),
110+
),
111+
headers: jsonContentHeaders,
112+
method: 'PATCH',
113+
path: `/ipam/v1/regions/${validatePathParam(
114+
'region',
115+
request.region ?? this.client.settings.defaultRegion,
116+
)}/ips/${validatePathParam('ipId', request.ipId)}`,
117+
},
118+
unmarshalIP,
119+
)
120+
121+
protected pageOfListIPs = (request: Readonly<ListIPsRequest> = {}) =>
122+
this.client.fetch<ListIPsResponse>(
123+
{
124+
method: 'GET',
125+
path: `/ipam/v1/regions/${validatePathParam(
126+
'region',
127+
request.region ?? this.client.settings.defaultRegion,
128+
)}/ips`,
129+
urlParams: urlParams(
130+
['attached', request.attached],
131+
['is_ipv6', request.isIpv6],
132+
['mac_address', request.macAddress],
133+
['order_by', request.orderBy ?? 'created_at_desc'],
134+
['organization_id', request.organizationId],
135+
['page', request.page],
136+
[
137+
'page_size',
138+
request.pageSize ?? this.client.settings.defaultPageSize,
139+
],
140+
['project_id', request.projectId],
141+
['resource_id', request.resourceId],
142+
['resource_name', request.resourceName],
143+
['resource_type', request.resourceType ?? 'unknown_type'],
144+
['tags', request.tags],
145+
...Object.entries(
146+
resolveOneOf([
147+
{
148+
param: 'zonal',
149+
value: request.zonal,
150+
},
151+
{
152+
param: 'private_network_id',
153+
value: request.privateNetworkId,
154+
},
155+
]),
156+
),
157+
),
158+
},
159+
unmarshalListIPsResponse,
160+
)
161+
162+
/**
163+
* List existing IPs. List existing IPs in the specified region using various
164+
* filters. For example, you can filter for IPs within a specified Private
165+
* Network, or for public IPs within a specified Project. By default, the IPs
166+
* returned in the list are ordered by creation date in ascending order,
167+
* though this can be modified via the order_by field.
168+
*
169+
* @param request - The request {@link ListIPsRequest}
170+
* @returns A Promise of ListIPsResponse
171+
*/
172+
listIPs = (request: Readonly<ListIPsRequest> = {}) =>
173+
enrichForPagination('ips', this.pageOfListIPs, request)
174+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
export { API } from './api.gen'
4+
export type {
5+
BookIPRequest,
6+
GetIPRequest,
7+
IP,
8+
ListIPsRequest,
9+
ListIPsRequestOrderBy,
10+
ListIPsResponse,
11+
ReleaseIPRequest,
12+
Resource,
13+
ResourceType,
14+
Source,
15+
UpdateIPRequest,
16+
} from './types.gen'
17+
export * as ValidationRules from './validation-rules.gen'
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
isJSONObject,
5+
resolveOneOf,
6+
unmarshalArrayOfObject,
7+
unmarshalDate,
8+
} from '../../../bridge'
9+
import type { DefaultValues } from '../../../bridge'
10+
import type {
11+
BookIPRequest,
12+
IP,
13+
ListIPsResponse,
14+
Resource,
15+
Source,
16+
UpdateIPRequest,
17+
} from './types.gen'
18+
19+
const unmarshalResource = (data: unknown) => {
20+
if (!isJSONObject(data)) {
21+
throw new TypeError(
22+
`Unmarshalling the type 'Resource' failed as data isn't a dictionary.`,
23+
)
24+
}
25+
26+
return {
27+
id: data.id,
28+
macAddress: data.mac_address,
29+
name: data.name,
30+
type: data.type,
31+
} as Resource
32+
}
33+
34+
const unmarshalSource = (data: unknown) => {
35+
if (!isJSONObject(data)) {
36+
throw new TypeError(
37+
`Unmarshalling the type 'Source' failed as data isn't a dictionary.`,
38+
)
39+
}
40+
41+
return {
42+
privateNetworkId: data.private_network_id,
43+
subnetId: data.subnet_id,
44+
zonal: data.zonal,
45+
} as Source
46+
}
47+
48+
export const unmarshalIP = (data: unknown) => {
49+
if (!isJSONObject(data)) {
50+
throw new TypeError(
51+
`Unmarshalling the type 'IP' failed as data isn't a dictionary.`,
52+
)
53+
}
54+
55+
return {
56+
address: data.address,
57+
createdAt: unmarshalDate(data.created_at),
58+
id: data.id,
59+
isIpv6: data.is_ipv6,
60+
projectId: data.project_id,
61+
region: data.region,
62+
resource: data.resource ? unmarshalResource(data.resource) : undefined,
63+
source: data.source ? unmarshalSource(data.source) : undefined,
64+
tags: data.tags,
65+
updatedAt: unmarshalDate(data.updated_at),
66+
zone: data.zone,
67+
} as IP
68+
}
69+
70+
export const unmarshalListIPsResponse = (data: unknown) => {
71+
if (!isJSONObject(data)) {
72+
throw new TypeError(
73+
`Unmarshalling the type 'ListIPsResponse' failed as data isn't a dictionary.`,
74+
)
75+
}
76+
77+
return {
78+
ips: unmarshalArrayOfObject(data.ips, unmarshalIP),
79+
totalCount: data.total_count,
80+
} as ListIPsResponse
81+
}
82+
83+
const marshalSource = (
84+
request: Source,
85+
defaults: DefaultValues,
86+
): Record<string, unknown> => ({
87+
...resolveOneOf([
88+
{
89+
param: 'zonal',
90+
value: request.zonal,
91+
},
92+
{
93+
param: 'private_network_id',
94+
value: request.privateNetworkId,
95+
},
96+
{
97+
param: 'subnet_id',
98+
value: request.subnetId,
99+
},
100+
]),
101+
})
102+
103+
export const marshalBookIPRequest = (
104+
request: BookIPRequest,
105+
defaults: DefaultValues,
106+
): Record<string, unknown> => ({
107+
address: request.address,
108+
is_ipv6: request.isIpv6,
109+
project_id: request.projectId ?? defaults.defaultProjectId,
110+
source: request.source ? marshalSource(request.source, defaults) : undefined,
111+
tags: request.tags,
112+
})
113+
114+
export const marshalUpdateIPRequest = (
115+
request: UpdateIPRequest,
116+
defaults: DefaultValues,
117+
): Record<string, unknown> => ({
118+
tags: request.tags,
119+
})

0 commit comments

Comments
 (0)