Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function main() {
const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure());
const meta = new grpc.Metadata();
meta.add('key', 'value');
grpc_promise.promisifyAll(client, { metadata: meta, timeout: 1000 }); // timeout in milliseconds
client.testStreamSimple(meta)
.sendMessage({id: 1})
.sendMessage({id: 2})
.sendMessage({id: 3})
.end()
.then(res => {
console.log('Client: Simple Message Received = ', res); // Client: Simple Message Received = {id: 3}
})
.catch(err => console.error(err))
;
}
function main() {
const client = new test_proto.Test('localhost:50052', grpc.credentials.createInsecure());
const meta = new grpc.Metadata();
meta.add('key', 'value');
grpc_promise.promisifyAll(client, { metadata: meta, timeout: 1000 }); // timeout in milliseconds
client.testSimpleStream()
.sendMessage({id: 1})
.then(res => {
console.log('Client: Stream Message Received = ', res); // Client: Stream Message Received = [{id: 1}, {id: 1}]
})
.catch(err => console.error(err))
;
}
// We do not require a macaroon to be available to use the lnd-engine, as the user
// may have used the configuration `--no-macaroons` for testing.
//
// A macaroon will not be created if:
// 1. An LND wallet hasn't been initialized (NEEDS_WALLET or UNKNOWN): expected
// 2. The daemon/docker has messed up: unexpected
const showMacaroonWarn = ![ ENGINE_STATUSES.UNKNOWN, ENGINE_STATUSES.NEEDS_WALLET ].includes(status)
if (!macaroonExists) {
if (showMacaroonWarn) {
logger.warn(`LND-ENGINE warning - macaroon not found at path: ${macaroonPath}`)
}
rpcCredentials = grpc.credentials.createSsl(tls)
} else {
const macaroon = fs.readFileSync(macaroonPath)
const metadata = new grpc.Metadata()
metadata.add('macaroon', macaroon.toString('hex'))
const macaroonCredentials = grpc.credentials.createFromMetadataGenerator((_, cb) => cb(null, metadata))
const sslCredentials = grpc.credentials.createSsl(tls)
rpcCredentials = grpc.credentials.combineChannelCredentials(sslCredentials, macaroonCredentials)
}
const client = new lnrpc.Lightning(host, rpcCredentials, {})
client.invoices = new invoicesrpc.Invoices(host, rpcCredentials, {})
client.router = new routerrpc.Router(host, rpcCredentials, {})
return client
}
function GrpcService(config, options) {
if (global.GCLOUD_SANDBOX_ENV) {
// gRPC has a tendency to cause our doc unit tests to fail, so we prevent
// any calls to that library from going through.
// Reference: https://github.com/GoogleCloudPlatform/google-cloud-node/pull/1137#issuecomment-193315047
return global.GCLOUD_SANDBOX_ENV;
}
Service.call(this, config, options);
if (config.customEndpoint) {
this.grpcCredentials = grpc.credentials.createInsecure();
}
this.grpcMetadata = new grpc.Metadata();
this.grpcMetadata.add('x-goog-api-client', [
'gl-node/' + process.versions.node,
'gccl/' + config.packageJson.version,
'grpc/' + require('grpc/package.json').version
].join(' '));
if (config.grpcMetadata) {
for (var prop in config.grpcMetadata) {
if (config.grpcMetadata.hasOwnProperty(prop)) {
this.grpcMetadata.add(prop, config.grpcMetadata[prop]);
}
}
}
this.maxRetries = options.maxRetries;
function getEchoTrailer(call) {
var echo_trailer = call.metadata.get(ECHO_TRAILING_KEY);
var response_trailer = new grpc.Metadata();
if (echo_trailer.length > 0) {
response_trailer.set(ECHO_TRAILING_KEY, echo_trailer[0]);
}
return response_trailer;
}
const getMacaroonMeta = (name) => {
const macaroonFile = path.join(settings.get.lndPath, name, MACAROON_FILE);
const metadata = new grpc.Metadata();
const macaroonHex = fs.readFileSync(macaroonFile).toString("hex");
metadata.add("macaroon", macaroonHex);
return metadata;
};
private async getAuthToken() {
let metadata
if (this.oAuth) {
const token = await this.oAuth.getToken()
metadata = new Metadata()
metadata.add('Authorization', `Bearer ${token}`)
}
if (this.basicAuth) {
const token = Buffer.from(
`${this.basicAuth.username}:${this.basicAuth.password}`
).toString('base64')
metadata = new Metadata()
metadata.add('Authorization', `Basic ${token}`)
}
return metadata
}
var macaroonCreds = grpc.credentials.createFromMetadataGenerator(function (args, callback) {
const adminMacaroon = fs.readFileSync(macaroonPath);
const metadata = new grpc.Metadata();
metadata.add("macaroon", adminMacaroon.toString("hex"));
callback(null, metadata);
});
credentials = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
function createMacaroonCreds(macaroon) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
let macaroonCreds = grpc.credentials.createFromMetadataGenerator((params, callback) =>
callback(null, metadata)
);
return macaroonCreds;
}