Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
constructor(config: LibralLibConfig) {
this.config = config;
if (config.host === undefined) {
// since only testnet for now
this.config.host = DefaultTestnetServerHost;
}
if (config.port === undefined) {
this.config.port = '80';
}
const connectionAddress = `${this.config.host}:${this.config.port}`;
this.client = new AdmissionControlClient(connectionAddress, credentials.createInsecure());
}
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,
/**
constructor(address: string, ctx: EnvoyContext | Metadata | HttpHeader) {
let envoyContext: EnvoyContext;
if (ctx instanceof EnvoyContext) {
envoyContext = ctx;
} else {
envoyContext = new EnvoyContext(ctx);
}
const actualAddr = envoyContext.shouldCallWithoutEnvoy(address)
? address
: `${envoyContext.envoyEgressAddr}:${envoyContext.envoyEgressPort}`;
super(actualAddr, credentials.createInsecure(), { channelFactoryOverride });
this.originalAddress = address;
this.envoyContext = envoyContext;
}
} as EnvoyClientConstructor;
});
const productsPackageDefinition = protoLoader.loadSync(PRODUCTS_PROTO_PATH, {
keepCase: false,
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const orders: any = loadPackageDefinition(ordersPackageDefinition).orders;
const products: any = loadPackageDefinition(productsPackageDefinition).products;
const ordersStub = new orders.orders(
`${ORDERS_SERVICE}`,
credentials.createInsecure(),
);
const productsStub = new products.products(
`${PRODUCTS_SERVICE}`,
credentials.createInsecure(),
);
const ordersGrpcClient: any = promisifyAll(ordersStub);
const productsGrpcClient: any = promisifyAll(productsStub);
export { ordersGrpcClient, productsGrpcClient };
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),
export function initAdmissionControlClient(connectionAddress: string): AdmissionControlClient {
return new AdmissionControlClient(connectionAddress, credentials.createInsecure());
}
longs: String,
enums: String,
defaults: true,
oneofs: true,
});
const orders: any = loadPackageDefinition(ordersPackageDefinition).orders;
const products: any = loadPackageDefinition(productsPackageDefinition).products;
const ordersStub = new orders.orders(
`${ORDERS_SERVICE}`,
credentials.createInsecure(),
);
const productsStub = new products.products(
`${PRODUCTS_SERVICE}`,
credentials.createInsecure(),
);
const ordersGrpcClient: any = promisifyAll(ordersStub);
const productsGrpcClient: any = promisifyAll(productsStub);
export { ordersGrpcClient, productsGrpcClient };
.then(hosts => new ClientConstructor(hosts[0], credentials.createInsecure()))
.catch(err => {
function createClient() {
const packageDefinition = loadSync('modules/grpc-engine/grpc-engine.proto', {});
const grpcEngineProto = loadPackageDefinition(packageDefinition).grpcengine;
const client = new grpcEngineProto.SSR('localhost:9090', credentials.createInsecure());
return client;
}