Class v2.StorageClient (0.7.0)

## API Overview and Naming Syntax

The Cloud Storage gRPC API allows applications to read and write data through the abstractions of buckets and objects. For a description of these abstractions please see [Cloud Storage documentation](https://cloud.google.com/storage/docs).

Resources are named as follows:

  • Projects are referred to as they are defined by the Resource Manager API, using strings like projects/123456 or projects/my-string-id. - Buckets are named using string names of the form: projects/{project}/buckets/{bucket}. For globally unique buckets, _ might be substituted for the project. - Objects are uniquely identified by their name along with the name of the bucket they belong to, as separate strings in this API. For example:

``` ReadObjectRequest { bucket: 'projects/_/buckets/my-bucket' object: 'my-object' } ```

Note that object names can contain / characters, which are treated as any other character (no special directory semantics). v2

Package

@google-cloud/storage-control

Constructors

(constructor)(opts, gaxInstance)

constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);

Construct an instance of StorageClient.

Parameters
Name Description
opts ClientOptions
gaxInstance typeof gax | typeof fallback

: loaded instance of google-gax. Useful if you need to avoid loading the default gRPC version and want to use the fallback HTTP implementation. Load only fallback version and pass it to the constructor: ``` const gax = require('google-gax/build/src/fallback'); // avoids loading google-gax with gRPC const client = new StorageClient({fallback: true}, gax); ```

Properties

apiEndpoint

get apiEndpoint(): string;

The DNS address for this API service.

apiEndpoint

static get apiEndpoint(): string;

The DNS address for this API service - same as servicePath.

auth

auth: gax.GoogleAuth;

descriptors

descriptors: Descriptors;

innerApiCalls

innerApiCalls: {
        [name: string]: Function;
    };

pathTemplates

pathTemplates: {
        [name: string]: gax.PathTemplate;
    };

port

static get port(): number;

The port for this API service.

scopes

static get scopes(): string[];

The scopes needed to make gRPC calls for every method defined in this service.

servicePath

static get servicePath(): string;

The DNS address for this API service.

storageStub

storageStub?: Promise<{
        [name: string]: Function;
    }>;

universeDomain

get universeDomain(): string;

warn

warn: (code: string, message: string, warnType?: string) => void;

Methods

bucketPath(project, bucket)

bucketPath(project: string, bucket: string): string;

Return a fully-qualified bucket resource name string.

Parameters
Name Description
project string
bucket string
Returns
Type Description
string

{string} Resource name string.

close()

close(): Promise<void>;

Terminate the gRPC channel and close the client.

The client will no longer be usable and all future behavior is undefined.

Returns
Type Description
Promise<void>

{Promise} A promise that resolves when the client is closed.

createBucket(request, options)

createBucket(request?: protos.google.storage.v2.ICreateBucketRequest, options?: CallOptions): Promise<[
        protos.google.storage.v2.IBucket,
        protos.google.storage.v2.ICreateBucketRequest | undefined,
        {} | undefined
    ]>;

Creates a new bucket.

**IAM Permissions**:

Requires storage.buckets.create IAM permission on the bucket. Additionally, to enable specific bucket features, the authenticated user must have the following permissions:

  • To enable object retention using the enableObjectRetention query parameter: storage.buckets.enableObjectRetention - To set the bucket IP filtering rules: storage.buckets.setIpFilter
