Skip to content

Commit 1cf1b8f

Browse files
authored
feat(webhosting): add public backup api (#2307)
1 parent 367ce21 commit 1cf1b8f

File tree

6 files changed

+491
-0
lines changed

6 files changed

+491
-0
lines changed

packages_generated/webhosting/src/v1/api.gen.ts

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import {
1111
waitForResource,
1212
} from '@scaleway/sdk-client'
1313
import {
14+
BACKUP_TRANSIENT_STATUSES as BACKUP_TRANSIENT_STATUSES_WEBHOSTING,
1415
DOMAIN_TRANSIENT_STATUSES as DOMAIN_TRANSIENT_STATUSES_WEBHOSTING,
1516
HOSTING_TRANSIENT_STATUSES as HOSTING_TRANSIENT_STATUSES_WEBHOSTING,
1617
} from './content.gen'
1718
import {
19+
marshalBackupApiRestoreBackupItemsRequest,
1820
marshalDatabaseApiAssignDatabaseUserRequest,
1921
marshalDatabaseApiChangeDatabaseUserPasswordRequest,
2022
marshalDatabaseApiCreateDatabaseRequest,
@@ -29,13 +31,16 @@ import {
2931
marshalMailAccountApiChangeMailAccountPasswordRequest,
3032
marshalMailAccountApiCreateMailAccountRequest,
3133
marshalMailAccountApiRemoveMailAccountRequest,
34+
unmarshalBackup,
3235
unmarshalCheckUserOwnsDomainResponse,
3336
unmarshalDatabase,
3437
unmarshalDatabaseUser,
3538
unmarshalDnsRecords,
3639
unmarshalDomain,
3740
unmarshalFtpAccount,
3841
unmarshalHosting,
42+
unmarshalListBackupItemsResponse,
43+
unmarshalListBackupsResponse,
3944
unmarshalListControlPanelsResponse,
4045
unmarshalListDatabasesResponse,
4146
unmarshalListDatabaseUsersResponse,
@@ -47,10 +52,18 @@ import {
4752
unmarshalMailAccount,
4853
unmarshalResetHostingPasswordResponse,
4954
unmarshalResourceSummary,
55+
unmarshalRestoreBackupItemsResponse,
56+
unmarshalRestoreBackupResponse,
5057
unmarshalSearchDomainsResponse,
5158
unmarshalSession,
5259
} from './marshalling.gen'
5360
import type {
61+
Backup,
62+
BackupApiGetBackupRequest,
63+
BackupApiListBackupItemsRequest,
64+
BackupApiListBackupsRequest,
65+
BackupApiRestoreBackupItemsRequest,
66+
BackupApiRestoreBackupRequest,
5467
CheckUserOwnsDomainResponse,
5568
ControlPanelApiListControlPanelsRequest,
5669
Database,
@@ -87,6 +100,8 @@ import type {
87100
HostingApiListHostingsRequest,
88101
HostingApiResetHostingPasswordRequest,
89102
HostingApiUpdateHostingRequest,
103+
ListBackupItemsResponse,
104+
ListBackupsResponse,
90105
ListControlPanelsResponse,
91106
ListDatabasesResponse,
92107
ListDatabaseUsersResponse,
@@ -103,6 +118,8 @@ import type {
103118
OfferApiListOffersRequest,
104119
ResetHostingPasswordResponse,
105120
ResourceSummary,
121+
RestoreBackupItemsResponse,
122+
RestoreBackupResponse,
106123
SearchDomainsResponse,
107124
Session,
108125
WebsiteApiListWebsitesRequest,
@@ -112,6 +129,143 @@ const jsonContentHeaders = {
112129
'Content-Type': 'application/json; charset=utf-8',
113130
}
114131

132+
/**
133+
* Web Hosting backup API.
134+
135+
This API allows you to list and restore backups for your cPanel and WordPress Web Hosting service.
136+
*/
137+
export class BackupAPI extends ParentAPI {
138+
/**
139+
* Locality of this API.
140+
* type ∈ {'zone','region','global','unspecified'}
141+
*/
142+
public static readonly LOCALITY: ApiLocality = toApiLocality({
143+
regions: ['fr-par', 'nl-ams', 'pl-waw'],
144+
})
145+
146+
protected pageOfListBackups = (
147+
request: Readonly<BackupApiListBackupsRequest>,
148+
) =>
149+
this.client.fetch<ListBackupsResponse>(
150+
{
151+
method: 'GET',
152+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backups`,
153+
urlParams: urlParams(
154+
['order_by', request.orderBy],
155+
['page', request.page],
156+
[
157+
'page_size',
158+
request.pageSize ?? this.client.settings.defaultPageSize,
159+
],
160+
),
161+
},
162+
unmarshalListBackupsResponse,
163+
)
164+
165+
/**
166+
* List all available backups for a hosting account.. List all available backups for a hosting account.
167+
*
168+
* @param request - The request {@link BackupApiListBackupsRequest}
169+
* @returns A Promise of ListBackupsResponse
170+
*/
171+
listBackups = (request: Readonly<BackupApiListBackupsRequest>) =>
172+
enrichForPagination('backups', this.pageOfListBackups, request)
173+
174+
/**
175+
* Get info about a backup specified by the backup ID.. Get info about a backup specified by the backup ID.
176+
*
177+
* @param request - The request {@link BackupApiGetBackupRequest}
178+
* @returns A Promise of Backup
179+
*/
180+
getBackup = (request: Readonly<BackupApiGetBackupRequest>) =>
181+
this.client.fetch<Backup>(
182+
{
183+
method: 'GET',
184+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backups/${validatePathParam('backupId', request.backupId)}`,
185+
},
186+
unmarshalBackup,
187+
)
188+
189+
/**
190+
* Waits for {@link Backup} to be in a final state.
191+
*
192+
* @param request - The request {@link BackupApiGetBackupRequest}
193+
* @param options - The waiting options
194+
* @returns A Promise of Backup
195+
*/
196+
waitForBackup = (
197+
request: Readonly<BackupApiGetBackupRequest>,
198+
options?: Readonly<WaitForOptions<Backup>>,
199+
) =>
200+
waitForResource(
201+
options?.stop ??
202+
(res =>
203+
Promise.resolve(
204+
!BACKUP_TRANSIENT_STATUSES_WEBHOSTING.includes(res.status),
205+
)),
206+
this.getBackup,
207+
request,
208+
options,
209+
)
210+
211+
/**
212+
* Restore an entire backup to your hosting environment.. Restore an entire backup to your hosting environment.
213+
*
214+
* @param request - The request {@link BackupApiRestoreBackupRequest}
215+
* @returns A Promise of RestoreBackupResponse
216+
*/
217+
restoreBackup = (request: Readonly<BackupApiRestoreBackupRequest>) =>
218+
this.client.fetch<RestoreBackupResponse>(
219+
{
220+
body: '{}',
221+
headers: jsonContentHeaders,
222+
method: 'POST',
223+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backups/${validatePathParam('backupId', request.backupId)}/restore`,
224+
},
225+
unmarshalRestoreBackupResponse,
226+
)
227+
228+
/**
229+
* List items within a specific backup, grouped by type.. List items within a specific backup, grouped by type.
230+
*
231+
* @param request - The request {@link BackupApiListBackupItemsRequest}
232+
* @returns A Promise of ListBackupItemsResponse
233+
*/
234+
listBackupItems = (request: Readonly<BackupApiListBackupItemsRequest>) =>
235+
this.client.fetch<ListBackupItemsResponse>(
236+
{
237+
method: 'GET',
238+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/backup-items`,
239+
urlParams: urlParams(['backup_id', request.backupId]),
240+
},
241+
unmarshalListBackupItemsResponse,
242+
)
243+
244+
/**
245+
* Restore specific items from a backup (e.g., a database or mailbox).. Restore specific items from a backup (e.g., a database or mailbox).
246+
*
247+
* @param request - The request {@link BackupApiRestoreBackupItemsRequest}
248+
* @returns A Promise of RestoreBackupItemsResponse
249+
*/
250+
restoreBackupItems = (
251+
request: Readonly<BackupApiRestoreBackupItemsRequest>,
252+
) =>
253+
this.client.fetch<RestoreBackupItemsResponse>(
254+
{
255+
body: JSON.stringify(
256+
marshalBackupApiRestoreBackupItemsRequest(
257+
request,
258+
this.client.settings,
259+
),
260+
),
261+
headers: jsonContentHeaders,
262+
method: 'POST',
263+
path: `/webhosting/v1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/hostings/${validatePathParam('hostingId', request.hostingId)}/restore-backup-items`,
264+
},
265+
unmarshalRestoreBackupItemsResponse,
266+
)
267+
}
268+
115269
/**
116270
* Web Hosting Control Panel API.
117271

packages_generated/webhosting/src/v1/content.gen.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33
import type {
4+
BackupStatus,
45
DomainAvailabilityStatus,
56
DomainStatus,
67
HostingStatus,
78
} from './types.gen'
89

10+
/** Lists transient statutes of the enum {@link BackupStatus}. */
11+
export const BACKUP_TRANSIENT_STATUSES: BackupStatus[] = ['restoring']
12+
913
/** Lists transient statutes of the enum {@link DomainAvailabilityStatus}. */
1014
export const DOMAIN_AVAILABILITY_TRANSIENT_STATUSES: DomainAvailabilityStatus[] =
1115
['validating']

packages_generated/webhosting/src/v1/index.gen.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// This file was automatically generated. DO NOT EDIT.
22
// If you have any remark or suggestion do not hesitate to open an issue.
33
export {
4+
BackupAPI,
45
ControlPanelAPI,
56
DatabaseAPI,
67
DnsAPI,
@@ -14,6 +15,16 @@ export * from './content.gen'
1415
export * from './marshalling.gen'
1516
export type {
1617
AutoConfigDomainDns,
18+
Backup,
19+
BackupApiGetBackupRequest,
20+
BackupApiListBackupItemsRequest,
21+
BackupApiListBackupsRequest,
22+
BackupApiRestoreBackupItemsRequest,
23+
BackupApiRestoreBackupRequest,
24+
BackupItem,
25+
BackupItemGroup,
26+
BackupItemType,
27+
BackupStatus,
1728
CheckUserOwnsDomainResponse,
1829
ControlPanel,
1930
ControlPanelApiListControlPanelsRequest,
@@ -69,6 +80,9 @@ export type {
6980
HostingStatus,
7081
HostingSummary,
7182
HostingUser,
83+
ListBackupItemsResponse,
84+
ListBackupsRequestOrderBy,
85+
ListBackupsResponse,
7286
ListControlPanelsResponse,
7387
ListDatabasesRequestOrderBy,
7488
ListDatabasesResponse,
@@ -103,6 +117,8 @@ export type {
103117
PlatformPlatformGroup,
104118
ResetHostingPasswordResponse,
105119
ResourceSummary,
120+
RestoreBackupItemsResponse,
121+
RestoreBackupResponse,
106122
SearchDomainsResponse,
107123
Session,
108124
SyncDomainDnsRecordsRequestRecord,

0 commit comments

Comments
 (0)