Skip to content

Instantly share code, notes, and snippets.

@shibafu528
Created June 21, 2020 17:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shibafu528/614cc080d0d4d498e61fa8407c7aa321 to your computer and use it in GitHub Desktop.
Save shibafu528/614cc080d0d4d498e61fa8407c7aa321 to your computer and use it in GitHub Desktop.
console.log(JSON.stringify(request));
console.log(JSON.stringify(imports));
console.log(JSON.stringify(server));
const args = [];
// -d
args.push('-d');
args.push(`'${request.body.replace(/\n/g, '')}'`);
// -H
for (const key in request.metadata) {
args.push('-H');
args.push(`"${key}: ${request.metadata[key]}"`);
}
// -import-path
for (const path of imports) {
args.push('-import-path');
args.push(`"${path}"`);
}
if (imports.length === 0) {
const idx = request.protoFile.lastIndexOf('/');
const dir = request.protoFile.substring(0, idx);
args.push('-import-path');
args.push(`"${dir}"`);
}
// -proto
args.push('-proto');
args.push(`"${request.protoFile}"`);
// server
if (server.useTLS) {
if (server.certificate.rootCerts) {
args.push('-cacert');
args.push(`${server.certificate.rootCerts}`);
}
if (server.certificate.privateKey) {
args.push('-key');
args.push(`${server.certificate.privateKey}`);
}
if (server.certificate.certChain) {
args.push('-cert');
args.push(`${server.certificate.certChain}`);
}
} else {
args.push('-plaintext');
}
args.push(server.address);
const path = request.path.startsWith('/') ? request.path.substring(1) : request.path;
args.push(path);
`grpcurl ${args.join(' ')}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment