How to use the grpc.ServerCredentials 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 pulumi / pulumi / examples / multilang / mycomponent / server / index.js View on Github external
// This file is the stub Node entrypoint that must be spawned by any language which wants to host JS
// components.  It should most likely live inside the JS SDK (or another JS package).

const pulumi = require("@pulumi/pulumi");
const grpc = require("grpc");
const runtimeServiceProto = require("@pulumi/pulumi/proto/runtime_grpc_pb.js");
const runtimeProto = require("@pulumi/pulumi/proto/runtime_pb.js");
const gstruct = require("google-protobuf/google/protobuf/struct_pb.js");

const server = new grpc.Server();
server.addService(runtimeServiceProto.RuntimeService, {
    construct: construct,
});
server.bind("0.0.0.0:50051", grpc.ServerCredentials.createInsecure());
server.start();

function construct(call, callback) {
    const library = require(call.request.getLibrarypath())
    const props = pulumi.runtime.deserializeProperties(call.request.getArgs());
    const opts = pulumi.runtime.deserializeProperties(call.request.getOpts());
    const res = new (library[call.request.getResource()])(call.request.getName(), props, opts);
    pulumi.runtime.serializeProperties("inner-construct", res).then(resolved => {
        return gstruct.Struct.fromJavaScript(resolved);
    }).then(outStruct => {
        const reply = new runtimeProto.ConstructResponse();
        reply.setOuts(outStruct);
        callback(null, reply)
    }, err => callback(err));
}
github strongloop / loopback-connector-grpc / test / fixtures / server.js View on Github external
function main() {
  const pkg = protoLoader.loadSync(PROTO_PATH);
  const proto = grpc.loadPackageDefinition(pkg);
  const server = new grpc.Server();
  server.addService(proto.demo.NoteService.service, {
    create: create,
    findById: findById,
    find: find,
  });
  server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  server.start();
  return server;
}
github Tubitv / envoy-node / test / lib / grpc-test-server.ts View on Github external
constructor(serverId: number, useManagedHostHeader = false) {
    super("./envoy-grpc-config.yaml", serverId, useManagedHostHeader);
    this.server = new grpc.Server();
    this.server.addService(Ping.service, {
      wrapper: wrapImpl(this.wrapper.bind(this)),
      inner: wrapImpl(this.inner.bind(this)),
      clientStream: this.clientStream.bind(this),
      serverStream: this.serverStream.bind(this),
      bidiStream: this.bidiStream.bind(this)
    });
    this.server.bind(
      `${GrpcTestServer.bindHost}:${this.servicePort}`,
      grpc.ServerCredentials.createInsecure()
    );
  }
github instana / nodejs-sensor / test / tracing / protocols / grpc / server.js View on Github external
function main() {
    server = new grpc.Server();
    server.addService(services.TestServiceService, staticServerDef);
    server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
    server.start();
  }
github GoogleCloudPlatform / cloud-ops-sandbox / src / paymentservice / server.js View on Github external
listen () {
    this.server.bind(`0.0.0.0:${this.port}`, grpc.ServerCredentials.createInsecure());
    console.log(`PaymentService grpc server listening on ${this.port}`);
    this.server.start();
  }
github vietnam-devs / coolstore-microservices / src / microservices / product-catalog-service / services / grpc-server.ts View on Github external
export default async () => {
  const server = new grpc.Server()
  const proto: any = getProto('../proto/catalog.proto').coolstore
  const healthProto: any = getProto('../proto/health.proto').grpc.health.v1

  logger.info(ProductProtoServices)
  await server.addService(proto.CatalogService.service, {
    ...ProductProtoServices
  })
  await server.addService(healthProto.Health.service, {
    ...HealthProtoServices
  })

  server.bind(`${process.env.HOST || '0.0.0.0'}:${process.env.PORT || 5002}`, grpc.ServerCredentials.createInsecure())
  server.start()
  xLogger.info(`gRPC server running on ${process.env.HOST || '0.0.0.0'}:${process.env.PORT || 5002}.`)
  xLogger.info(`Press CTRL-C to stop.`)
}
github baetyl / baetyl / baetyl-function-node8 / function-node8.js View on Github external
&& hasAttr(config['server']['message'], 'length')
        && hasAttr(config['server']['message']['length'], 'max')) {
        maxMessageSize = config['server']['message']['length']['max'];
    }
    let server = new grpc.Server({
        'grpc.max_send_message_length': maxMessageSize,
        'grpc.max_receive_message_length': maxMessageSize
    });

    let credentials = undefined;

    if (hasAttr(config.server, 'ca')
        && hasAttr(config.server, 'key')
        && hasAttr(config.server, 'cert')) {

        credentials = grpc.ServerCredentials.createSsl(
            fs.readFileSync(config['server']['ca']), [{
                cert_chain: fs.readFileSync(config['server']['cert']),
                private_key: fs.readFileSync(config['server']['key'])
            }], true);
    } else {
        credentials = grpc.ServerCredentials.createInsecure();
    }

    server.bind(config['server']['address'], credentials);
    return server;
}
github gabrielgrant / grpc-bus-websocket-proxy-server / demo / helloserver.js View on Github external
function main() {
  var server = new grpc.Server();
  server.addProtoService(hello_proto.Greeter.service, {sayHello: sayHello, streamOutHello: streamOutHello, echo: echo, concat: concat});
  server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());
  server.start();
}
github xuezier / grpc-server-ts / src / RpcRegistry.ts View on Github external
private static _addTls() {
    if (!this.ca || !this.cert || !this.key) {
        this._credentials = GRPC.ServerCredentials.createInsecure();
    } else {
        let ca = FS.readFileSync(this.ca);
        let cert = FS.readFileSync(this.cert);
        let key = FS.readFileSync(this.key);
        this._credentials = GRPC.ServerCredentials.createSsl(ca, [{
        cert_chain: cert,
        private_key: key
        }], true);
    }
  }
}
github dataform-co / dataform / server / service / index.ts View on Github external
public start() {
    this.server.addService(
      Service.DEFINITION,
      new Service.ServicePromiseWrapper(new ServiceImpl())
    );

    this.server.bind(`0.0.0.0:${this.port}`, grpc.ServerCredentials.createInsecure());
    this.server.start();
  }