Skip to content

Commit

Permalink
feat(block): add snapshot import (scaleway#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
scaleway-bot authored Oct 11, 2023
1 parent 0f09608 commit 3d74e31
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/clients/src/api/block/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
import {
marshalCreateSnapshotRequest,
marshalCreateVolumeRequest,
marshalImportSnapshotFromS3Request,
marshalUpdateSnapshotRequest,
marshalUpdateVolumeRequest,
unmarshalListSnapshotsResponse,
Expand All @@ -30,6 +31,7 @@ import type {
DeleteVolumeRequest,
GetSnapshotRequest,
GetVolumeRequest,
ImportSnapshotFromS3Request,
ListSnapshotsRequest,
ListSnapshotsResponse,
ListVolumeTypesRequest,
Expand Down Expand Up @@ -327,6 +329,22 @@ export class API extends ParentAPI {
unmarshalSnapshot,
)

importSnapshotFromS3 = (request: Readonly<ImportSnapshotFromS3Request>) =>
this.client.fetch<Snapshot>(
{
body: JSON.stringify(
marshalImportSnapshotFromS3Request(request, this.client.settings),
),
headers: jsonContentHeaders,
method: 'POST',
path: `/block/v1alpha1/zones/${validatePathParam(
'zone',
request.zone ?? this.client.settings.defaultZone,
)}/snapshots/import-from-s3`,
},
unmarshalSnapshot,
)

/**
* Delete a snapshot. You must specify the `snapshot_id` of the snapshot you
* want to delete. The snapshot must not be in use.
Expand Down
1 change: 1 addition & 0 deletions packages/clients/src/api/block/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type {
DeleteVolumeRequest,
GetSnapshotRequest,
GetVolumeRequest,
ImportSnapshotFromS3Request,
ListSnapshotsRequest,
ListSnapshotsRequestOrderBy,
ListSnapshotsResponse,
Expand Down
12 changes: 12 additions & 0 deletions packages/clients/src/api/block/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type {
CreateVolumeRequest,
CreateVolumeRequestFromEmpty,
CreateVolumeRequestFromSnapshot,
ImportSnapshotFromS3Request,
ListSnapshotsResponse,
ListVolumeTypesResponse,
ListVolumesResponse,
Expand Down Expand Up @@ -255,6 +256,17 @@ export const marshalCreateVolumeRequest = (
),
})

export const marshalImportSnapshotFromS3Request = (
request: ImportSnapshotFromS3Request,
defaults: DefaultValues,
): Record<string, unknown> => ({
bucket: request.bucket,
key: request.key,
name: request.name,
project_id: request.projectId ?? defaults.defaultProjectId,
tags: request.tags,
})

export const marshalUpdateSnapshotRequest = (
request: UpdateSnapshotRequest,
defaults: DefaultValues,
Expand Down
10 changes: 10 additions & 0 deletions packages/clients/src/api/block/v1alpha1/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ export type CreateSnapshotRequest = {
tags?: string[]
}

export type ImportSnapshotFromS3Request = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
bucket: string
key: string
name: string
projectId?: string
tags?: string[]
}

export type DeleteSnapshotRequest = {
/** Zone to target. If none is passed will use default zone from the config. */
zone?: Zone
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ export const CreateVolumeRequest = {
},
}

export const ImportSnapshotFromS3Request = {
name: {
minLength: 1,
},
}

export const ListSnapshotsRequest = {
page: {
greaterThan: 0,
Expand Down

0 comments on commit 3d74e31

Please sign in to comment.