From 219dd92c8fb52d66b499f5bae446c821c637be26 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Fri, 29 Jul 2022 07:44:55 +0000 Subject: [PATCH] feat: update generated APIs --- packages/clients/src/api/rdb/v1/api.gen.ts | 126 ++++++++++++++++ .../clients/src/api/rdb/v1/marshalling.gen.ts | 135 ++++++++++++++---- packages/clients/src/api/rdb/v1/types.gen.ts | 82 +++++++++++ 3 files changed, 318 insertions(+), 25 deletions(-) diff --git a/packages/clients/src/api/rdb/v1/api.gen.ts b/packages/clients/src/api/rdb/v1/api.gen.ts index 375d0e466..da60de76d 100644 --- a/packages/clients/src/api/rdb/v1/api.gen.ts +++ b/packages/clients/src/api/rdb/v1/api.gen.ts @@ -23,6 +23,8 @@ import { marshalCreateEndpointRequest, marshalCreateInstanceFromSnapshotRequest, marshalCreateInstanceRequest, + marshalCreateReadReplicaEndpointRequest, + marshalCreateReadReplicaRequest, marshalCreateSnapshotRequest, marshalCreateUserRequest, marshalDeleteInstanceACLRulesRequest, @@ -61,6 +63,7 @@ import { unmarshalListUsersResponse, unmarshalPrepareInstanceLogsResponse, unmarshalPrivilege, + unmarshalReadReplica, unmarshalSetInstanceACLRulesResponse, unmarshalSetInstanceSettingsResponse, unmarshalSnapshot, @@ -77,6 +80,8 @@ import type { CreateEndpointRequest, CreateInstanceFromSnapshotRequest, CreateInstanceRequest, + CreateReadReplicaEndpointRequest, + CreateReadReplicaRequest, CreateSnapshotRequest, CreateUserRequest, Database, @@ -89,6 +94,7 @@ import type { DeleteInstanceRequest, DeleteInstanceSettingsRequest, DeleteInstanceSettingsResponse, + DeleteReadReplicaRequest, DeleteSnapshotRequest, DeleteUserRequest, Endpoint, @@ -99,6 +105,7 @@ import type { GetInstanceLogRequest, GetInstanceMetricsRequest, GetInstanceRequest, + GetReadReplicaRequest, GetSnapshotRequest, Instance, InstanceLog, @@ -129,7 +136,9 @@ import type { PrepareInstanceLogsResponse, Privilege, PurgeInstanceLogsRequest, + ReadReplica, RenewInstanceCertificateRequest, + ResetReadReplicaRequest, RestartInstanceRequest, RestoreDatabaseBackupRequest, SetInstanceACLRulesRequest, @@ -703,6 +712,123 @@ export class RdbV1GenAPI extends API { unmarshalInstanceMetrics, ) + /** + * Create a read replica + * + * @param request - The request {@link CreateReadReplicaRequest} + * @returns A Promise of ReadReplica + */ + createReadReplica = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateReadReplicaRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/rdb/v1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/read-replicas`, + }, + unmarshalReadReplica, + ) + + /** + * Get a read replica + * + * @param request - The request {@link GetReadReplicaRequest} + * @returns A Promise of ReadReplica + */ + getReadReplica = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/rdb/v1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/read-replicas/${validatePathParam( + 'readReplicaId', + request.readReplicaId, + )}`, + }, + unmarshalReadReplica, + ) + + /** + * Delete a read replica + * + * @param request - The request {@link DeleteReadReplicaRequest} + * @returns A Promise of ReadReplica + */ + deleteReadReplica = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/rdb/v1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/read-replicas/${validatePathParam( + 'readReplicaId', + request.readReplicaId, + )}`, + }, + unmarshalReadReplica, + ) + + /** + * Reset a read replica + * + * @param request - The request {@link ResetReadReplicaRequest} + * @returns A Promise of ReadReplica + */ + resetReadReplica = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/rdb/v1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/read-replicas/${validatePathParam( + 'readReplicaId', + request.readReplicaId, + )}/reset`, + }, + unmarshalReadReplica, + ) + + /** + * Create a new endpoint for a given read replica + * + * @param request - The request {@link CreateReadReplicaEndpointRequest} + * @returns A Promise of ReadReplica + */ + createReadReplicaEndpoint = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateReadReplicaEndpointRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/rdb/v1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/read-replicas/${validatePathParam( + 'readReplicaId', + request.readReplicaId, + )}/endpoints`, + }, + unmarshalReadReplica, + ) + /** * Prepare your instance logs. Logs will be grouped on a minimum interval of a day. * diff --git a/packages/clients/src/api/rdb/v1/marshalling.gen.ts b/packages/clients/src/api/rdb/v1/marshalling.gen.ts index 8b2046f57..3022987a8 100644 --- a/packages/clients/src/api/rdb/v1/marshalling.gen.ts +++ b/packages/clients/src/api/rdb/v1/marshalling.gen.ts @@ -23,6 +23,8 @@ import type { CreateEndpointRequest, CreateInstanceFromSnapshotRequest, CreateInstanceRequest, + CreateReadReplicaEndpointRequest, + CreateReadReplicaRequest, CreateSnapshotRequest, CreateUserRequest, Database, @@ -66,6 +68,10 @@ import type { PrepareInstanceLogsResponse, Privilege, PurgeInstanceLogsRequest, + ReadReplica, + ReadReplicaEndpointSpec, + ReadReplicaEndpointSpecDirectAccess, + ReadReplicaEndpointSpecPrivateNetwork, RestoreDatabaseBackupRequest, SetInstanceACLRulesRequest, SetInstanceACLRulesResponse, @@ -116,6 +122,31 @@ const unmarshalEndpointPrivateNetworkDetails = (data: unknown) => { } as EndpointPrivateNetworkDetails } +export const unmarshalEndpoint = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Endpoint' failed as data isn't a dictionary.`, + ) + } + + return { + directAccess: data.direct_access + ? unmarshalEndpointDirectAccessDetails(data.direct_access) + : undefined, + hostname: data.hostname, + id: data.id, + ip: data.ip, + loadBalancer: data.load_balancer + ? unmarshalEndpointLoadBalancerDetails(data.load_balancer) + : undefined, + name: data.name, + port: data.port, + privateNetwork: data.private_network + ? unmarshalEndpointPrivateNetworkDetails(data.private_network) + : undefined, + } as Endpoint +} + const unmarshalEngineSetting = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -152,31 +183,6 @@ const unmarshalBackupSchedule = (data: unknown) => { } as BackupSchedule } -export const unmarshalEndpoint = (data: unknown) => { - if (!isJSONObject(data)) { - throw new TypeError( - `Unmarshalling the type 'Endpoint' failed as data isn't a dictionary.`, - ) - } - - return { - directAccess: data.direct_access - ? unmarshalEndpointDirectAccessDetails(data.direct_access) - : undefined, - hostname: data.hostname, - id: data.id, - ip: data.ip, - loadBalancer: data.load_balancer - ? unmarshalEndpointLoadBalancerDetails(data.load_balancer) - : undefined, - name: data.name, - port: data.port, - privateNetwork: data.private_network - ? unmarshalEndpointPrivateNetworkDetails(data.private_network) - : undefined, - } as Endpoint -} - const unmarshalEngineVersion = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -269,6 +275,21 @@ const unmarshalNodeTypeVolumeType = (data: unknown) => { } as NodeTypeVolumeType } +export const unmarshalReadReplica = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ReadReplica' failed as data isn't a dictionary.`, + ) + } + + return { + endpoints: unmarshalArrayOfObject(data.endpoints, unmarshalEndpoint), + id: data.id, + region: data.region, + status: data.status, + } as ReadReplica +} + const unmarshalVolume = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -384,6 +405,10 @@ export const unmarshalInstance = (data: unknown) => { nodeType: data.node_type, organizationId: data.organization_id, projectId: data.project_id, + readReplicas: unmarshalArrayOfObject( + data.read_replicas, + unmarshalReadReplica, + ), region: data.region, settings: unmarshalArrayOfObject(data.settings, unmarshalInstanceSetting), status: data.status, @@ -760,6 +785,19 @@ const marshalEndpointSpecPrivateNetwork = ( service_ip: request.serviceIp, }) +const marshalReadReplicaEndpointSpecDirectAccess = ( + request: ReadReplicaEndpointSpecDirectAccess, + defaults: DefaultValues, +): Record => ({}) + +const marshalReadReplicaEndpointSpecPrivateNetwork = ( + request: ReadReplicaEndpointSpecPrivateNetwork, + defaults: DefaultValues, +): Record => ({ + private_network_id: request.privateNetworkId, + service_ip: request.serviceIp, +}) + const marshalACLRuleRequest = ( request: ACLRuleRequest, defaults: DefaultValues, @@ -804,6 +842,32 @@ const marshalLogsPolicy = ( total_disk_retention: request.totalDiskRetention, }) +const marshalReadReplicaEndpointSpec = ( + request: ReadReplicaEndpointSpec, + defaults: DefaultValues, +): Record => ({ + ...resolveOneOf([ + { + param: 'direct_access', + value: request.directAccess + ? marshalReadReplicaEndpointSpecDirectAccess( + request.directAccess, + defaults, + ) + : undefined, + }, + { + param: 'private_network', + value: request.privateNetwork + ? marshalReadReplicaEndpointSpecPrivateNetwork( + request.privateNetwork, + defaults, + ) + : undefined, + }, + ]), +}) + export const marshalAddInstanceACLRulesRequest = ( request: AddInstanceACLRulesRequest, defaults: DefaultValues, @@ -896,6 +960,27 @@ export const marshalCreateInstanceRequest = ( ]), }) +export const marshalCreateReadReplicaEndpointRequest = ( + request: CreateReadReplicaEndpointRequest, + defaults: DefaultValues, +): Record => ({ + endpoint_spec: request.endpointSpec.map(elt => + marshalReadReplicaEndpointSpec(elt, defaults), + ), +}) + +export const marshalCreateReadReplicaRequest = ( + request: CreateReadReplicaRequest, + defaults: DefaultValues, +): Record => ({ + endpoint_spec: request.endpointSpec + ? request.endpointSpec.map(elt => + marshalReadReplicaEndpointSpec(elt, defaults), + ) + : undefined, + instance_id: request.instanceId, +}) + export const marshalCreateSnapshotRequest = ( request: CreateSnapshotRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/rdb/v1/types.gen.ts b/packages/clients/src/api/rdb/v1/types.gen.ts index b7b8ff902..d7fd3bd1e 100644 --- a/packages/clients/src/api/rdb/v1/types.gen.ts +++ b/packages/clients/src/api/rdb/v1/types.gen.ts @@ -376,6 +376,8 @@ export interface Instance { backupSchedule?: BackupSchedule /** Whether or not High-Availability is enabled */ isHaCluster: boolean + /** Read replicas of the instance */ + readReplicas: Array /** Node type of the instance */ nodeType: string /** List of engine settings to be set at database initialisation */ @@ -594,6 +596,47 @@ export interface Privilege { userName: string } +/** Read replica */ +export interface ReadReplica { + /** UUID of the read replica */ + id: string + /** Display read replica connection information */ + endpoints: Array + /** Read replica status */ + status: ReadReplicaStatus + /** Region the read replica is in */ + region: Region +} + +/** Read replica endpoint spec */ +export interface ReadReplicaEndpointSpec { + /** + * Direct access endpoint specifications. + * + * One-of ('spec'): at most one of 'directAccess', 'privateNetwork' could be set. + */ + directAccess?: ReadReplicaEndpointSpecDirectAccess + /** + * Private network endpoint specifications. + * + * One-of ('spec'): at most one of 'directAccess', 'privateNetwork' could be set. + */ + privateNetwork?: ReadReplicaEndpointSpecPrivateNetwork +} + +export interface ReadReplicaEndpointSpecDirectAccess {} + +/** Read replica endpoint spec. private network */ +export interface ReadReplicaEndpointSpecPrivateNetwork { + /** UUID of the private network to be connected to the read replica */ + privateNetworkId: string + /** + * Endpoint IPv4 adress with a CIDR notation. Check documentation about IP and + * subnet limitations. + */ + serviceIp: string +} + /** Set instance acl rules response */ export interface SetInstanceACLRulesResponse { /** ACLs rules configured for an instance */ @@ -918,6 +961,45 @@ export type GetInstanceMetricsRequest = { metricName?: string } +export type CreateReadReplicaRequest = { + /** Region to target. If none is passed will use default region from the config */ + region?: Region + /** UUID of the instance you want a read replica of */ + instanceId: string + /** Specification of the endpoint you want to create */ + endpointSpec?: Array +} + +export type GetReadReplicaRequest = { + /** Region to target. If none is passed will use default region from the config */ + region?: Region + /** UUID of the read replica */ + readReplicaId: string +} + +export type DeleteReadReplicaRequest = { + /** Region to target. If none is passed will use default region from the config */ + region?: Region + /** UUID of the read replica */ + readReplicaId: string +} + +export type ResetReadReplicaRequest = { + /** Region to target. If none is passed will use default region from the config */ + region?: Region + /** UUID of the read replica */ + readReplicaId: string +} + +export type CreateReadReplicaEndpointRequest = { + /** Region to target. If none is passed will use default region from the config */ + region?: Region + /** UUID of the read replica */ + readReplicaId: string + /** Specification of the endpoint you want to create */ + endpointSpec: Array +} + export type PrepareInstanceLogsRequest = { /** Region to target. If none is passed will use default region from the config */ region?: Region