How to use the grpc.credentials.createSsl 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 creditsenseau / zeebe-client-node-js / src / lib / GRPCClient.ts View on Github external
pollInterval: this.longPoll!,
			stdout,
			taskType: tasktype,
		})
		this.packageDefinition = loadSync(protoPath, {
			defaults: options.defaults === undefined ? true : options.defaults,
			enums: options.enums === undefined ? String : options.enums,
			keepCase: options.keepCase === undefined ? true : options.keepCase,
			longs: options.longs === undefined ? String : options.longs,
			oneofs: options.oneofs === undefined ? true : options.oneofs,
		})

		const proto = loadPackageDefinition(this.packageDefinition)[packageName]
		const listMethods = this.packageDefinition[`${packageName}.${service}`]
		const channelCredentials = useTLS
			? credentials.createSsl()
			: credentials.createInsecure()
		// Options documented here: https://github.com/grpc/grpc/blob/master/include/grpc/impl/codegen/grpc_types.h
		this.client = new proto[service](host, channelCredentials, {
			/**
			 * If set to zero, disables retry behavior.
			 * Otherwise, transparent retries are enabled for all RPCs,
			 * and configurable retries are enabled when they are configured
			 * via the service config. For details, see:
			 * https://github.com/grpc/proposal/blob/master/A6-client-retries.md
			 */
			'grpc.enable_retries': 1,
			/**
			 * The time between the first and second connection attempts,
			 * in ms
			 */
			'grpc.initial_reconnect_backoff_ms': 1000,
github sparkswap / broker / broker-daemon / relayer / relayer-client.js View on Github external
constructor ({ privKeyPath, pubKeyPath }, { certPath, host = 'localhost:28492' }, logger = consoleLogger) {
    this.logger = logger
    this.address = host
    this.proto = loadProto(path.resolve(RELAYER_PROTO_PATH))
    this.identity = Identity.load(privKeyPath, pubKeyPath)

    let channelCredentials = credentials.createSsl()

    if (!PRODUCTION) {
      logger.info('Using local certs for relayer client', { production: PRODUCTION })
      channelCredentials = credentials.createSsl(readFileSync(certPath))
    }

    this.credentials = channelCredentials
    const options = { interceptors: [grpcDeadlineInterceptor] }

    const orderServiceClient = new this.proto.OrderService(
      this.address, this.credentials, GRPC_STREAM_OPTIONS)
    this.orderService = caller.wrap(orderServiceClient, {}, options)

    const makerServiceClient = new this.proto.MakerService(
      this.address, this.credentials, GRPC_STREAM_OPTIONS)
    this.makerService = caller.wrap(makerServiceClient, {}, options)

    const takerServiceClient = new this.proto.TakerService(
      this.address, this.credentials, GRPC_STREAM_OPTIONS)
    this.takerService = caller.wrap(takerServiceClient, {}, options)
github uw-labs / bloomrpc / app / behaviour / sendRequest.ts View on Github external
private getClient(serviceClient: any): grpc.Client {
    let creds = credentials.createInsecure();
    let options = {};

    if (this.tlsCertificate) {
      if (this.tlsCertificate.sslTargetHost) {
        options = {
          ...options,
          'grpc.ssl_target_name_override' : this.tlsCertificate.sslTargetHost,
          'grpc.default_authority': this.tlsCertificate.sslTargetHost,
        }
      }
      if(this.tlsCertificate.useServerCertificate === true) {
        creds = credentials.createSsl();
      } else {
        creds = credentials.createSsl(
            fs.readFileSync(this.tlsCertificate.rootCert.filePath),
            this.tlsCertificate.privateKey && fs.readFileSync(this.tlsCertificate.privateKey.filePath),
            this.tlsCertificate.certChain && fs.readFileSync(this.tlsCertificate.certChain.filePath),
        );
      }
    }

    return new serviceClient(this.url, creds, options);
  }
github sparkswap / broker / broker-daemon / relayer / relayer-client.js View on Github external
constructor ({ privKeyPath, pubKeyPath }, { certPath, host = 'localhost:28492' }, logger = consoleLogger) {
    this.logger = logger
    this.address = host
    this.proto = loadProto(path.resolve(RELAYER_PROTO_PATH))
    this.identity = Identity.load(privKeyPath, pubKeyPath)

    let channelCredentials = credentials.createSsl()

    if (!PRODUCTION) {
      logger.info('Using local certs for relayer client', { production: PRODUCTION })
      channelCredentials = credentials.createSsl(readFileSync(certPath))
    }

    this.credentials = channelCredentials
    const options = { interceptors: [grpcDeadlineInterceptor] }

    const orderServiceClient = new this.proto.OrderService(
      this.address, this.credentials, GRPC_STREAM_OPTIONS)
    this.orderService = caller.wrap(orderServiceClient, {}, options)

    const makerServiceClient = new this.proto.MakerService(
      this.address, this.credentials, GRPC_STREAM_OPTIONS)
    this.makerService = caller.wrap(makerServiceClient, {}, options)
github uw-labs / bloomrpc / app / behaviour / sendRequest.ts View on Github external
private getClient(serviceClient: any): grpc.Client {
    let creds = credentials.createInsecure();
    let options = {};

    if (this.tlsCertificate) {
      if (this.tlsCertificate.sslTargetHost) {
        options = {
          ...options,
          'grpc.ssl_target_name_override' : this.tlsCertificate.sslTargetHost,
          'grpc.default_authority': this.tlsCertificate.sslTargetHost,
        }
      }
      if(this.tlsCertificate.useServerCertificate === true) {
        creds = credentials.createSsl();
      } else {
        creds = credentials.createSsl(
            fs.readFileSync(this.tlsCertificate.rootCert.filePath),
            this.tlsCertificate.privateKey && fs.readFileSync(this.tlsCertificate.privateKey.filePath),
            this.tlsCertificate.certChain && fs.readFileSync(this.tlsCertificate.certChain.filePath),
        );
      }
    }

    return new serviceClient(this.url, creds, options);
  }