Parameters
Name Description
request ICreateBucketRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.storage.v2.IBucket, protos.google.storage.v2.ICreateBucketRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The project to which this bucket belongs. This field must either
   *  be empty or `projects/_`. The project ID that owns this bucket should be
   *  specified in the `bucket.project` field.
   */
  // const parent = 'abc123'
  /**
   *  Optional. Properties of the new bucket being inserted.
   *  The name of the bucket is specified in the `bucket_id` field. Populating
   *  `bucket.name` field results in an error.
   *  The project of the bucket must be specified in the `bucket.project` field.
   *  This field must be in `projects/{projectIdentifier}` format,
   *  {projectIdentifier} can be the project ID or project number. The `parent`
   *  field must be either empty or `projects/_`.
   */
  // const bucket = {}
  /**
   *  Required. The ID to use for this bucket, which becomes the final component
   *  of the bucket's resource name. For example, the value `foo` might result in
   *  a bucket with the name `projects/123456/buckets/foo`.
   */
  // const bucketId = 'abc123'
  /**
   *  Optional. Apply a predefined set of access controls to this bucket.
   *  Valid values are `authenticatedRead`, `private`, `projectPrivate`,
   *  `publicRead`, or `publicReadWrite`.
   */
  // const predefinedAcl = 'abc123'
  /**
   *  Optional. Apply a predefined set of default object access controls to this
   *  bucket. Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   *  `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  // const predefinedDefaultObjectAcl = 'abc123'
  /**
   *  Optional. If true, enable object retention on the bucket.
   */
  // const enableObjectRetention = true

  // Imports the Storage library
  const {StorageClient} = require('@google-cloud/storage').v2;

  // Instantiates a client
  const storageClient = new StorageClient();

  async function callCreateBucket() {
    // Construct request
    const request = {
      parent,
      bucketId,
    };

    // Run request
    const response = await storageClient.createBucket(request);
    console.log(response);
  }

  callCreateBucket();

createBucket(request, options, callback)

