How to use the grpc.Metadata function in grpc

To help you get started, we’ve selected a few grpc 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 carlessistare / grpc-promise / examples / client-client-stream.js View on Github external
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))
  ;
}
github carlessistare / grpc-promise / examples / client-server-stream.js View on Github external
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))
  ;
}
github sparkswap / lnd-engine / src / lnd-setup / generate-lightning-client.js View on Github external
// 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
}
github firebase / user-privacy / functions / node_modules / @google-cloud / common-grpc / src / service.js View on Github external
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;
github grpc / grpc-node / test / interop / interop_server.js View on Github external
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;
}
github LightningPeach / peach-wallet-desktop / server / binaries / Lnd.js View on Github external
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;
};
github creditsenseau / zeebe-client-node-js / src / lib / GRPCClient.ts View on Github external
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
	}
github chemicstry / recksplorer / server / lightning.js View on Github external
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);
github altangent / lnd-async / lib / lnd-rpc.js View on Github external
function createMacaroonCreds(macaroon) {
  let metadata = new grpc.Metadata();
  metadata.add('macaroon', macaroon);

  let macaroonCreds = grpc.credentials.createFromMetadataGenerator((params, callback) =>
    callback(null, metadata)
  );

  return macaroonCreds;
}