How to use @google-cloud/projectify - 8 common examples

To help you get started, we’ve selected a few @google-cloud/projectify 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-bigtable / src / index.ts View on Github external
callback(err);
          return;
        }

        let gaxClient = this.api[config.client];

        if (!gaxClient) {
          // Lazily instantiate client.
          gaxClient = new v2[config.client](this.options[config.client]);
          this.api[config.client] = gaxClient;
        }

        let reqOpts = extend(true, {}, config.reqOpts);

        if (this.shouldReplaceProjectIdToken && projectId !== '{{projectId}}') {
          reqOpts = replaceProjectIdToken(reqOpts, projectId);
        }

        const requestFn = gaxClient[config.method].bind(
          gaxClient,
          reqOpts,
          config.gaxOpts
        );

        callback(null, requestFn);
      });
    };
github googleapis / nodejs-compute / src / vm.js View on Github external
self.zone.compute.authClient.getProjectId((err, projectId) => {
        if (err) {
          callback(err);
          return;
        }
        const diskName = replaceProjectIdToken(disk.formattedName, projectId);
        let deviceName;
        const resourceBaseUrl = `https://www.googleapis.com/compute/v1/`;
        const disks = metadata.disks || [];
        // Try to find the deviceName by matching the source of the attached disks
        // to the name of the disk provided by the user.
        for (let i = 0; !deviceName && i < disks.length; i++) {
          const attachedDisk = disks[i];
          const source = attachedDisk.source.replace(resourceBaseUrl, '');
          if (source === diskName) {
            deviceName = attachedDisk.deviceName;
          }
        }
        if (!deviceName) {
          callback(
            new DetachDiskError('Device name for this disk was not found.')
          );
github googleapis / nodejs-pubsub / src / connection-pool.ts View on Github external
this.emit('error', error);
        }
      };

      this.once(CHANNEL_ERROR_EVENT, onChannelError).once(
        CHANNEL_READY_EVENT,
        onChannelReady
      );
      requestStream.on('status', status =>
        setImmediate(onConnectionStatus, status)
      );
      connection
        .on('error', onConnectionError)
        .on('data', onConnectionData)
        .write({
          subscription: replaceProjectIdToken(
            this.subscription.name,
            this.pubsub.projectId
          ),
          streamAckDeadlineSeconds: this.settings.ackDeadline / 1000,
        });
      this.connections.set(id, connection);
    });
  }
github googleapis / nodejs-pubsub / src / subscriber.ts View on Github external
get name(): string {
    if (!this._name) {
      const {name, projectId} = this._subscription;
      this._name = replaceProjectIdToken(name, projectId);
    }

    return this._name;
  }
  /**
github googleapis / nodejs-firestore / src / index.js View on Github external
_decorateRequest(request) {
    let decoratedRequest = extend(true, {}, request);
    decoratedRequest =
        replaceProjectIdToken(decoratedRequest, this._referencePath.projectId);
    let decoratedGax = {otherArgs: {headers: {}}};
    decoratedGax.otherArgs.headers[CLOUD_RESOURCE_HEADER] = this.formattedName;

    return {request: decoratedRequest, gax: decoratedGax};
  }
github googleapis / nodejs-spanner / src / index.ts View on Github external
this.auth.getProjectId((err, projectId) => {
      if (err) {
        callback(err);
        return;
      }
      const clientName = config.client;
      if (!this.clients_.has(clientName)) {
        this.clients_.set(clientName, new gapic.v1[clientName](this.options));
      }
      const gaxClient = this.clients_.get(clientName)!;
      let reqOpts = extend(true, {}, config.reqOpts);
      reqOpts = replaceProjectIdToken(reqOpts, projectId!);
      const requestFn =
          gaxClient[config.method].bind(gaxClient, reqOpts, config.gaxOpts);
      callback(null, requestFn);
    });
  }
github googleapis / nodejs-firestore / src / index.js View on Github external
let transform = through2.obj(function(chunk, encoding, callback) {
            let decoratedChunk = extend(true, {}, chunk);
            replaceProjectIdToken(
                decoratedChunk, self._referencePath.projectId);
            logger(
                'Firestore.readWriteStream', requestTag,
                'Streaming request: %j', decoratedChunk);
            requestStream.write(decoratedChunk, encoding, callback);
          });
github googleapis / nodejs-datastore / src / request.ts View on Github external
datastore.auth.getProjectId((err, projectId) => {
      if (err) {
        callback(err);
        return;
      }

      const clientName = config.client;

      if (!datastore.clients_.has(clientName)) {
        datastore.clients_.set(
            clientName, new gapic.v1[clientName](datastore.options));
      }
      const gaxClient = datastore.clients_.get(clientName);
      reqOpts = replaceProjectIdToken(reqOpts, projectId!);
      const gaxOpts = extend(true, {}, config.gaxOpts, {
        headers: {
          'google-cloud-resource-prefix': `projects/${projectId}`,
        },
      });
      gaxClient[method](reqOpts, gaxOpts, callback);
    });
  }

@google-cloud/projectify

A simple utility for replacing the projectid token in objects.

Apache-2.0
Latest version published 9 months ago

Package Health Score

82 / 100
Full package analysis

Popular @google-cloud/projectify functions

Similar packages