How to use @google-cloud/common - 10 common examples

To help you get started, we’ve selected a few @google-cloud/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github googleapis / nodejs-storage / test / file.ts View on Github external
it('should warn only once `keepAcl` parameter is passed', done => {
        file.request = util.noop;

        // since --throw-deprication is enabled using try=>catch block
        try {
          file.copy('newFile', {keepAcl: 'private'}, assert.ifError);
        } catch (err) {
          assert.strictEqual(
            err.message,
            'keepAcl parameter is not supported and will be removed in the next major'
          );
          assert.strictEqual(err.name, 'DeprecationWarning');
        }
        file2.copy('newFile2', {keepAcl: 'private'}, assert.ifError);
        done();
      });
    });
github googleapis / nodejs-spanner / test / index.ts View on Github external
beforeEach(() => {
    sandbox = sinon.createSandbox();
    fakeGapicClient = util.noop;
    // tslint:disable-next-line no-any
    (fakeGapicClient as any).scopes = [];
    fakeV1.DatabaseAdminClient = fakeGapicClient;
    fakeV1.InstanceAdminClient = fakeGapicClient;
    fakeV1.SpannerClient = fakeGapicClient;
    fakeCodec.SpannerDate = util.noop;
    fakeCodec.Int = util.noop;
    spanner = new Spanner(OPTIONS);
    spanner.projectId = OPTIONS.projectId;
    replaceProjectIdTokenOverride = null;
  });
github googleapis / cloud-trace-nodejs / test / test-trace-writer.ts View on Github external
after(() => {
    shimmer.unwrap(Service.prototype, 'getProjectId');
    oauth2Scope.done(); // It will likely be called at least once
    nock.enableNetConnect();
  });
github googleapis / nodejs-compute / src / operation.js View on Github external
this.getMetadata(function(err, metadata, apiResponse) {
      // Parsing the response body will automatically create an ApiError object if
      // the operation failed.
      const parsedHttpRespBody = common.util.parseHttpRespBody(apiResponse);
      err = err || parsedHttpRespBody.err;
      if (err) {
        callback(err);
        return;
      }
      if (metadata.status === 'RUNNING' && !self.status) {
        self.status = metadata.status;
        self.emit('running', metadata);
      }
      if (metadata.status !== 'DONE') {
        callback();
        return;
      }
      self.status = metadata.status;
      callback(null, metadata);
    });
github googleapis / google-cloud-node / packages / bigquery / src / table.js View on Github external
// Catch all for read-modify-write cycle
  // https://cloud.google.com/bigquery/docs/api-performance#read-patch-write
  this.interceptors.push({
    request: function(reqOpts) {
      if (reqOpts.method === 'PATCH' && reqOpts.json.etag) {
        reqOpts.headers = reqOpts.headers || {};
        reqOpts.headers['If-Match'] = reqOpts.json.etag;
      }

      return reqOpts;
    }
  });
}

util.inherits(Table, common.ServiceObject);

/**
 * Convert a comma-separated name:type string to a table schema object.
 *
 * @static
 * @private
 *
 * @param {string} str - Comma-separated schema string.
 * @return {object} Table schema in the format the API expects.
 */
