Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
};
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.')
);
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);
});
}
get name(): string {
if (!this._name) {
const {name, projectId} = this._subscription;
this._name = replaceProjectIdToken(name, projectId);
}
return this._name;
}
/**
_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};
}
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);
});
}
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);
});
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);
});
}