@@ -11,10 +11,12 @@ import {
11
11
waitForResource ,
12
12
} from '@scaleway/sdk-client'
13
13
import {
14
+ BACKUP_TRANSIENT_STATUSES as BACKUP_TRANSIENT_STATUSES_WEBHOSTING ,
14
15
DOMAIN_TRANSIENT_STATUSES as DOMAIN_TRANSIENT_STATUSES_WEBHOSTING ,
15
16
HOSTING_TRANSIENT_STATUSES as HOSTING_TRANSIENT_STATUSES_WEBHOSTING ,
16
17
} from './content.gen'
17
18
import {
19
+ marshalBackupApiRestoreBackupItemsRequest ,
18
20
marshalDatabaseApiAssignDatabaseUserRequest ,
19
21
marshalDatabaseApiChangeDatabaseUserPasswordRequest ,
20
22
marshalDatabaseApiCreateDatabaseRequest ,
@@ -29,13 +31,16 @@ import {
29
31
marshalMailAccountApiChangeMailAccountPasswordRequest ,
30
32
marshalMailAccountApiCreateMailAccountRequest ,
31
33
marshalMailAccountApiRemoveMailAccountRequest ,
34
+ unmarshalBackup ,
32
35
unmarshalCheckUserOwnsDomainResponse ,
33
36
unmarshalDatabase ,
34
37
unmarshalDatabaseUser ,
35
38
unmarshalDnsRecords ,
36
39
unmarshalDomain ,
37
40
unmarshalFtpAccount ,
38
41
unmarshalHosting ,
42
+ unmarshalListBackupItemsResponse ,
43
+ unmarshalListBackupsResponse ,
39
44
unmarshalListControlPanelsResponse ,
40
45
unmarshalListDatabasesResponse ,
41
46
unmarshalListDatabaseUsersResponse ,
@@ -47,10 +52,18 @@ import {
47
52
unmarshalMailAccount ,
48
53
unmarshalResetHostingPasswordResponse ,
49
54
unmarshalResourceSummary ,
55
+ unmarshalRestoreBackupItemsResponse ,
56
+ unmarshalRestoreBackupResponse ,
50
57
unmarshalSearchDomainsResponse ,
51
58
unmarshalSession ,
52
59
} from './marshalling.gen'
53
60
import type {
61
+ Backup ,
62
+ BackupApiGetBackupRequest ,
63
+ BackupApiListBackupItemsRequest ,
64
+ BackupApiListBackupsRequest ,
65
+ BackupApiRestoreBackupItemsRequest ,
66
+ BackupApiRestoreBackupRequest ,
54
67
CheckUserOwnsDomainResponse ,
55
68
ControlPanelApiListControlPanelsRequest ,
56
69
Database ,
@@ -87,6 +100,8 @@ import type {
87
100
HostingApiListHostingsRequest ,
88
101
HostingApiResetHostingPasswordRequest ,
89
102
HostingApiUpdateHostingRequest ,
103
+ ListBackupItemsResponse ,
104
+ ListBackupsResponse ,
90
105
ListControlPanelsResponse ,
91
106
ListDatabasesResponse ,
92
107
ListDatabaseUsersResponse ,
@@ -103,6 +118,8 @@ import type {
103
118
OfferApiListOffersRequest ,
104
119
ResetHostingPasswordResponse ,
105
120
ResourceSummary ,
121
+ RestoreBackupItemsResponse ,
122
+ RestoreBackupResponse ,
106
123
SearchDomainsResponse ,
107
124
Session ,
108
125
WebsiteApiListWebsitesRequest ,
@@ -112,6 +129,143 @@ const jsonContentHeaders = {
112
129
'Content-Type' : 'application/json; charset=utf-8' ,
113
130
}
114
131
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
+
115
269
/**
116
270
* Web Hosting Control Panel API.
117
271
0 commit comments