Table.createSchemaFromString_ = function(str) {
  return str.split(/\s*,\s*/).reduce(function(acc, pair) {
    acc.fields.push({
      name: pair.split(':')[0],
      type: (pair.split(':')[1] || 'STRING').toUpperCase()
    });
github googleapis / nodejs-compute / src / instance-group.js View on Github external
* don't have to individually control each instance in your project.
 *
 * @see [Creating Groups of Instances]{@link https://cloud.google.com/compute/docs/instance-groups}
 * @see [Unmanaged Instance Groups]{@link https://cloud.google.com/compute/docs/instance-groups/creating-groups-of-unmanaged-instances}
 *
 * @class
 * @param {Zone} zone
 * @param {string} name
 *
 * @example
 * const Compute = require('@google-cloud/compute');
 * const compute = new Compute();
 * const zone = compute.zone('us-central1-a');
 * const instanceGroup = zone.instanceGroup('web-servers');
 */
class InstanceGroup extends common.ServiceObject {
  constructor(zone, name) {
    const methods = {
      /**
       * Create an instance group.
       *
       * @method InstanceGroup#create
       * @param {object=} options - See {@link Zone#createInstanceGroup}.
       *
       * @example
       * const Compute = require('@google-cloud/compute');
       * const compute = new Compute();
       * const zone = compute.zone('us-central1-a');
       * const instanceGroup = zone.instanceGroup('web-servers');
       *
       * function onCreated(err, instanceGroup, operation, apiResponse) {
       *   // `instanceGroup` is an InstanceGroup object.
github googleapis / google-cloud-node / packages / compute / src / zone.js View on Github external
protocols: {
      tcp: [443]
    },
    ranges: ['0.0.0.0/0'],
    tags: ['https-server']
  }, function(err) {
    // If it already exists, we're all good.
    callback(err && err.code !== 409 ? err : null);
  });
};

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.paginator.extend(Zone, [
  'getAutoscalers',
  'getDisks',
  'getInstanceGroups',
  'getMachineTypes',
  'getOperations',
  'getVMs'
]);

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
common.util.promisifyAll(Zone, {
  exclude: [
    'autoscaler',
github googleapis / google-cloud-node / packages / storage / src / index.js View on Github external
*     // bucket is a Bucket object.
 *   })
 *   .on('end', function() {
 *     // All buckets retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * gcs.getBucketsStream()
 *   .on('data', function(bucket) {
 *     this.end();
 *   });
 */
Storage.prototype.getBucketsStream = common.paginator.streamify('getBuckets');

/*! Developer Documentation
 *
 * These methods can be auto-paginated.
 */
common.paginator.extend(Storage, 'getBuckets');

/*! Developer Documentation
 *
 * All async methods (except for streams) will return a Promise in the event
 * that a callback is omitted.
 */
common.util.promisifyAll(Storage, {
  exclude: ['bucket', 'channel']
});
github googleapis / google-cloud-node / packages / pubsub / src / index.js View on Github external
*   })
 *   .on('end', function() {
 *     // All snapshots retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * pubsub.getSnapshotsStream()
 *   .on('data', function(snapshot) {
 *     this.end();
 *   });
 */
PubSub.prototype.getSnapshotsStream =
  common.paginator.streamify('getSnapshots');

/**
 * Get a list of the subscriptions registered to all of your project's topics.
 * You may optionally provide a query object as the first argument to customize
 * the response.
 *
 * Your provided callback will be invoked with an error object if an API error
 * occurred or an array of {module:pubsub/subscription} objects.
 *
 * To get subscriptions for a topic, see {module:pubsub/topic}.
 *
 * @resource [Subscriptions: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/list}
 *
 * @param {object=} options - Configuration object.
 * @param {boolean} options.autoPaginate - Have pagination handled
 *     automatically. Default: true.
github googleapis / google-cloud-node / packages / pubsub / src / index.js View on Github external
*   })
 *   .on('end', function() {
 *     // All subscriptions retrieved.
 *   });
 *
 * //-
 * // If you anticipate many results, you can end a stream early to prevent
 * // unnecessary processing and API requests.
 * //-
 * pubsub.getSubscriptionsStream()
 *   .on('data', function(subscription) {
 *     this.end();
 *   });
 */
PubSub.prototype.getSubscriptionsStream =
  common.paginator.streamify('getSubscriptions');

/**
 * Get a list of the topics registered to your project. You may optionally
 * provide a query object as the first argument to customize the response.
 *
 * @resource [Topics: list API Documentation]{@link https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/list}
 *
 * @param {object=} query - Query object.
 * @param {boolean} query.autoPaginate - Have pagination handled
 *     automatically. Default: true.
 * @param {object} query.gaxOpts - Request configuration options, outlined
 *     here: https://googleapis.github.io/gax-nodejs/CallSettings.html.
 * @param {number} query.pageSize - Max number of results to return.
 * @param {string} query.pageToken - Page token.
 * @param {function} callback - The callback function.
 * @param {?error} callback.err - An error from the API call, may be null.