Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'nextPageToken',
'entries'
),
listMonitoredResourceDescriptors: new gax.PageDescriptor(
'pageToken',
'nextPageToken',
'resourceDescriptors'
),
listLogs: new gax.PageDescriptor(
'pageToken',
'nextPageToken',
'logNames'
),
};
var protoFilesRoot = new gax.GoogleProtoFilesRoot();
protoFilesRoot = protobuf.loadSync(
path.join(
__dirname,
'..',
'..',
'protos',
'google/logging/v2/logging.proto'
),
protoFilesRoot
);
// Some methods on this API support automatically batching
// requests; denote this.
this._descriptors.batching = {
writeLogEntries: new gax.BundleDescriptor(
'entries',
['logName', 'resource', 'labels'],
/*
* vim: ts=2:sw=2:expandtab
*/
"use strict";
const debug = require("debug")("libsignal-service:protobuf");
const ByteBuffer = require("bytebuffer");
const protobufjs = require("protobufjs");
const path = require("path");
const protobuf = protobufjs.loadSync([
path.join(__dirname, "..", "protos", "SubProtocol.proto"),
path.join(__dirname, "..", "protos", "DeviceMessages.proto"),
path.join(__dirname, "..", "protos", "SignalService.proto"),
path.join(__dirname, "..", "protos", "Stickers.proto"),
path.join(__dirname, "..", "protos", "DeviceName.proto"),
path.join(__dirname, "..", "protos", "UnidentifiedDelivery.proto")
]).root;
// Add contacts_parser.js extended types
const ContactDetails = protobuf.lookupType("signalservice.ContactDetails");
const GroupDetails = protobuf.lookupType("signalservice.GroupDetails");
class ProtoParser {
constructor(arrayBuffer, protobuf) {
this.protobuf = protobuf;
this.buffer = new ByteBuffer();
/**
* Metadata retry info key.
*
* @private
*/
const RETRY_INFO_KEY = 'google.rpc.retryinfo-bin';
/**
* Default timeout for Transactions.
*
* @private
*/
const DEFAULT_TRANSACTION_TIMEOUT = config.methods.Commit.timeout_millis;
const root = new gax.GoogleProtoFilesRoot();
const protoFilesRoot = protobuf.loadSync(
path.join(__dirname, '..', 'protos', 'google/rpc/error_details.proto'),
root);
// tslint:disable-next-line variable-name
const RetryInfo = protoFilesRoot.lookup('google.rpc.RetryInfo');
/**
* Read/write transaction options.
*
* @typedef {object} TransactionOptions
* @property {number} [timeout=3600000] Specify a timeout (in milliseconds) for
* the transaction. The transaction will be ran in its entirety, however if
* an abort error is returned the transaction will be retried if the timeout
* has not been met.
* @property {boolean} [readOnly=false] Specifies if the transaction is
* read-only.
constructor(desc, serviceName, protobufLoadOptions) {
// Protobuf may be one of the following:
// * A protobufjs root object
// * A a single protobuf file
// * Multiple protobuf files
let root;
if (Array.isArray(desc) || typeof desc === "string") {
root = protobuf.loadSync(desc, protobufLoadOptions).resolveAll();
} else if (typeof desc === "object") {
root = desc.resolveAll();
} else {
throw new Error("Unknown descriptor type: " + typeof desc)
}
this.root = root;
this.serviceName = serviceName;
// Eagerly lookup the service to fail early
this.service = root.lookupService(serviceName);
}
export async function buildTypeScript(protoFiles: string[]) {
const tempDir = await createTempDir();
try {
// Use pbjs to generate static JS code for the protobuf definitions
const jsFile = await call(tempDir.name, pbjsMain, protoFiles, 'js', ['keep-case'], {
target: 'static-module',
wrap: 'commonjs',
});
const jsonDescriptor = await call(tempDir.name, pbjsMain, protoFiles, 'js', ['keep-case'], {
target: 'json',
});
const root = protobuf.loadSync(jsonDescriptor);
const js = transformJavaScriptSource(await fs.readFile(jsFile, 'utf8'), root);
await fs.writeFile(jsFile, js);
// Create TypeScript file
const tsFile = await call(tempDir.name, pbtsMain, [jsFile], 'ts');
return transformTypeScriptSource(await fs.readFile(tsFile, 'utf8'));
} finally {
tempDir.removeCallback();
}
}
var protos = merge(
{},
gaxGrpc.loadProto(
path.join(__dirname, '..', '..', 'protos'),
'google/privacy/dlp/v2beta1/dlp.proto'
)
);
// This API contains "path templates"; forward-slash-separated
// identifiers to uniquely identify resources within the API.
// Create useful helper objects for these.
this._pathTemplates = {
resultPathTemplate: new gax.PathTemplate('inspect/results/{result}'),
};
var protoFilesRoot = new gax.grpc.GoogleProtoFilesRoot();
protoFilesRoot = protobuf.loadSync(
path.join(
__dirname,
'..',
'..',
'protos',
'google/privacy/dlp/v2beta1/dlp.proto'
),
protoFilesRoot
);
// This API contains "long-running operations", which return a
// an Operation object that allows for tracking of the operation,
// rather than holding a request open.
this.operationsClient = new gax.lro({
auth: gaxGrpc.auth,
grpc: gaxGrpc.grpc,
const protocolPath = "protocol.proto";
const grpc = require("grpc");
const protoLoader = require("@grpc/proto-loader");
const protobuf = require("protobufjs");
const packageDefinition = protoLoader.loadSync(protocolPath, {});
const descriptor = grpc.loadPackageDefinition(packageDefinition);
const protocol = protobuf.loadSync(protocolPath);
const Any = protocol.lookupType("google.protobuf.Any");
// Support for doing this exists here:
// https://github.com/protobufjs/protobuf.js/tree/master/ext/descriptor
// However that has been found to be quite buggy, so we're doing it manually.
function serviceToDescriptor(root, serviceName) {
const service = root.lookupService(serviceName);
const pkg = fullNameOf(service.parent);
const typeNames = new Set(Object.keys(service.methods).map(key => {
const requestType = service.methods[key].requestType;
if (requestType.includes(".")) {
return requestType;
} else if (pkg) {
return pkg + "." + requestType;
} else {
import * as crypto from "crypto";
import * as https from "https";
import * as path from "path";
import * as protobuf from "protobufjs";
import { Log, LogGroup, SlsOptions } from "./types";
import lz4 from "./utils/lz4";
const MessageTypes = protobuf.loadSync(path.resolve(__dirname, "../sls.proto"));
const PbLogGroup = MessageTypes.lookupType("sls.LogGroup");
const DEFAULT_BULK_SIZE = 512;
const agent = new https.Agent({
keepAlive: true,
keepAliveMsecs: 10000,
timeout: 1000,
});
class SlsProducer {
private options: SlsOptions;
private worker?: Promise;
private buffer: Log[] = [];
private resource: string;
constructor(opts: SlsOptions) {
function loadProto(filePath, typeName) {
const absPath = path.join(__dirname, '../protobuf', filePath + '.proto');
return protobuf.loadSync(absPath).lookupType(typeName);
}
public loadProto(filename: string, namespace: string) {
if (typeof this.protos[namespace] !== 'undefined') {
throw new Error(
`Proto[${namespace}] already defined and redefinition attempted in ${filename}`
);
}
let root: Root;
try {
root = protobuf.loadSync(filename);
this.protos[namespace] = root;
} catch (err) {
this.logger.error(err.message);
throw err;
}
}