1 | import { ApiError, Service, ServiceOptions } from './nodejs-common/index.js';
|
2 | import { Readable } from 'stream';
|
3 | import { Bucket, BucketMetadata } from './bucket.js';
|
4 | import { Channel } from './channel.js';
|
5 | import { File } from './file.js';
|
6 | import { HmacKey, HmacKeyMetadata, HmacKeyOptions } from './hmacKey.js';
|
7 | import { CRC32CValidatorGenerator } from './crc32c.js';
|
8 | export interface GetServiceAccountOptions {
|
9 | userProject?: string;
|
10 | projectIdentifier?: string;
|
11 | }
|
12 | export interface ServiceAccount {
|
13 | emailAddress?: string;
|
14 | }
|
15 | export type GetServiceAccountResponse = [ServiceAccount, unknown];
|
16 | export interface GetServiceAccountCallback {
|
17 | (err: Error | null, serviceAccount?: ServiceAccount, apiResponse?: unknown): void;
|
18 | }
|
19 | export interface CreateBucketQuery {
|
20 | enableObjectRetention: boolean;
|
21 | predefinedAcl?: 'authenticatedRead' | 'private' | 'projectPrivate' | 'publicRead' | 'publicReadWrite';
|
22 | predefinedDefaultObjectAcl?: 'authenticatedRead' | 'bucketOwnerFullControl' | 'bucketOwnerRead' | 'private' | 'projectPrivate' | 'publicRead';
|
23 | project: string;
|
24 | projection?: 'full' | 'noAcl';
|
25 | userProject: string;
|
26 | }
|
27 | export declare enum IdempotencyStrategy {
|
28 | RetryAlways = 0,
|
29 | RetryConditional = 1,
|
30 | RetryNever = 2
|
31 | }
|
32 | export interface RetryOptions {
|
33 | retryDelayMultiplier?: number;
|
34 | totalTimeout?: number;
|
35 | maxRetryDelay?: number;
|
36 | autoRetry?: boolean;
|
37 | maxRetries?: number;
|
38 | retryableErrorFn?: (err: ApiError) => boolean;
|
39 | idempotencyStrategy?: IdempotencyStrategy;
|
40 | }
|
41 | export interface PreconditionOptions {
|
42 | ifGenerationMatch?: number | string;
|
43 | ifGenerationNotMatch?: number | string;
|
44 | ifMetagenerationMatch?: number | string;
|
45 | ifMetagenerationNotMatch?: number | string;
|
46 | }
|
47 | export interface StorageOptions extends ServiceOptions {
|
48 | /**
|
49 | * The API endpoint of the service used to make requests.
|
50 | * Defaults to `storage.googleapis.com`.
|
51 | */
|
52 | apiEndpoint?: string;
|
53 | crc32cGenerator?: CRC32CValidatorGenerator;
|
54 | retryOptions?: RetryOptions;
|
55 | }
|
56 | export interface BucketOptions {
|
57 | crc32cGenerator?: CRC32CValidatorGenerator;
|
58 | kmsKeyName?: string;
|
59 | preconditionOpts?: PreconditionOptions;
|
60 | userProject?: string;
|
61 | generation?: number;
|
62 | softDeleted?: boolean;
|
63 | }
|
64 | export interface Cors {
|
65 | maxAgeSeconds?: number;
|
66 | method?: string[];
|
67 | origin?: string[];
|
68 | responseHeader?: string[];
|
69 | }
|
70 | interface Versioning {
|
71 | enabled: boolean;
|
72 | }
|
73 | /**
|
74 | * Custom placement configuration.
|
75 | * Initially used for dual-region buckets.
|
76 | **/
|
77 | export interface CustomPlacementConfig {
|
78 | dataLocations?: string[];
|
79 | }
|
80 | export interface AutoclassConfig {
|
81 | enabled?: boolean;
|
82 | terminalStorageClass?: 'NEARLINE' | 'ARCHIVE';
|
83 | }
|
84 | export interface CreateBucketRequest extends BucketMetadata {
|
85 | archive?: boolean;
|
86 | coldline?: boolean;
|
87 | dataLocations?: string[];
|
88 | dra?: boolean;
|
89 | enableObjectRetention?: boolean;
|
90 | multiRegional?: boolean;
|
91 | nearline?: boolean;
|
92 | predefinedAcl?: 'authenticatedRead' | 'private' | 'projectPrivate' | 'publicRead' | 'publicReadWrite';
|
93 | predefinedDefaultObjectAcl?: 'authenticatedRead' | 'bucketOwnerFullControl' | 'bucketOwnerRead' | 'private' | 'projectPrivate' | 'publicRead';
|
94 | projection?: 'full' | 'noAcl';
|
95 | regional?: boolean;
|
96 | requesterPays?: boolean;
|
97 | rpo?: string;
|
98 | standard?: boolean;
|
99 | storageClass?: string;
|
100 | userProject?: string;
|
101 | versioning?: Versioning;
|
102 | }
|
103 | export type CreateBucketResponse = [Bucket, unknown];
|
104 | export interface BucketCallback {
|
105 | (err: Error | null, bucket?: Bucket | null, apiResponse?: unknown): void;
|
106 | }
|
107 | export type GetBucketsResponse = [Bucket[], {}, unknown];
|
108 | export interface GetBucketsCallback {
|
109 | (err: Error | null, buckets: Bucket[], nextQuery?: {}, apiResponse?: unknown): void;
|
110 | }
|
111 | export interface GetBucketsRequest {
|
112 | prefix?: string;
|
113 | project?: string;
|
114 | autoPaginate?: boolean;
|
115 | maxApiCalls?: number;
|
116 | maxResults?: number;
|
117 | pageToken?: string;
|
118 | userProject?: string;
|
119 | softDeleted?: boolean;
|
120 | generation?: number;
|
121 | }
|
122 | export interface HmacKeyResourceResponse {
|
123 | metadata: HmacKeyMetadata;
|
124 | secret: string;
|
125 | }
|
126 | export type CreateHmacKeyResponse = [HmacKey, string, HmacKeyResourceResponse];
|
127 | export interface CreateHmacKeyOptions {
|
128 | projectId?: string;
|
129 | userProject?: string;
|
130 | }
|
131 | export interface CreateHmacKeyCallback {
|
132 | (err: Error | null, hmacKey?: HmacKey | null, secret?: string | null, apiResponse?: HmacKeyResourceResponse): void;
|
133 | }
|
134 | export interface GetHmacKeysOptions {
|
135 | projectId?: string;
|
136 | serviceAccountEmail?: string;
|
137 | showDeletedKeys?: boolean;
|
138 | autoPaginate?: boolean;
|
139 | maxApiCalls?: number;
|
140 | maxResults?: number;
|
141 | pageToken?: string;
|
142 | userProject?: string;
|
143 | }
|
144 | export interface GetHmacKeysCallback {
|
145 | (err: Error | null, hmacKeys: HmacKey[] | null, nextQuery?: {}, apiResponse?: unknown): void;
|
146 | }
|
147 | export declare enum ExceptionMessages {
|
148 | EXPIRATION_DATE_INVALID = "The expiration date provided was invalid.",
|
149 | EXPIRATION_DATE_PAST = "An expiration date cannot be in the past."
|
150 | }
|
151 | export declare enum StorageExceptionMessages {
|
152 | BUCKET_NAME_REQUIRED = "A bucket name is needed to use Cloud Storage.",
|
153 | BUCKET_NAME_REQUIRED_CREATE = "A name is required to create a bucket.",
|
154 | HMAC_SERVICE_ACCOUNT = "The first argument must be a service account email to create an HMAC key.",
|
155 | HMAC_ACCESS_ID = "An access ID is needed to create an HmacKey object."
|
156 | }
|
157 | export type GetHmacKeysResponse = [HmacKey[]];
|
158 | export declare const PROTOCOL_REGEX: RegExp;
|
159 | /**
|
160 | * Default behavior: Automatically retry retriable server errors.
|
161 | *
|
162 | * @const {boolean}
|
163 | */
|
164 | export declare const AUTO_RETRY_DEFAULT = true;
|
165 | /**
|
166 | * Default behavior: Only attempt to retry retriable errors 3 times.
|
167 | *
|
168 | * @const {number}
|
169 | */
|
170 | export declare const MAX_RETRY_DEFAULT = 3;
|
171 | /**
|
172 | * Default behavior: Wait twice as long as previous retry before retrying.
|
173 | *
|
174 | * @const {number}
|
175 | */
|
176 | export declare const RETRY_DELAY_MULTIPLIER_DEFAULT = 2;
|
177 | /**
|
178 | * Default behavior: If the operation doesn't succeed after 600 seconds,
|
179 | * stop retrying.
|
180 | *
|
181 | * @const {number}
|
182 | */
|
183 | export declare const TOTAL_TIMEOUT_DEFAULT = 600;
|
184 | /**
|
185 | * Default behavior: Wait no more than 64 seconds between retries.
|
186 | *
|
187 | * @const {number}
|
188 | */
|
189 | export declare const MAX_RETRY_DELAY_DEFAULT = 64;
|
190 | /**
|
191 | * Returns true if the API request should be retried, given the error that was
|
192 | * given the first time the request was attempted.
|
193 | * @const
|
194 | * @param {error} err - The API error to check if it is appropriate to retry.
|
195 | * @return {boolean} True if the API request should be retried, false otherwise.
|
196 | */
|
197 | export declare const RETRYABLE_ERR_FN_DEFAULT: (err?: ApiError) => boolean;
|
198 | /*! Developer Documentation
|
199 | *
|
200 | * Invoke this method to create a new Storage object bound with pre-determined
|
201 | * configuration options. For each object that can be created (e.g., a bucket),
|
202 | * there is an equivalent static and instance method. While they are classes,
|
203 | * they can be instantiated without use of the `new` keyword.
|
204 | */
|
205 | /**
|
206 | * Cloud Storage uses access control lists (ACLs) to manage object and
|
207 | * bucket access. ACLs are the mechanism you use to share objects with other
|
208 | * users and allow other users to access your buckets and objects.
|
209 | *
|
210 | * This object provides constants to refer to the three permission levels that
|
211 | * can be granted to an entity:
|
212 | *
|
213 | * - `gcs.acl.OWNER_ROLE` - ("OWNER")
|
214 | * - `gcs.acl.READER_ROLE` - ("READER")
|
215 | * - `gcs.acl.WRITER_ROLE` - ("WRITER")
|
216 | *
|
217 | * See {@link https://cloud.google.com/storage/docs/access-control/lists| About Access Control Lists}
|
218 | *
|
219 | * @name Storage#acl
|
220 | * @type {object}
|
221 | * @property {string} OWNER_ROLE
|
222 | * @property {string} READER_ROLE
|
223 | * @property {string} WRITER_ROLE
|
224 | *
|
225 | * @example
|
226 | * ```
|
227 | * const {Storage} = require('@google-cloud/storage');
|
228 | * const storage = new Storage();
|
229 | * const albums = storage.bucket('albums');
|
230 | *
|
231 | * //-
|
232 | * // Make all of the files currently in a bucket publicly readable.
|
233 | * //-
|
234 | * const options = {
|
235 | * entity: 'allUsers',
|
236 | * role: storage.acl.READER_ROLE
|
237 | * };
|
238 | *
|
239 | * albums.acl.add(options, function(err, aclObject) {});
|
240 | *
|
241 | * //-
|
242 | * // Make any new objects added to a bucket publicly readable.
|
243 | * //-
|
244 | * albums.acl.default.add(options, function(err, aclObject) {});
|
245 | *
|
246 | * //-
|
247 | * // Grant a user ownership permissions to a bucket.
|
248 | * //-
|
249 | * albums.acl.add({
|
250 | * entity: 'user-useremail@example.com',
|
251 | * role: storage.acl.OWNER_ROLE
|
252 | * }, function(err, aclObject) {});
|
253 | *
|
254 | * //-
|
255 | * // If the callback is omitted, we'll return a Promise.
|
256 | * //-
|
257 | * albums.acl.add(options).then(function(data) {
|
258 | * const aclObject = data[0];
|
259 | * const apiResponse = data[1];
|
260 | * });
|
261 | * ```
|
262 | */
|
263 | /**
|
264 | * Get {@link Bucket} objects for all of the buckets in your project as
|
265 | * a readable object stream.
|
266 | *
|
267 | * @method Storage#getBucketsStream
|
268 | * @param {GetBucketsRequest} [query] Query object for listing buckets.
|
269 | * @returns {ReadableStream} A readable stream that emits {@link Bucket}
|
270 | * instances.
|
271 | *
|
272 | * @example
|
273 | * ```
|
274 | * storage.getBucketsStream()
|
275 | * .on('error', console.error)
|
276 | * .on('data', function(bucket) {
|
277 | * // bucket is a Bucket object.
|
278 | * })
|
279 | * .on('end', function() {
|
280 | * // All buckets retrieved.
|
281 | * });
|
282 | *
|
283 | * //-
|
284 | * // If you anticipate many results, you can end a stream early to prevent
|
285 | * // unnecessary processing and API requests.
|
286 | * //-
|
287 | * storage.getBucketsStream()
|
288 | * .on('data', function(bucket) {
|
289 | * this.end();
|
290 | * });
|
291 | * ```
|
292 | */
|
293 | /**
|
294 | * Get {@link HmacKey} objects for all of the HMAC keys in the project in a
|
295 | * readable object stream.
|
296 | *
|
297 | * @method Storage#getHmacKeysStream
|
298 | * @param {GetHmacKeysOptions} [options] Configuration options.
|
299 | * @returns {ReadableStream} A readable stream that emits {@link HmacKey}
|
300 | * instances.
|
301 | *
|
302 | * @example
|
303 | * ```
|
304 | * storage.getHmacKeysStream()
|
305 | * .on('error', console.error)
|
306 | * .on('data', function(hmacKey) {
|
307 | * // hmacKey is an HmacKey object.
|
308 | * })
|
309 | * .on('end', function() {
|
310 | * // All HmacKey retrieved.
|
311 | * });
|
312 | *
|
313 | * //-
|
314 | * // If you anticipate many results, you can end a stream early to prevent
|
315 | * // unnecessary processing and API requests.
|
316 | * //-
|
317 | * storage.getHmacKeysStream()
|
318 | * .on('data', function(bucket) {
|
319 | * this.end();
|
320 | * });
|
321 | * ```
|
322 | */
|
323 | /**
|
324 | * <h4>ACLs</h4>
|
325 | * Cloud Storage uses access control lists (ACLs) to manage object and
|
326 | * bucket access. ACLs are the mechanism you use to share files with other users
|
327 | * and allow other users to access your buckets and files.
|
328 | *
|
329 | * To learn more about ACLs, read this overview on
|
330 | * {@link https://cloud.google.com/storage/docs/access-control| Access Control}.
|
331 | *
|
332 | * See {@link https://cloud.google.com/storage/docs/overview| Cloud Storage overview}
|
333 | * See {@link https://cloud.google.com/storage/docs/access-control| Access Control}
|
334 | *
|
335 | * @class
|
336 | */
|
337 | export declare class Storage extends Service {
|
338 | /**
|
339 | * {@link Bucket} class.
|
340 | *
|
341 | * @name Storage.Bucket
|
342 | * @see Bucket
|
343 | * @type {Constructor}
|
344 | */
|
345 | static Bucket: typeof Bucket;
|
346 | /**
|
347 | * {@link Channel} class.
|
348 | *
|
349 | * @name Storage.Channel
|
350 | * @see Channel
|
351 | * @type {Constructor}
|
352 | */
|
353 | static Channel: typeof Channel;
|
354 | /**
|
355 | * {@link File} class.
|
356 | *
|
357 | * @name Storage.File
|
358 | * @see File
|
359 | * @type {Constructor}
|
360 | */
|
361 | static File: typeof File;
|
362 | /**
|
363 | * {@link HmacKey} class.
|
364 | *
|
365 | * @name Storage.HmacKey
|
366 | * @see HmacKey
|
367 | * @type {Constructor}
|
368 | */
|
369 | static HmacKey: typeof HmacKey;
|
370 | static acl: {
|
371 | OWNER_ROLE: string;
|
372 | READER_ROLE: string;
|
373 | WRITER_ROLE: string;
|
374 | };
|
375 | /**
|
376 | * Reference to {@link Storage.acl}.
|
377 | *
|
378 | * @name Storage#acl
|
379 | * @see Storage.acl
|
380 | */
|
381 | acl: typeof Storage.acl;
|
382 | crc32cGenerator: CRC32CValidatorGenerator;
|
383 | getBucketsStream(): Readable;
|
384 | getHmacKeysStream(): Readable;
|
385 | retryOptions: RetryOptions;
|
386 | /**
|
387 | * @callback Crc32cGeneratorToStringCallback
|
388 | * A method returning the CRC32C as a base64-encoded string.
|
389 | *
|
390 | * @returns {string}
|
391 | *
|
392 | * @example
|
393 | * Hashing the string 'data' should return 'rth90Q=='
|
394 | *
|
395 | * ```js
|
396 | * const buffer = Buffer.from('data');
|
397 | * crc32c.update(buffer);
|
398 | * crc32c.toString(); // 'rth90Q=='
|
399 | * ```
|
400 | **/
|
401 | /**
|
402 | * @callback Crc32cGeneratorValidateCallback
|
403 | * A method validating a base64-encoded CRC32C string.
|
404 | *
|
405 | * @param {string} [value] base64-encoded CRC32C string to validate
|
406 | * @returns {boolean}
|
407 | *
|
408 | * @example
|
409 | * Should return `true` if the value matches, `false` otherwise
|
410 | *
|
411 | * ```js
|
412 | * const buffer = Buffer.from('data');
|
413 | * crc32c.update(buffer);
|
414 | * crc32c.validate('DkjKuA=='); // false
|
415 | * crc32c.validate('rth90Q=='); // true
|
416 | * ```
|
417 | **/
|
418 | /**
|
419 | * @callback Crc32cGeneratorUpdateCallback
|
420 | * A method for passing `Buffer`s for CRC32C generation.
|
421 | *
|
422 | * @param {Buffer} [data] data to update CRC32C value with
|
423 | * @returns {undefined}
|
424 | *
|
425 | * @example
|
426 | * Hashing buffers from 'some ' and 'text\n'
|
427 | *
|
428 | * ```js
|
429 | * const buffer1 = Buffer.from('some ');
|
430 | * crc32c.update(buffer1);
|
431 | *
|
432 | * const buffer2 = Buffer.from('text\n');
|
433 | * crc32c.update(buffer2);
|
434 | *
|
435 | * crc32c.toString(); // 'DkjKuA=='
|
436 | * ```
|
437 | **/
|
438 | /**
|
439 | * @typedef {object} CRC32CValidator
|
440 | * @property {Crc32cGeneratorToStringCallback}
|
441 | * @property {Crc32cGeneratorValidateCallback}
|
442 | * @property {Crc32cGeneratorUpdateCallback}
|
443 | */
|
444 | /**
|
445 | * @callback Crc32cGeneratorCallback
|
446 | * @returns {CRC32CValidator}
|
447 | */
|
448 | /**
|
449 | * @typedef {object} StorageOptions
|
450 | * @property {string} [projectId] The project ID from the Google Developer's
|
451 | * Console, e.g. 'grape-spaceship-123'. We will also check the environment
|
452 | * variable `GCLOUD_PROJECT` for your project ID. If your app is running
|
453 | * in an environment which supports {@link
|
454 | * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
|
455 | * Application Default Credentials}, your project ID will be detected
|
456 | * automatically.
|
457 | * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key
|
458 | * downloaded from the Google Developers Console. If you provide a path to
|
459 | * a JSON file, the `projectId` option above is not necessary. NOTE: .pem and
|
460 | * .p12 require you to specify the `email` option as well.
|
461 | * @property {string} [email] Account email address. Required when using a .pem
|
462 | * or .p12 keyFilename.
|
463 | * @property {object} [credentials] Credentials object.
|
464 | * @property {string} [credentials.client_email]
|
465 | * @property {string} [credentials.private_key]
|
466 | * @property {object} [retryOptions] Options for customizing retries. Retriable server errors
|
467 | * will be retried with exponential delay between them dictated by the formula
|
468 | * max(maxRetryDelay, retryDelayMultiplier*retryNumber) until maxRetries or totalTimeout
|
469 | * has been reached. Retries will only happen if autoRetry is set to true.
|
470 | * @property {boolean} [retryOptions.autoRetry=true] Automatically retry requests if the
|
471 | * response is related to rate limits or certain intermittent server
|
472 | * errors. We will exponentially backoff subsequent requests by default.
|
473 | * @property {number} [retryOptions.retryDelayMultiplier = 2] the multiplier by which to
|
474 | * increase the delay time between the completion of failed requests, and the
|
475 | * initiation of the subsequent retrying request.
|
476 | * @property {number} [retryOptions.totalTimeout = 600] The total time, starting from
|
477 | * when the initial request is sent, after which an error will
|
478 | * be returned, regardless of the retrying attempts made meanwhile.
|
479 | * @property {number} [retryOptions.maxRetryDelay = 64] The maximum delay time between requests.
|
480 | * When this value is reached, ``retryDelayMultiplier`` will no longer be used to
|
481 | * increase delay time.
|
482 | * @property {number} [retryOptions.maxRetries=3] Maximum number of automatic retries
|
483 | * attempted before returning the error.
|
484 | * @property {function} [retryOptions.retryableErrorFn] Function that returns true if a given
|
485 | * error should be retried and false otherwise.
|
486 | * @property {enum} [retryOptions.idempotencyStrategy=IdempotencyStrategy.RetryConditional] Enumeration
|
487 | * controls how conditionally idempotent operations are retried. Possible values are: RetryAlways -
|
488 | * will respect other retry settings and attempt to retry conditionally idempotent operations. RetryConditional -
|
489 | * will retry conditionally idempotent operations if the correct preconditions are set. RetryNever - never
|
490 | * retry a conditionally idempotent operation.
|
491 | * @property {string} [userAgent] The value to be prepended to the User-Agent
|
492 | * header in API requests.
|
493 | * @property {object} [authClient] `AuthClient` or `GoogleAuth` client to reuse instead of creating a new one.
|
494 | * @property {number} [timeout] The amount of time in milliseconds to wait per http request before timing out.
|
495 | * @property {object[]} [interceptors_] Array of custom request interceptors to be returned in the order they were assigned.
|
496 | * @property {string} [apiEndpoint = storage.google.com] The API endpoint of the service used to make requests.
|
497 | * @property {boolean} [useAuthWithCustomEndpoint = false] Controls whether or not to use authentication when using a custom endpoint.
|
498 | * @property {Crc32cGeneratorCallback} [callback] A function that generates a CRC32C Validator. Defaults to {@link CRC32C}
|
499 | */
|
500 | /**
|
501 | * Constructs the Storage client.
|
502 | *
|
503 | * @example
|
504 | * Create a client that uses Application Default Credentials
|
505 | * (ADC)
|
506 | * ```
|
507 | * const {Storage} = require('@google-cloud/storage');
|
508 | * const storage = new Storage();
|
509 | * ```
|
510 | *
|
511 | * @example
|
512 | * Create a client with explicit credentials
|
513 | * ```
|
514 | * const storage = new Storage({
|
515 | * projectId: 'your-project-id',
|
516 | * keyFilename: '/path/to/keyfile.json'
|
517 | * });
|
518 | * ```
|
519 | *
|
520 | * @example
|
521 | * Create a client with credentials passed
|
522 | * by value as a JavaScript object
|
523 | * ```
|
524 | * const storage = new Storage({
|
525 | * projectId: 'your-project-id',
|
526 | * credentials: {
|
527 | * type: 'service_account',
|
528 | * project_id: 'xxxxxxx',
|
529 | * private_key_id: 'xxxx',
|
530 | * private_key:'-----BEGIN PRIVATE KEY-----xxxxxxx\n-----END PRIVATE KEY-----\n',
|
531 | * client_email: 'xxxx',
|
532 | * client_id: 'xxx',
|
533 | * auth_uri: 'https://accounts.google.com/o/oauth2/auth',
|
534 | * token_uri: 'https://oauth2.googleapis.com/token',
|
535 | * auth_provider_x509_cert_url: 'https://www.googleapis.com/oauth2/v1/certs',
|
536 | * client_x509_cert_url: 'xxx',
|
537 | * }
|
538 | * });
|
539 | * ```
|
540 | *
|
541 | * @example
|
542 | * Create a client with credentials passed
|
543 | * by loading a JSON file directly from disk
|
544 | * ```
|
545 | * const storage = new Storage({
|
546 | * projectId: 'your-project-id',
|
547 | * credentials: require('/path/to-keyfile.json')
|
548 | * });
|
549 | * ```
|
550 | *
|
551 | * @example
|
552 | * Create a client with an `AuthClient` (e.g. `DownscopedClient`)
|
553 | * ```
|
554 | * const {DownscopedClient} = require('google-auth-library');
|
555 | * const authClient = new DownscopedClient({...});
|
556 | *
|
557 | * const storage = new Storage({authClient});
|
558 | * ```
|
559 | *
|
560 | * Additional samples:
|
561 | * - https://github.com/googleapis/google-auth-library-nodejs#sample-usage-1
|
562 | * - https://github.com/googleapis/google-auth-library-nodejs/blob/main/samples/downscopedclient.js
|
563 | *
|
564 | * @param {StorageOptions} [options] Configuration options.
|
565 | */
|
566 | constructor(options?: StorageOptions);
|
567 | private static sanitizeEndpoint;
|
568 | /**
|
569 | * Get a reference to a Cloud Storage bucket.
|
570 | *
|
571 | * @param {string} name Name of the bucket.
|
572 | * {object} [options] Configuration object.
|
573 | * string} [options.kmsKeyName] A Cloud KMS key that will be used to
{ |
574 | * encrypt objects inserted into this bucket, if no encryption method is
|
575 | * specified.
|
576 | * string} [options.userProject] User project to be billed for all
{ |
577 | * requests made from this Bucket object.
|
578 | * {Bucket}
|
579 | * Bucket
|
580 | *
|
581 | *
|
582 | * ```
|
583 | * const {Storage} = require('@google-cloud/storage');
|
584 | * const storage = new Storage();
|
585 | * const albums = storage.bucket('albums');
|
586 | * const photos = storage.bucket('photos');
|
587 | * ```
|
588 | */
|
589 | bucket(name: string, options?: BucketOptions): Bucket;
|
590 | /**
|
591 | * Reference a channel to receive notifications about changes to your bucket.
|
592 | *
|
593 | * @param {string} id The ID of the channel.
|
594 | * @param {string} resourceId The resource ID of the channel.
|
595 | * @returns {Channel}
|
596 | * @see Channel
|
597 | *
|
598 | * @example
|
599 | * ```
|
600 | * const {Storage} = require('@google-cloud/storage');
|
601 | * const storage = new Storage();
|
602 | * const channel = storage.channel('id', 'resource-id');
|
603 | * ```
|
604 | */
|
605 | channel(id: string, resourceId: string): Channel;
|
606 | createBucket(name: string, metadata?: CreateBucketRequest): Promise<CreateBucketResponse>;
|
607 | createBucket(name: string, callback: BucketCallback): void;
|
608 | createBucket(name: string, metadata: CreateBucketRequest, callback: BucketCallback): void;
|
609 | createBucket(name: string, metadata: CreateBucketRequest, callback: BucketCallback): void;
|
610 | createHmacKey(serviceAccountEmail: string, options?: CreateHmacKeyOptions): Promise<CreateHmacKeyResponse>;
|
611 | createHmacKey(serviceAccountEmail: string, callback: CreateHmacKeyCallback): void;
|
612 | createHmacKey(serviceAccountEmail: string, options: CreateHmacKeyOptions, callback: CreateHmacKeyCallback): void;
|
613 | getBuckets(options?: GetBucketsRequest): Promise<GetBucketsResponse>;
|
614 | getBuckets(options: GetBucketsRequest, callback: GetBucketsCallback): void;
|
615 | getBuckets(callback: GetBucketsCallback): void;
|
616 | /**
|
617 | * Query object for listing HMAC keys.
|
618 | *
|
619 | * @typedef {object} GetHmacKeysOptions
|
620 | * @property {string} [projectId] The project ID of the project that owns
|
621 | * the service account of the requested HMAC key. If not provided,
|
622 | * the project ID used to instantiate the Storage client will be used.
|
623 | * @property {string} [serviceAccountEmail] If present, only HMAC keys for the
|
624 | * given service account are returned.
|
625 | * @property {boolean} [showDeletedKeys=false] If true, include keys in the DELETE
|
626 | * state. Default is false.
|
627 | * @property {boolean} [autoPaginate=true] Have pagination handled
|
628 | * automatically.
|
629 | * @property {number} [maxApiCalls] Maximum number of API calls to make.
|
630 | * @property {number} [maxResults] Maximum number of items plus prefixes to
|
631 | * return per call.
|
632 | * Note: By default will handle pagination automatically
|
633 | * if more than 1 page worth of results are requested per call.
|
634 | * When `autoPaginate` is set to `false` the smaller of `maxResults`
|
635 | * or 1 page of results will be returned per call.
|
636 | * @property {string} [pageToken] A previously-returned page token
|
637 | * representing part of the larger set of results to view.
|
638 | * @property {string} [userProject] This parameter is currently ignored.
|
639 | */
|
640 | /**
|
641 | * @typedef {array} GetHmacKeysResponse
|
642 | * @property {HmacKey[]} 0 Array of {@link HmacKey} instances.
|
643 | * @param {object} nextQuery 1 A query object to receive more results.
|
644 | * @param {object} apiResponse 2 The full API response.
|
645 | */
|
646 | /**
|
647 | * @callback GetHmacKeysCallback
|
648 | * @param {?Error} err Request error, if any.
|
649 | * @param {HmacKey[]} hmacKeys Array of {@link HmacKey} instances.
|
650 | * @param {object} nextQuery A query object to receive more results.
|
651 | * @param {object} apiResponse The full API response.
|
652 | */
|
653 | /**
|
654 | * Retrieves a list of HMAC keys matching the criteria.
|
655 | *
|
656 | * The authenticated user must have storage.hmacKeys.list permission for the project in which the key exists.
|
657 | *
|
658 | * @param {GetHmacKeysOption} options Configuration options.
|
659 | * @param {GetHmacKeysCallback} callback Callback function.
|
660 | * @return {Promise<GetHmacKeysResponse>}
|
661 | *
|
662 | * @example
|
663 | * ```
|
664 | * const {Storage} = require('@google-cloud/storage');
|
665 | * const storage = new Storage();
|
666 | * storage.getHmacKeys(function(err, hmacKeys) {
|
667 | * if (!err) {
|
668 | * // hmacKeys is an array of HmacKey objects.
|
669 | * }
|
670 | * });
|
671 | *
|
672 | * //-
|
673 | * // To control how many API requests are made and page through the results
|
674 | * // manually, set `autoPaginate` to `false`.
|
675 | * //-
|
676 | * const callback = function(err, hmacKeys, nextQuery, apiResponse) {
|
677 | * if (nextQuery) {
|
678 | * // More results exist.
|
679 | * storage.getHmacKeys(nextQuery, callback);
|
680 | * }
|
681 | *
|
682 | * // The `metadata` property is populated for you with the metadata at the
|
683 | * // time of fetching.
|
684 | * hmacKeys[0].metadata;
|
685 | * };
|
686 | *
|
687 | * storage.getHmacKeys({
|
688 | * autoPaginate: false
|
689 | * }, callback);
|
690 | *
|
691 | * //-
|
692 | * // If the callback is omitted, we'll return a Promise.
|
693 | * //-
|
694 | * storage.getHmacKeys().then(function(data) {
|
695 | * const hmacKeys = data[0];
|
696 | * });
|
697 | * ```
|
698 | */
|
699 | getHmacKeys(options?: GetHmacKeysOptions): Promise<GetHmacKeysResponse>;
|
700 | getHmacKeys(callback: GetHmacKeysCallback): void;
|
701 | getHmacKeys(options: GetHmacKeysOptions, callback: GetHmacKeysCallback): void;
|
702 | getServiceAccount(options?: GetServiceAccountOptions): Promise<GetServiceAccountResponse>;
|
703 | getServiceAccount(options?: GetServiceAccountOptions): Promise<GetServiceAccountResponse>;
|
704 | getServiceAccount(options: GetServiceAccountOptions, callback: GetServiceAccountCallback): void;
|
705 | getServiceAccount(callback: GetServiceAccountCallback): void;
|
706 | /**
|
707 | * Get a reference to an HmacKey object.
|
708 | * Note: this does not fetch the HMAC key's metadata. Use HmacKey#get() to
|
709 | * retrieve and populate the metadata.
|
710 | *
|
711 | * To get a reference to an HMAC key that's not created for a service
|
712 | * account in the same project used to instantiate the Storage client,
|
713 | * supply the project's ID as `projectId` in the `options` argument.
|
714 | *
|
715 | * @param {string} accessId The HMAC key's access ID.
|
716 | * @param {HmacKeyOptions} options HmacKey constructor options.
|
717 | * @returns {HmacKey}
|
718 | * @see HmacKey
|
719 | *
|
720 | * @example
|
721 | * ```
|
722 | * const {Storage} = require('@google-cloud/storage');
|
723 | * const storage = new Storage();
|
724 | * const hmacKey = storage.hmacKey('ACCESS_ID');
|
725 | * ```
|
726 | */
|
727 | hmacKey(accessId: string, options?: HmacKeyOptions): HmacKey;
|
728 | }
|
729 | export {};
|