createBucket(request: protos.google.storage.v2.ICreateBucketRequest, options: CallOptions, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ICreateBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ICreateBucketRequest
options CallOptions
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ICreateBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

createBucket(request, callback)

createBucket(request: protos.google.storage.v2.ICreateBucketRequest, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ICreateBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ICreateBucketRequest
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ICreateBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

cryptoKeyPath(project, location, keyRing, cryptoKey)

cryptoKeyPath(project: string, location: string, keyRing: string, cryptoKey: string): string;

Return a fully-qualified cryptoKey resource name string.

Parameters
Name Description
project string
location string
keyRing string
cryptoKey string
Returns
Type Description
string

{string} Resource name string.

deleteBucket(request, options)

deleteBucket(request?: protos.google.storage.v2.IDeleteBucketRequest, options?: CallOptions): Promise<[
        protos.google.protobuf.IEmpty,
        protos.google.storage.v2.IDeleteBucketRequest | undefined,
        {} | undefined
    ]>;

Permanently deletes an empty bucket. The request fails if there are any live or noncurrent objects in the bucket, but the request succeeds if the bucket only contains soft-deleted objects or incomplete uploads, such as ongoing XML API multipart uploads. Does not permanently delete soft-deleted objects.

When this API is used to delete a bucket containing an object that has a soft delete policy enabled, the object becomes soft deleted, and the softDeleteTime and hardDeleteTime properties are set on the object.

Objects and multipart uploads that were in the bucket at the time of deletion are also retained for the specified retention duration. When a soft-deleted bucket reaches the end of its retention duration, it is permanently deleted. The hardDeleteTime of the bucket always equals or exceeds the expiration time of the last soft-deleted object in the bucket.

**IAM Permissions**:

Requires storage.buckets.delete IAM permission on the bucket.

Parameters
Name Description
request IDeleteBucketRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.protobuf.IEmpty, protos.google.storage.v2.IDeleteBucketRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing Empty. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Name of a bucket to delete.
   */
  // const name = 'abc123'
  /**
   *  If set, only deletes the bucket if its metageneration matches this value.
   */
  // const ifMetagenerationMatch = 1234
  /**
   *  If set, only deletes the bucket if its metageneration does not match this
   *  value.
   */
  // const ifMetagenerationNotMatch = 1234

  // Imports the Storage library
  const {StorageClient} = require('@google-cloud/storage').v2;

  // Instantiates a client
  const storageClient = new StorageClient();

  async function callDeleteBucket() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const response = await storageClient.deleteBucket(request);
    console.log(response);
  }

  callDeleteBucket();

deleteBucket(request, options, callback)

deleteBucket(request: protos.google.storage.v2.IDeleteBucketRequest, options: CallOptions, callback: Callback<protos.google.protobuf.IEmpty, protos.google.storage.v2.IDeleteBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IDeleteBucketRequest
options CallOptions
callback Callback<protos.google.protobuf.IEmpty, protos.google.storage.v2.IDeleteBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

deleteBucket(request, callback)

deleteBucket(request: protos.google.storage.v2.IDeleteBucketRequest, callback: Callback<protos.google.protobuf.IEmpty, protos.google.storage.v2.IDeleteBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IDeleteBucketRequest
callback Callback<protos.google.protobuf.IEmpty, protos.google.storage.v2.IDeleteBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

getBucket(request, options)

getBucket(request?: protos.google.storage.v2.IGetBucketRequest, options?: CallOptions): Promise<[
        protos.google.storage.v2.IBucket,
        protos.google.storage.v2.IGetBucketRequest | undefined,
        {} | undefined
    ]>;

Returns metadata for the specified bucket.

**IAM Permissions**:

Requires storage.buckets.get IAM permission on the bucket. Additionally, to return specific bucket metadata, the authenticated user must have the following permissions:

  • To return the IAM policies: storage.buckets.getIamPolicy - To return the bucket IP filtering rules: storage.buckets.getIpFilter
Parameters
Name Description
request IGetBucketRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.storage.v2.IBucket, protos.google.storage.v2.IGetBucketRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Name of a bucket.
   */
  // const name = 'abc123'
  /**
   *  If set, only gets the bucket metadata if its metageneration matches this
   *  value.
   */
  // const ifMetagenerationMatch = 1234
  /**
   *  If set, and if the bucket's current metageneration matches the specified
   *  value, the request returns an error.
   */
  // const ifMetagenerationNotMatch = 1234
  /**
   *  Mask specifying which fields to read.
   *  A `*` field might be used to indicate all fields.
   *  If no mask is specified, it defaults to all fields.
   */
  // const readMask = {}

  // Imports the Storage library
  const {StorageClient} = require('@google-cloud/storage').v2;

  // Instantiates a client
  const storageClient = new StorageClient();

  async function callGetBucket() {
    // Construct request
    const request = {
      name,
    };

    // Run request
    const response = await storageClient.getBucket(request);
    console.log(response);
  }

  callGetBucket();

getBucket(request, options, callback)

getBucket(request: protos.google.storage.v2.IGetBucketRequest, options: CallOptions, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IGetBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IGetBucketRequest
options CallOptions
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IGetBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

getBucket(request, callback)

getBucket(request: protos.google.storage.v2.IGetBucketRequest, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IGetBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IGetBucketRequest
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IGetBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

getProjectId()

getProjectId(): Promise<string>;
Returns
Type Description
Promise<string>

getProjectId(callback)

getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter
Name Description
callback Callback<string, undefined, undefined>
Returns
Type Description
void

initialize()

initialize(): Promise<{
        [name: string]: Function;
    }>;

Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.

You can await on this method if you want to make sure the client is initialized.

Returns
Type Description
Promise<{ [name: string]: Function; }>

{Promise} A promise that resolves to an authenticated service stub.

listBuckets(request, options)

listBuckets(request?: protos.google.storage.v2.IListBucketsRequest, options?: CallOptions): Promise<[
        protos.google.storage.v2.IBucket[],
        protos.google.storage.v2.IListBucketsRequest | null,
        protos.google.storage.v2.IListBucketsResponse
    ]>;

Retrieves a list of buckets for a given project, ordered lexicographically by name.

**IAM Permissions**:

Requires storage.buckets.list IAM permission on the bucket. Additionally, to enable specific bucket features, the authenticated user must have the following permissions:

  • To list the IAM policies: storage.buckets.getIamPolicy - To list the bucket IP filtering rules: storage.buckets.getIpFilter
Parameters
Name Description
request IListBucketsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.storage.v2.IBucket[], protos.google.storage.v2.IListBucketsRequest | null, protos.google.storage.v2.IListBucketsResponse ]>

{Promise} - The promise which resolves to an array. The first element of the array is Array of . The client library will perform auto-pagination by default: it will call the API as many times as needed and will merge results from all the pages into this array. Note that it can affect your quota. We recommend using listBucketsAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

listBuckets(request, options, callback)

listBuckets(request: protos.google.storage.v2.IListBucketsRequest, options: CallOptions, callback: PaginationCallback<protos.google.storage.v2.IListBucketsRequest, protos.google.storage.v2.IListBucketsResponse | null | undefined, protos.google.storage.v2.IBucket>): void;
Parameters
Name Description
request IListBucketsRequest
options CallOptions
callback PaginationCallback<protos.google.storage.v2.IListBucketsRequest, protos.google.storage.v2.IListBucketsResponse | null | undefined, protos.google.storage.v2.IBucket>
Returns
Type Description
void

listBuckets(request, callback)

listBuckets(request: protos.google.storage.v2.IListBucketsRequest, callback: PaginationCallback<protos.google.storage.v2.IListBucketsRequest, protos.google.storage.v2.IListBucketsResponse | null | undefined, protos.google.storage.v2.IBucket>): void;
Parameters
Name Description
request IListBucketsRequest
callback PaginationCallback<protos.google.storage.v2.IListBucketsRequest, protos.google.storage.v2.IListBucketsResponse | null | undefined, protos.google.storage.v2.IBucket>
Returns
Type Description
void

listBucketsAsync(request, options)

listBucketsAsync(request?: protos.google.storage.v2.IListBucketsRequest, options?: CallOptions): AsyncIterable<protos.google.storage.v2.IBucket>;

Equivalent to listBuckets, but returns an iterable object.

for-await-of syntax is used with the iterable to get response elements on-demand.

Parameters
Name Description
request IListBucketsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
AsyncIterable<protos.google.storage.v2.IBucket>

{Object} An iterable Object that allows async iteration. When you iterate the returned iterable, each element will be an object representing . The API will be called under the hood as needed, once per the page, so you can stop the iteration when you don't need more results. Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The project whose buckets we are listing.
   */
  // const parent = 'abc123'
  /**
   *  Optional. Maximum number of buckets to return in a single response. The
   *  service uses this parameter or `1,000` items, whichever is smaller. If
   *  `acl` is present in the `read_mask`, the service uses this parameter of
   *  `200` items, whichever is smaller.
   */
  // const pageSize = 1234
  /**
   *  Optional. A previously-returned page token representing part of the larger
   *  set of results to view.
   */
  // const pageToken = 'abc123'
  /**
   *  Optional. Filter results to buckets whose names begin with this prefix.
   */
  // const prefix = 'abc123'
  /**
   *  Mask specifying which fields to read from each result.
   *  If no mask is specified, it defaults to all fields except `items.
   *  owner`, `items.acl`, and `items.default_object_acl`.
   *  `*` might be used to mean "all fields".
   */
  // const readMask = {}
  /**
   *  Optional. Allows listing of buckets, even if there are buckets that are
   *  unreachable.
   */
  // const returnPartialSuccess = true

  // Imports the Storage library
  const {StorageClient} = require('@google-cloud/storage').v2;

  // Instantiates a client
  const storageClient = new StorageClient();

  async function callListBuckets() {
    // Construct request
    const request = {
      parent,
    };

    // Run request
    const iterable = storageClient.listBucketsAsync(request);
    for await (const response of iterable) {
        console.log(response);
    }
  }

  callListBuckets();

listBucketsStream(request, options)

listBucketsStream(request?: protos.google.storage.v2.IListBucketsRequest, options?: CallOptions): Transform;

Equivalent to listBuckets, but returns a NodeJS Stream object.

Parameters
Name Description
request IListBucketsRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Transform

{Stream} An object stream which emits an object representing on 'data' event. The client library will perform auto-pagination by default: it will call the API as many times as needed. Note that it can affect your quota. We recommend using listBucketsAsync() method described below for async iteration which you can stop as needed. Please see the documentation for more details and examples.

lockBucketRetentionPolicy(request, options)

lockBucketRetentionPolicy(request?: protos.google.storage.v2.ILockBucketRetentionPolicyRequest, options?: CallOptions): Promise<[
        protos.google.storage.v2.IBucket,
        protos.google.storage.v2.ILockBucketRetentionPolicyRequest | undefined,
        {} | undefined
    ]>;

Permanently locks the retention policy that is currently applied to the specified bucket.

Caution: Locking a bucket is an irreversible action. Once you lock a bucket:

  • You cannot remove the retention policy from the bucket. - You cannot decrease the retention period for the policy.

Once locked, you must delete the entire bucket in order to remove the bucket's retention policy. However, before you can delete the bucket, you must delete all the objects in the bucket, which is only possible if all the objects have reached the retention period set by the retention policy.

**IAM Permissions**:

Requires storage.buckets.update IAM permission on the bucket.

Parameters
Name Description
request ILockBucketRetentionPolicyRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.storage.v2.IBucket, protos.google.storage.v2.ILockBucketRetentionPolicyRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. Name of a bucket.
   */
  // const bucket = 'abc123'
  /**
   *  Required. Makes the operation conditional on whether bucket's current
   *  metageneration matches the given value. Must be positive.
   */
  // const ifMetagenerationMatch = 1234

  // Imports the Storage library
  const {StorageClient} = require('@google-cloud/storage').v2;

  // Instantiates a client
  const storageClient = new StorageClient();

  async function callLockBucketRetentionPolicy() {
    // Construct request
    const request = {
      bucket,
      ifMetagenerationMatch,
    };

    // Run request
    const response = await storageClient.lockBucketRetentionPolicy(request);
    console.log(response);
  }

  callLockBucketRetentionPolicy();

lockBucketRetentionPolicy(request, options, callback)

lockBucketRetentionPolicy(request: protos.google.storage.v2.ILockBucketRetentionPolicyRequest, options: CallOptions, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ILockBucketRetentionPolicyRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ILockBucketRetentionPolicyRequest
options CallOptions
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ILockBucketRetentionPolicyRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

lockBucketRetentionPolicy(request, callback)

lockBucketRetentionPolicy(request: protos.google.storage.v2.ILockBucketRetentionPolicyRequest, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ILockBucketRetentionPolicyRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request ILockBucketRetentionPolicyRequest
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.ILockBucketRetentionPolicyRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

matchBucketFromBucketName(bucketName)

matchBucketFromBucketName(bucketName: string): string | number;

Parse the bucket from Bucket resource.

Parameter
Name Description
bucketName string

A fully-qualified path representing Bucket resource.

Returns
Type Description
string | number

{string} A string representing the bucket.

matchCryptoKeyFromCryptoKeyName(cryptoKeyName)

matchCryptoKeyFromCryptoKeyName(cryptoKeyName: string): string | number;

Parse the crypto_key from CryptoKey resource.

Parameter
Name Description
cryptoKeyName string

A fully-qualified path representing CryptoKey resource.

Returns
Type Description
string | number

{string} A string representing the crypto_key.

matchKeyRingFromCryptoKeyName(cryptoKeyName)

matchKeyRingFromCryptoKeyName(cryptoKeyName: string): string | number;

Parse the key_ring from CryptoKey resource.

Parameter
Name Description
cryptoKeyName string

A fully-qualified path representing CryptoKey resource.

Returns
Type Description
string | number

{string} A string representing the key_ring.

matchLocationFromCryptoKeyName(cryptoKeyName)

matchLocationFromCryptoKeyName(cryptoKeyName: string): string | number;

Parse the location from CryptoKey resource.

Parameter
Name Description
cryptoKeyName string

A fully-qualified path representing CryptoKey resource.

Returns
Type Description
string | number

{string} A string representing the location.

matchProjectFromBucketName(bucketName)

matchProjectFromBucketName(bucketName: string): string | number;

Parse the project from Bucket resource.

Parameter
Name Description
bucketName string

A fully-qualified path representing Bucket resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchProjectFromCryptoKeyName(cryptoKeyName)

matchProjectFromCryptoKeyName(cryptoKeyName: string): string | number;

Parse the project from CryptoKey resource.

Parameter
Name Description
cryptoKeyName string

A fully-qualified path representing CryptoKey resource.

Returns
Type Description
string | number

{string} A string representing the project.

matchProjectFromProjectName(projectName)

matchProjectFromProjectName(projectName: string): string | number;

Parse the project from Project resource.

Parameter
Name Description
projectName string

A fully-qualified path representing Project resource.

Returns
Type Description
string | number

{string} A string representing the project.

projectPath(project)

projectPath(project: string): string;

Return a fully-qualified project resource name string.

Parameter
Name Description
project string
Returns
Type Description
string

{string} Resource name string.

updateBucket(request, options)

updateBucket(request?: protos.google.storage.v2.IUpdateBucketRequest, options?: CallOptions): Promise<[
        protos.google.storage.v2.IBucket,
        protos.google.storage.v2.IUpdateBucketRequest | undefined,
        {} | undefined
    ]>;

Updates a bucket. Changes to the bucket are readable immediately after writing, but configuration changes might take time to propagate. This method supports patch semantics.

**IAM Permissions**:

Requires storage.buckets.update IAM permission on the bucket. Additionally, to enable specific bucket features, the authenticated user must have the following permissions:

  • To set bucket IP filtering rules: storage.buckets.setIpFilter - To update public access prevention policies or access control lists (ACLs): storage.buckets.setIamPolicy
Parameters
Name Description
request IUpdateBucketRequest

The request object that will be sent.

options CallOptions

Call options. See CallOptions for more details.

Returns
Type Description
Promise<[ protos.google.storage.v2.IBucket, protos.google.storage.v2.IUpdateBucketRequest | undefined, {} | undefined ]>

{Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the documentation for more details and examples.

Example

  /**
   * This snippet has been automatically generated and should be regarded as a code template only.
   * It will require modifications to work.
   * It may require correct/in-range values for request initialization.
   * TODO(developer): Uncomment these variables before running the sample.
   */
  /**
   *  Required. The bucket to update.
   *  The bucket's `name` field is used to identify the bucket.
   */
  // const bucket = {}
  /**
   *  If set, the request modifies the bucket if its metageneration matches this
   *  value.
   */
  // const ifMetagenerationMatch = 1234
  /**
   *  If set, the request modifies the bucket if its metageneration doesn't
   *  match this value.
   */
  // const ifMetagenerationNotMatch = 1234
  /**
   *  Optional. Apply a predefined set of access controls to this bucket.
   *  Valid values are `authenticatedRead`, `private`, `projectPrivate`,
   *  `publicRead`, or `publicReadWrite`.
   */
  // const predefinedAcl = 'abc123'
  /**
   *  Optional. Apply a predefined set of default object access controls to this
   *  bucket. Valid values are `authenticatedRead`, `bucketOwnerFullControl`,
   *  `bucketOwnerRead`, `private`, `projectPrivate`, or `publicRead`.
   */
  // const predefinedDefaultObjectAcl = 'abc123'
  /**
   *  Required. List of fields to be updated.
   *  To specify ALL fields, equivalent to the JSON API's "update" function,
   *  specify a single field with the value `*`. Note: not recommended. If a new
   *  field is introduced at a later time, an older client updating with the `*`
   *  might accidentally reset the new field's value.
   *  Not specifying any fields is an error.
   */
  // const updateMask = {}

  // Imports the Storage library
  const {StorageClient} = require('@google-cloud/storage').v2;

  // Instantiates a client
  const storageClient = new StorageClient();

  async function callUpdateBucket() {
    // Construct request
    const request = {
      bucket,
      updateMask,
    };

    // Run request
    const response = await storageClient.updateBucket(request);
    console.log(response);
  }

  callUpdateBucket();

updateBucket(request, options, callback)

updateBucket(request: protos.google.storage.v2.IUpdateBucketRequest, options: CallOptions, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IUpdateBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IUpdateBucketRequest
options CallOptions
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IUpdateBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void

updateBucket(request, callback)

updateBucket(request: protos.google.storage.v2.IUpdateBucketRequest, callback: Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IUpdateBucketRequest | null | undefined, {} | null | undefined>): void;
Parameters
Name Description
request IUpdateBucketRequest
callback Callback<protos.google.storage.v2.IBucket, protos.google.storage.v2.IUpdateBucketRequest | null | undefined, {} | null | undefined>
Returns
Type Description
void