How to use the grpc.credentials 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 iotexproject / iotex-antenna / src / rpc-method / node-rpc-method.ts View on Github external
constructor(hostname: string, options: Opts = {}) {
    const normalizedHostname = String(hostname).replace(
      /^(http:\/\/|https:\/\/)/,
      ""
    );
    if (hostname.startsWith("https://")) {
      options.enableSsl = true;
    }
    this.credentials =
      options && options.enableSsl
        ? grpc.credentials.createSsl(Buffer.from(ROOT_CERTS))
        : grpc.credentials.createInsecure();
    // @ts-ignore
    this.client = new iotexapi.APIService(
      normalizedHostname,
      this.credentials,
      null
    );
    this.timeout = options.timeout || 300000;
  }
github projectriff / node-function-invoker / spec / grpc-protocol.spec.js View on Github external
function makeLocalServer(fn) {
    const argumentTransformer = argumentTransformers[fn.$argumentType || 'payload'];
    const interactionModel = interactionModels[fn.$interactionModel || 'request-reply'];
    const server = makeServer(fn, interactionModel, argumentTransformer);

    // TODO figure out why resuing the same port fails after three test cases
    const address = `${HOST}:${++port}`;

    server.bind(address, grpc.ServerCredentials.createInsecure());
    server.start();

    const client = new FunctionInvokerClient(address, grpc.credentials.createInsecure());

    return { client, server };
}
github GroaJS / groa / lib / client.js View on Github external
// Getting instance
		let instance = this.instances[servicePath];
		if (instance !== undefined)
			return instance;

		// Getting service class
		let service = this.services[servicePath];
		if (service === undefined) {
			return null;
		}

		// Getting existing connection
		let connection = this.connections[servicePath];
		if (connection === undefined) {
			connection = this.connections[servicePath] = new service(this.host + ':' + this.port, grpc.credentials.createInsecure());
		}

		instance = this.instances[servicePath] = Object.entries(service.service).reduce((result, [ method, value ]) => {

			// Stream
			if (value.responseStream || value.requestStream) {
				let func = result[method] = function(...args) {
					return connection[method].apply(connection, args);
				};

				func.info = value;

				return result;
			}

			// Normal RPC
github TinkoffCreditSystems / voicekit-examples / nodejs / common.js View on Github external
function createAuthCredentials() {
    const apiKey = process.env.VOICEKIT_API_KEY;
    const secretKey = process.env.VOICEKIT_SECRET_KEY;
    if (apiKey == null || secretKey == null) {
        console.error("No VOICEKIT_API_KEY or VOICEKIT_SECRET_KEY environment variable defined");
        process.exit(1);
    }

    const channelCredentials = grpcLibrary.credentials.createSsl();
    const callCredentials = grpcLibrary.credentials.createFromMetadataGenerator(
        auth.jwtMetadataGenerator(apiKey, secretKey, "test_issuer", "test_subject"));

    return grpcLibrary.credentials.combineChannelCredentials(channelCredentials, callCredentials);
}
github prisma / photonjs / examples / typescript / grpc / client / post.ts View on Github external
function main() {
  const client = new blog.Blog(
    'localhost:50051',
    grpc.credentials.createInsecure(),
  )

  const id = ''
  client.post({ id }, (err: any, response: any) => {
    if (err) {
      console.error(err)
      return
    }
    console.log(response)
  })
}
github hyperledger / caliper / src / adapters / iroha / iroha.js View on Github external
if(fakeContracts.hasOwnProperty(id)) {
                                logger.warn('WARNING: multiple callbacks for ' + id + ' have been found');
                            }
                            else {
                                fakeContracts[id] = factory.contracts[id];
                            }
                        }
                    }
                }

                let node = this._findNode();
                contexts[args.id].torii = node.torii;
                contexts[args.id].contract = fakeContracts;
            }

            this.grpcCommandClient = new endpointGrpc.CommandServiceClient(contexts[args.id].torii, grpc.credentials.createInsecure());
            this.grpcQueryClient   = new endpointGrpc.QueryServiceClient(contexts[args.id].torii, grpc.credentials.createInsecure());
            this.statusWaiting     = {};
            let self = this;
            const getStatus = function() {
                for(let key in self.statusWaiting) {
                    (function(id) {
                        let item   = self.statusWaiting[id];
                        let status = item.status;
                        let timeElapse =  Date.now() - status.GetTimeCreate();
                        if(timeElapse > status.Get('timeout')) {
                            logger.warn('Timeout when querying transaction\'s status');
                            status.SetStatusFail();
                            item.resolve(status);
                            delete self.statusWaiting[id];
                        }
                        else if(!item.isquery) {
github googleapis / google-cloud-node / packages / common-grpc / src / service.js View on Github external
this.authClient.getAuthClient(function(err, authClient) {
    if (err) {
      callback(err);
      return;
    }

    var credentials = grpc.credentials.combineChannelCredentials(
      grpc.credentials.createSsl(),
      grpc.credentials.createFromGoogleCredential(authClient)
    );

    if (!self.projectId || self.projectId === '{{projectId}}') {
      self.projectId = self.authClient.projectId;
    }

    callback(null, credentials);
  });
};
github SkyAPM / SkyAPM-nodejs / modules / nodejs-agent / lib / services / application-register-service.js View on Github external
function AppAndInstanceDiscoveryService(directServers) {
  this._directServers = directServers;
  this._processUUID = uuid();
  this._applicationRegisterServiceStub = new ApplicationRegisterService.ApplicationRegisterServiceClient(
      this._directServers,
      grpc.credentials.createInsecure());
  this._instanceDiscoveryServiceStub = new DiscoveryService.InstanceDiscoveryServiceClient(this._directServers,
      grpc.credentials.createInsecure());
}