How to use the @grpc/grpc-js.credentials function in @grpc/grpc-js

To help you get started, we’ve selected a few @grpc/grpc-js 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 cjihrig / grpc-server-js / test / server.js View on Github external
const Assert = require('assert');
const Fs = require('fs');
const Http2 = require('http2');
const Path = require('path');
const Barrier = require('cb-barrier');
const Lab = require('@hapi/lab');
const Grpc = require('@grpc/grpc-js');
const { Server, ServerCredentials } = require('../lib');
const { loadProtoFile } = require('./common');

// Test shortcuts
const lab = exports.lab = Lab.script();
const { describe, it, before, after, beforeEach, afterEach } = lab;


const clientInsecureCreds = Grpc.credentials.createInsecure();
const serverInsecureCreds = ServerCredentials.createInsecure();


describe('Server', () => {
  describe('constructor', () => {
    it('should work with no arguments', () => {
      Assert.doesNotThrow(() => {
        new Server(); // eslint-disable-line no-new
      });
    });

    it('should work with an empty object argument', () => {
      const options = {};

      Assert.doesNotThrow(() => {
        new Server(options); // eslint-disable-line no-new
github googleapis / nodejs-pubsub / test / pubsub.ts View on Github external
import {CallOptions, ChannelCredentials, ServiceError} from '@grpc/grpc-js';
import * as proxyquire from 'proxyquire';
import * as sinon from 'sinon';

import {google} from '../proto/pubsub';
import * as pubsubTypes from '../src/pubsub';
import {Snapshot} from '../src/snapshot';
import * as subby from '../src/subscription';
import {Topic} from '../src/topic';
import * as util from '../src/util';

const PKG = require('../../package.json');
const sandbox = sinon.createSandbox();

const fakeCreds = {} as ChannelCredentials;
sandbox.stub(grpc.credentials, 'createInsecure').returns(fakeCreds);

const subscriptionCached = subby.Subscription;

// tslint:disable-next-line no-any
let subscriptionOverride: any;

function Subscription(
  pubsub: pubsubTypes.PubSub,
  name: string,
  options: subby.SubscriptionOptions
) {
  const overrideFn = subscriptionOverride || subscriptionCached;
  return new overrideFn(pubsub, name, options);
}

let promisified = false;
github ablehq / firestore-explorer / firebase-proxy / src / controllers / LocalHelper.ts View on Github external
import { LocalQuery } from "../models/Commands";
import { Firestore } from "@google-cloud/firestore";
const grpc = require("@grpc/grpc-js");
// Create a new client
const firestore = new Firestore({
  servicePath: "localhost",
  port: 8080,
  projectId: "firebase-explorer-test",
  sslCreds: grpc.credentials.createInsecure(),
  customHeaders: {
    Authorization: "Bearer owner"
  }
});

export const handleLocalQuery = async (query: LocalQuery) => {
  let data: { [key: string]: any } = {};
  const db = firestore;
  const result = await db.doc("movies/60756").get();
  const collections = await result.ref.listCollections();
  console.log(collections);
  data["success"] = true;
  data["data"] = {
    id: result.id,
    path: result.ref.path,
    data: result.data()
github mozilla / fxa / packages / fxa-event-broker / bin / workerDev.ts View on Github external
.createQueue({
          QueueName: queueName
        })
        .promise();
    }

    // Utilize the local firestore emulator if we were told to use it
    if (firestoreEnabled && NODE_ENV === 'development') {
      const fstore = new Firestore({
        customHeaders: {
          Authorization: 'Bearer owner'
        },
        port: 8006,
        projectId: 'fx-event-broker',
        servicePath: 'localhost',
        sslCreds: grpc.credentials.createInsecure()
      });
      db = new FirestoreDatastore(firestoreConfig, fstore);
    }
  } catch (err) {
    logger.error('Error loading application:', { err });
    process.exit(1);
  }

  const capabilityService = new ClientCapabilityService(
    logger,
    Config.get('clientCapabilityFetch')
  );
  const webhookService = new ClientWebhookService(
    logger,
    Config.get('clientCapabilityFetch.refreshInterval'),
    db
github hyperledger / burrow / js / src / lib / burrow.ts View on Github external
function newClient(pkg: string, service: string, URL: string): T {
  const imp = require(`../../proto/${pkg}_grpc_pb`);
  // As per https://github.com/agreatfool/grpc_tools_node_protoc_ts/blob/master/examples/src/grpcjs/client.ts
  const cons = makeClientConstructor(imp[`${pkg}.${service}`], service);
  // ugh
  return new cons(URL, grpc.credentials.createInsecure()) as unknown as T
}
github maierj / fastlane-action / .github / actions / statistics-chart-action / node_modules / @google-cloud / firestore / build / src / index.js View on Github external
/* clientFactory= */ () => {
            let client;
            if (this._settings.ssl === false) {
                const grpc = require('@grpc/grpc-js');
                const sslCreds = grpc.credentials.createInsecure();
                client = new module.exports.v1(Object.assign({ sslCreds }, this._settings));
            }
            else {
                client = new module.exports.v1(this._settings);
            }
            logger_1.logger('Firestore', null, 'Initialized Firestore GAPIC Client');
            return client;
        }, 
        /* clientDestructor= */ (client) => client.close());
github cjihrig / grpc-server-js / test / server-credentials.js View on Github external
it('should be able to use multiple plugin credentials', () => {
      function altMetadataUpdater (serviceUrl, callback) {
        const metadata = new Grpc.Metadata();

        metadata.set('other_plugin_key', 'other_plugin_value');
        callback(null, metadata);
      }

      const barrier = new Barrier(2);
      const altUpdaterCreds = Grpc.credentials.createFromMetadataGenerator(altMetadataUpdater);
      const combinedUpdater = Grpc.credentials.combineCallCredentials(updaterCreds, altUpdaterCreds);
      const call = client.unary({}, { credentials: combinedUpdater }, (err, data) => {
        Assert.ifError(err);
        barrier.pass();
      });

      call.on('metadata', (metadata) => {
        Assert.deepStrictEqual(metadata.get('plugin_key'), ['plugin_value']);
        Assert.deepStrictEqual(metadata.get('other_plugin_key'), ['other_plugin_value']);
        barrier.pass();
      });

      return barrier;
    });
  });
github googleapis / nodejs-bigtable / system-test / mutate-rows.ts View on Github external
describe('Bigtable/Table', () => {
  const bigtable = new Bigtable();
  bigtable.api = {};
  bigtable.auth = {
    getProjectId(callback) {
      callback(null, 'project-id');
    },
  };
  bigtable.grpcCredentials = grpc.credentials.createInsecure();

  const INSTANCE = bigtable.instance('instance');
  const TABLE = INSTANCE.table('table');

  describe('mutate()', () => {
    let clock;
    let mutationBatchesInvoked;
    let mutationCallTimes;
    let responses;

    beforeEach(() => {
      clock = sinon.useFakeTimers({
        toFake: ['setTimeout', 'setImmediate', 'Date', 'nextTick'],
      });
      mutationBatchesInvoked = [];
      mutationCallTimes = [];
github JustinBeckwith / cloudcats / web / catrelay.js View on Github external
function makeRequest(socket) {
	try {
		logger.info(`Requesting a run on ${apiEndpoint}...`);
		let cnt = 0;
		const client = new proto.Worker(apiEndpoint, grpc.credentials.createInsecure());
		const call = client.analyze();
		call.on('data', data => {
			logger.info('received data');
			cnt++;
			logger.info(JSON.stringify(data));
			logger.info(`MESSAGE ${cnt}: ${data.type}`);
			socket.emit('cloudcats', data);
		});
		call.on('end', () => {
			logger.info('Analyze request complete.');
			socket.emit('cloudcats', {
				type: 'FIN'
			});
		});
	} catch (error) {
		logger.error('Error making gRPC request');
github ablehq / firestore-explorer / firebase-proxy / dist / models / FirebaseProxy.js View on Github external
exports.generateFirestoreEmulatedInstance = (projectId) => {
    return new firestore_1.Firestore({
        servicePath: "localhost",
        port: 8080,
        projectId,
        sslCreds: grpc.credentials.createInsecure(),
        customHeaders: {
            Authorization: "Bearer owner"
        }
    });
};
exports.generateCloudEmulatedInstance = (server) => {