|
| 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 | + urlParams, |
| 7 | + validatePathParam, |
| 8 | +} from '../../../bridge' |
| 9 | +import type { Region } from '../../../bridge' |
| 10 | +import { |
| 11 | + marshalCreateSecretRequest, |
| 12 | + marshalCreateSecretVersionRequest, |
| 13 | + marshalUpdateSecretRequest, |
| 14 | + marshalUpdateSecretVersionRequest, |
| 15 | + unmarshalAccessSecretVersionResponse, |
| 16 | + unmarshalListSecretVersionsResponse, |
| 17 | + unmarshalListSecretsResponse, |
| 18 | + unmarshalSecret, |
| 19 | + unmarshalSecretVersion, |
| 20 | +} from './marshalling.gen' |
| 21 | +import type { |
| 22 | + AccessSecretVersionRequest, |
| 23 | + AccessSecretVersionResponse, |
| 24 | + CreateSecretRequest, |
| 25 | + CreateSecretVersionRequest, |
| 26 | + DeleteSecretRequest, |
| 27 | + DestroySecretVersionRequest, |
| 28 | + DisableSecretVersionRequest, |
| 29 | + EnableSecretVersionRequest, |
| 30 | + GetSecretRequest, |
| 31 | + GetSecretVersionRequest, |
| 32 | + ListSecretVersionsRequest, |
| 33 | + ListSecretVersionsResponse, |
| 34 | + ListSecretsRequest, |
| 35 | + ListSecretsResponse, |
| 36 | + Secret, |
| 37 | + SecretVersion, |
| 38 | + UpdateSecretRequest, |
| 39 | + UpdateSecretVersionRequest, |
| 40 | +} from './types.gen' |
| 41 | + |
| 42 | +const jsonContentHeaders = { |
| 43 | + 'Content-Type': 'application/json; charset=utf-8', |
| 44 | +} |
| 45 | + |
| 46 | +/** |
| 47 | + * Secret API (beta). |
| 48 | + * |
| 49 | + * This API allows you to conveniently store, access and share sensitive data. |
| 50 | + */ |
| 51 | +export class API extends ParentAPI { |
| 52 | + /** Lists the available regions of the API. */ |
| 53 | + public static readonly LOCALITIES: Region[] = ['fr-par'] |
| 54 | + |
| 55 | + /** |
| 56 | + * Create a Secret containing no versions |
| 57 | + * |
| 58 | + * @param request - The request {@link CreateSecretRequest} |
| 59 | + * @returns A Promise of Secret |
| 60 | + */ |
| 61 | + createSecret = (request: Readonly<CreateSecretRequest>) => |
| 62 | + this.client.fetch<Secret>( |
| 63 | + { |
| 64 | + body: JSON.stringify( |
| 65 | + marshalCreateSecretRequest(request, this.client.settings), |
| 66 | + ), |
| 67 | + headers: jsonContentHeaders, |
| 68 | + method: 'POST', |
| 69 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 70 | + 'region', |
| 71 | + request.region ?? this.client.settings.defaultRegion, |
| 72 | + )}/secrets`, |
| 73 | + }, |
| 74 | + unmarshalSecret, |
| 75 | + ) |
| 76 | + |
| 77 | + /** |
| 78 | + * Get metadata of a Secret |
| 79 | + * |
| 80 | + * @param request - The request {@link GetSecretRequest} |
| 81 | + * @returns A Promise of Secret |
| 82 | + */ |
| 83 | + getSecret = (request: Readonly<GetSecretRequest>) => |
| 84 | + this.client.fetch<Secret>( |
| 85 | + { |
| 86 | + method: 'GET', |
| 87 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 88 | + 'region', |
| 89 | + request.region ?? this.client.settings.defaultRegion, |
| 90 | + )}/secrets/${validatePathParam('secretId', request.secretId)}`, |
| 91 | + }, |
| 92 | + unmarshalSecret, |
| 93 | + ) |
| 94 | + |
| 95 | + /** |
| 96 | + * Update metadata of a Secret |
| 97 | + * |
| 98 | + * @param request - The request {@link UpdateSecretRequest} |
| 99 | + * @returns A Promise of Secret |
| 100 | + */ |
| 101 | + updateSecret = (request: Readonly<UpdateSecretRequest>) => |
| 102 | + this.client.fetch<Secret>( |
| 103 | + { |
| 104 | + body: JSON.stringify( |
| 105 | + marshalUpdateSecretRequest(request, this.client.settings), |
| 106 | + ), |
| 107 | + headers: jsonContentHeaders, |
| 108 | + method: 'PATCH', |
| 109 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 110 | + 'region', |
| 111 | + request.region ?? this.client.settings.defaultRegion, |
| 112 | + )}/secrets/${validatePathParam('secretId', request.secretId)}`, |
| 113 | + }, |
| 114 | + unmarshalSecret, |
| 115 | + ) |
| 116 | + |
| 117 | + protected pageOfListSecrets = (request: Readonly<ListSecretsRequest> = {}) => |
| 118 | + this.client.fetch<ListSecretsResponse>( |
| 119 | + { |
| 120 | + method: 'GET', |
| 121 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 122 | + 'region', |
| 123 | + request.region ?? this.client.settings.defaultRegion, |
| 124 | + )}/secrets`, |
| 125 | + urlParams: urlParams( |
| 126 | + ['order_by', request.orderBy ?? 'name_asc'], |
| 127 | + [ |
| 128 | + 'organization_id', |
| 129 | + request.organizationId ?? |
| 130 | + this.client.settings.defaultOrganizationId, |
| 131 | + ], |
| 132 | + ['page', request.page], |
| 133 | + [ |
| 134 | + 'page_size', |
| 135 | + request.pageSize ?? this.client.settings.defaultPageSize, |
| 136 | + ], |
| 137 | + [ |
| 138 | + 'project_id', |
| 139 | + request.projectId ?? this.client.settings.defaultProjectId, |
| 140 | + ], |
| 141 | + ['tags', request.tags], |
| 142 | + ), |
| 143 | + }, |
| 144 | + unmarshalListSecretsResponse, |
| 145 | + ) |
| 146 | + |
| 147 | + /** |
| 148 | + * List Secrets |
| 149 | + * |
| 150 | + * @param request - The request {@link ListSecretsRequest} |
| 151 | + * @returns A Promise of ListSecretsResponse |
| 152 | + */ |
| 153 | + listSecrets = (request: Readonly<ListSecretsRequest> = {}) => |
| 154 | + enrichForPagination('secrets', this.pageOfListSecrets, request) |
| 155 | + |
| 156 | + /** |
| 157 | + * Delete a secret |
| 158 | + * |
| 159 | + * @param request - The request {@link DeleteSecretRequest} |
| 160 | + */ |
| 161 | + deleteSecret = (request: Readonly<DeleteSecretRequest>) => |
| 162 | + this.client.fetch<void>({ |
| 163 | + method: 'DELETE', |
| 164 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 165 | + 'region', |
| 166 | + request.region ?? this.client.settings.defaultRegion, |
| 167 | + )}/secrets/${validatePathParam('secretId', request.secretId)}`, |
| 168 | + }) |
| 169 | + |
| 170 | + /** |
| 171 | + * Create a SecretVersion |
| 172 | + * |
| 173 | + * @param request - The request {@link CreateSecretVersionRequest} |
| 174 | + * @returns A Promise of SecretVersion |
| 175 | + */ |
| 176 | + createSecretVersion = (request: Readonly<CreateSecretVersionRequest>) => |
| 177 | + this.client.fetch<SecretVersion>( |
| 178 | + { |
| 179 | + body: JSON.stringify( |
| 180 | + marshalCreateSecretVersionRequest(request, this.client.settings), |
| 181 | + ), |
| 182 | + headers: jsonContentHeaders, |
| 183 | + method: 'POST', |
| 184 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 185 | + 'region', |
| 186 | + request.region ?? this.client.settings.defaultRegion, |
| 187 | + )}/secrets/${validatePathParam('secretId', request.secretId)}/versions`, |
| 188 | + }, |
| 189 | + unmarshalSecretVersion, |
| 190 | + ) |
| 191 | + |
| 192 | + /** |
| 193 | + * Get metadata of a SecretVersion |
| 194 | + * |
| 195 | + * @param request - The request {@link GetSecretVersionRequest} |
| 196 | + * @returns A Promise of SecretVersion |
| 197 | + */ |
| 198 | + getSecretVersion = (request: Readonly<GetSecretVersionRequest>) => |
| 199 | + this.client.fetch<SecretVersion>( |
| 200 | + { |
| 201 | + method: 'GET', |
| 202 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 203 | + 'region', |
| 204 | + request.region ?? this.client.settings.defaultRegion, |
| 205 | + )}/secrets/${validatePathParam( |
| 206 | + 'secretId', |
| 207 | + request.secretId, |
| 208 | + )}/versions/${validatePathParam('revision', request.revision)}`, |
| 209 | + }, |
| 210 | + unmarshalSecretVersion, |
| 211 | + ) |
| 212 | + |
| 213 | + /** |
| 214 | + * Update metadata of a SecretVersion |
| 215 | + * |
| 216 | + * @param request - The request {@link UpdateSecretVersionRequest} |
| 217 | + * @returns A Promise of SecretVersion |
| 218 | + */ |
| 219 | + updateSecretVersion = (request: Readonly<UpdateSecretVersionRequest>) => |
| 220 | + this.client.fetch<SecretVersion>( |
| 221 | + { |
| 222 | + body: JSON.stringify( |
| 223 | + marshalUpdateSecretVersionRequest(request, this.client.settings), |
| 224 | + ), |
| 225 | + headers: jsonContentHeaders, |
| 226 | + method: 'PATCH', |
| 227 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 228 | + 'region', |
| 229 | + request.region ?? this.client.settings.defaultRegion, |
| 230 | + )}/secrets/${validatePathParam( |
| 231 | + 'secretId', |
| 232 | + request.secretId, |
| 233 | + )}/versions/${validatePathParam('revision', request.revision)}`, |
| 234 | + }, |
| 235 | + unmarshalSecretVersion, |
| 236 | + ) |
| 237 | + |
| 238 | + protected pageOfListSecretVersions = ( |
| 239 | + request: Readonly<ListSecretVersionsRequest>, |
| 240 | + ) => |
| 241 | + this.client.fetch<ListSecretVersionsResponse>( |
| 242 | + { |
| 243 | + method: 'GET', |
| 244 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 245 | + 'region', |
| 246 | + request.region ?? this.client.settings.defaultRegion, |
| 247 | + )}/secrets/${validatePathParam('secretId', request.secretId)}/versions`, |
| 248 | + urlParams: urlParams( |
| 249 | + ['page', request.page], |
| 250 | + [ |
| 251 | + 'page_size', |
| 252 | + request.pageSize ?? this.client.settings.defaultPageSize, |
| 253 | + ], |
| 254 | + ), |
| 255 | + }, |
| 256 | + unmarshalListSecretVersionsResponse, |
| 257 | + ) |
| 258 | + |
| 259 | + /** |
| 260 | + * List versions of a secret, not returning any sensitive data |
| 261 | + * |
| 262 | + * @param request - The request {@link ListSecretVersionsRequest} |
| 263 | + * @returns A Promise of ListSecretVersionsResponse |
| 264 | + */ |
| 265 | + listSecretVersions = (request: Readonly<ListSecretVersionsRequest>) => |
| 266 | + enrichForPagination('versions', this.pageOfListSecretVersions, request) |
| 267 | + |
| 268 | + /** |
| 269 | + * Destroy a SecretVersion, permanently destroying the sensitive data |
| 270 | + * |
| 271 | + * @param request - The request {@link DestroySecretVersionRequest} |
| 272 | + * @returns A Promise of SecretVersion |
| 273 | + */ |
| 274 | + destroySecretVersion = (request: Readonly<DestroySecretVersionRequest>) => |
| 275 | + this.client.fetch<SecretVersion>( |
| 276 | + { |
| 277 | + body: '{}', |
| 278 | + headers: jsonContentHeaders, |
| 279 | + method: 'POST', |
| 280 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 281 | + 'region', |
| 282 | + request.region ?? this.client.settings.defaultRegion, |
| 283 | + )}/secrets/${validatePathParam( |
| 284 | + 'secretId', |
| 285 | + request.secretId, |
| 286 | + )}/versions/${validatePathParam('revision', request.revision)}/destroy`, |
| 287 | + }, |
| 288 | + unmarshalSecretVersion, |
| 289 | + ) |
| 290 | + |
| 291 | + /** |
| 292 | + * Enable a SecretVersion |
| 293 | + * |
| 294 | + * @param request - The request {@link EnableSecretVersionRequest} |
| 295 | + * @returns A Promise of SecretVersion |
| 296 | + */ |
| 297 | + enableSecretVersion = (request: Readonly<EnableSecretVersionRequest>) => |
| 298 | + this.client.fetch<SecretVersion>( |
| 299 | + { |
| 300 | + body: '{}', |
| 301 | + headers: jsonContentHeaders, |
| 302 | + method: 'POST', |
| 303 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 304 | + 'region', |
| 305 | + request.region ?? this.client.settings.defaultRegion, |
| 306 | + )}/secrets/${validatePathParam( |
| 307 | + 'secretId', |
| 308 | + request.secretId, |
| 309 | + )}/versions/${validatePathParam('revision', request.revision)}/enable`, |
| 310 | + }, |
| 311 | + unmarshalSecretVersion, |
| 312 | + ) |
| 313 | + |
| 314 | + /** |
| 315 | + * Disable a SecretVersion |
| 316 | + * |
| 317 | + * @param request - The request {@link DisableSecretVersionRequest} |
| 318 | + * @returns A Promise of SecretVersion |
| 319 | + */ |
| 320 | + disableSecretVersion = (request: Readonly<DisableSecretVersionRequest>) => |
| 321 | + this.client.fetch<SecretVersion>( |
| 322 | + { |
| 323 | + body: '{}', |
| 324 | + headers: jsonContentHeaders, |
| 325 | + method: 'POST', |
| 326 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 327 | + 'region', |
| 328 | + request.region ?? this.client.settings.defaultRegion, |
| 329 | + )}/secrets/${validatePathParam( |
| 330 | + 'secretId', |
| 331 | + request.secretId, |
| 332 | + )}/versions/${validatePathParam('revision', request.revision)}/disable`, |
| 333 | + }, |
| 334 | + unmarshalSecretVersion, |
| 335 | + ) |
| 336 | + |
| 337 | + /** |
| 338 | + * Access a SecretVersion, returning the sensitive data |
| 339 | + * |
| 340 | + * @param request - The request {@link AccessSecretVersionRequest} |
| 341 | + * @returns A Promise of AccessSecretVersionResponse |
| 342 | + */ |
| 343 | + accessSecretVersion = (request: Readonly<AccessSecretVersionRequest>) => |
| 344 | + this.client.fetch<AccessSecretVersionResponse>( |
| 345 | + { |
| 346 | + method: 'GET', |
| 347 | + path: `/secret-manager/v1alpha1/regions/${validatePathParam( |
| 348 | + 'region', |
| 349 | + request.region ?? this.client.settings.defaultRegion, |
| 350 | + )}/secrets/${validatePathParam( |
| 351 | + 'secretId', |
| 352 | + request.secretId, |
| 353 | + )}/versions/${validatePathParam('revision', request.revision)}/access`, |
| 354 | + }, |
| 355 | + unmarshalAccessSecretVersionResponse, |
| 356 | + ) |
| 357 | +} |
0 commit comments