Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
;
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;
}
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 };
}
// 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
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);
}
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)
})
}
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) {
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);
});
};
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());
}