|
| 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 | +} |
0 commit comments