Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI and Client & Agent Service test splitting #311

Merged
merged 16 commits into from
Feb 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,10 @@ class PolykeyAgent {
this.gestaltGraph = gestaltGraph;
this.fwdProxy = fwdProxy;
this.revProxy = revProxy;
this.discovery = discovery;
this.nodeGraph = nodeGraph;
this.nodeConnectionManager = nodeConnectionManager;
this.nodeManager = nodeManager;
this.discovery = discovery;
this.vaultManager = vaultManager;
this.notificationsManager = notificationsManager;
this.sessionManager = sessionManager;
Expand All @@ -516,8 +516,8 @@ class PolykeyAgent {
try {
this.logger.info(`Starting ${this.constructor.name}`);
// Set up error handling for event handlers
this.events[captureRejectionSymbol] = (err, event) => {
let msg = `EventBus error for ${event}`;
this.events[captureRejectionSymbol] = (err, event: symbol) => {
let msg = `EventBus error for ${event.toString()}`;
if (err instanceof errors.ErrorPolykey) {
msg += `: ${err.name}: ${err.description}`;
if (err.message !== '') {
Expand Down Expand Up @@ -617,8 +617,8 @@ class PolykeyAgent {
tlsConfig,
});
await this.revProxy.start({
serverHost: this.grpcServerAgent.host,
serverPort: this.grpcServerAgent.port,
serverHost: this.grpcServerAgent.getHost(),
serverPort: this.grpcServerAgent.getPort(),
ingressHost: networkConfig_.ingressHost,
ingressPort: networkConfig_.ingressPort,
tlsConfig,
Expand All @@ -633,8 +633,8 @@ class PolykeyAgent {
await this.status.finishStart({
pid: process.pid,
nodeId: this.keyManager.getNodeId(),
clientHost: this.grpcServerClient.host,
clientPort: this.grpcServerClient.port,
clientHost: this.grpcServerClient.getHost(),
clientPort: this.grpcServerClient.getPort(),
ingressHost: this.revProxy.getIngressHost(),
ingressPort: this.revProxy.getIngressPort(),
});
Expand Down Expand Up @@ -672,9 +672,9 @@ class PolykeyAgent {
await this.sessionManager.stop();
await this.notificationsManager.stop();
await this.vaultManager.stop();
await this.discovery.stop();
await this.nodeConnectionManager.stop();
await this.nodeGraph.stop();
await this.discovery.stop();
await this.revProxy.stop();
await this.fwdProxy.stop();
await this.grpcServerAgent.stop();
Expand All @@ -698,8 +698,8 @@ class PolykeyAgent {
await this.sessionManager.destroy();
await this.notificationsManager.destroy();
await this.vaultManager.destroy();
await this.nodeGraph.destroy();
await this.discovery.destroy();
await this.nodeGraph.destroy();
await this.gestaltGraph.destroy();
await this.acl.destroy();
await this.sigchain.destroy();
Expand Down
6 changes: 5 additions & 1 deletion src/bin/identities/CommandAllow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class CommandAllow extends CommandPolykey {
'Node ID or `Provider ID:Identity ID`',
binParsers.parseGestaltId,
);
this.argument('<permissions>', 'permission to set');
this.argument(
'<permissions>',
'Permission to set',
binParsers.parseGestaltAction,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
Expand Down
13 changes: 11 additions & 2 deletions src/bin/identities/CommandAuthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type PolykeyClient from '../../PolykeyClient';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
import * as parsers from '../utils/parsers';
import * as binProcessors from '../utils/processors';
import * as identitiesUtils from '../../identities/utils';

Expand All @@ -10,8 +11,16 @@ class CommandAuthenticate extends CommandPolykey {
super(...args);
this.name('authenticate');
this.description('Authenticate a Digital Identity Provider');
this.argument('<providerId>', 'Name of the digital identity provider');
this.argument('<identityId>', 'Digital identity to authenticate');
this.argument(
'<providerId>',
'Name of the digital identity provider',
parsers.parseProviderId,
);
this.argument(
'<identityId>',
'Digital identity to authenticate',
parsers.parseIdentityId,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
Expand Down
13 changes: 11 additions & 2 deletions src/bin/identities/CommandClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import type PolykeyClient from '../../PolykeyClient';
import CommandPolykey from '../CommandPolykey';
import * as binUtils from '../utils';
import * as binOptions from '../utils/options';
import * as parsers from '../utils/parsers';
import * as binProcessors from '../utils/processors';

class CommandClaim extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('claim');
this.description('Claim a Digital Identity for this Keynode');
this.argument('<providerId>', 'Name of the digital identity provider');
this.argument('<identityId>', 'Digital identity to claim');
this.argument(
'<providerId>',
'Name of the digital identity provider',
parsers.parseProviderId,
);
this.argument(
'<identityId>',
'Digital identity to claim',
parsers.parseIdentityId,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
Expand Down
6 changes: 5 additions & 1 deletion src/bin/identities/CommandDisallow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ class CommandDisallow extends CommandPolykey {
'Node ID or `Provider Id:Identity Id`',
parsers.parseGestaltId,
);
this.argument('<permissions>', 'Permission to unset');
this.argument(
'<permissions>',
'Permission to unset',
parsers.parseGestaltAction,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
Expand Down
6 changes: 4 additions & 2 deletions src/bin/identities/CommandPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ class CommandPermissions extends CommandPolykey {
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Permissions: ${actions}`],
type: options.format === 'json' ? 'json' : 'dict',
data: {
permissions: actions,
},
}),
);
} finally {
Expand Down
9 changes: 4 additions & 5 deletions src/bin/identities/CommandSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ class CommandSearch extends CommandPolykey {
this.option(
'-pi, --provider-id [providerId...]',
'Digital identity provider(s) to search on',
parsers.parseProviderIdList,
);
this.option(
'-aii, --auth-identity-id, [authIdentityId]',
'-aii, --auth-identity-id [authIdentityId]',
'Name of your own authenticated identity to find connected identities of',
parsers.parseIdentityId,
);
Expand Down Expand Up @@ -87,11 +86,11 @@ class CommandSearch extends CommandPolykey {
providerSearchMessage.setDisconnected(true);
}
if (options.limit) {
providerSearchMessage.setLimit(options.limit);
providerSearchMessage.setLimit(options.limit.toString());
}
await binUtils.retryAuthentication(async (auth) => {
if (options.identity) {
providerSearchMessage.setIdentityId(options.identity);
if (options.identityId) {
providerSearchMessage.setIdentityId(options.identityId);
genReadable = pkClient.grpcClient.identitiesInfoGet(
providerSearchMessage,
auth,
Expand Down
9 changes: 8 additions & 1 deletion src/bin/keys/CommandCert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,17 @@ class CommandCert extends CommandPolykey {
(auth) => pkClient.grpcClient.keysCertsGet(emptyMessage, auth),
meta,
);
const result = {
cert: response.getCert(),
};
let output: any = result;
if (options.format === 'human') {
output = [`Root certificate:\t\t${result.cert}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Root certificate:\t\t${response.getCert()}`],
data: output,
}),
);
} finally {
Expand Down
11 changes: 9 additions & 2 deletions src/bin/keys/CommandCertchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,21 @@ class CommandsCertchain extends CommandPolykey {
auth,
);
for await (const cert of stream) {
data.push(`Certificate:\t\t${cert.getCert()}`);
data.push(cert.getCert());
}
return data;
}, meta);
const result = {
certchain: data,
};
let output: any = result;
if (options.format === 'human') {
output = [`Root Certificate Chain:\t\t${result.certchain}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: data,
data: output,
}),
);
} finally {
Expand Down
9 changes: 8 additions & 1 deletion src/bin/keys/CommandDecrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ class CommandDecrypt extends CommandPolykey {
(auth) => pkClient.grpcClient.keysDecrypt(cryptoMessage, auth),
meta,
);
const result = {
decryptedData: response.getData(),
};
let output: any = result;
if (options.format === 'human') {
output = [`Decrypted data:\t\t${result.decryptedData}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Decrypted data:\t\t${response.getData()}`],
data: output,
}),
);
} finally {
Expand Down
9 changes: 8 additions & 1 deletion src/bin/keys/CommandEncrypt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ class CommandEncypt extends CommandPolykey {
(auth) => pkClient.grpcClient.keysEncrypt(cryptoMessage, auth),
meta,
);
const result = {
encryptedData: response.getData(),
};
let output: any = result;
if (options.format === 'human') {
output = [`Encrypted data:\t\t${result.encryptedData}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Encrypted data:\t\t${response.getData()}`],
data: output,
}),
);
} finally {
Expand Down
21 changes: 12 additions & 9 deletions src/bin/keys/CommandRoot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,23 @@ class CommandRoot extends CommandPolykey {
(auth) => pkClient.grpcClient.keysKeyPairRoot(emptyMessage, auth),
meta,
);
const result: any = {
publicKey: keyPair.getPublic(),
};
if (options.privateKey) result.privateKey = keyPair.getPrivate();
let output: any = result;
if (options.format === 'human') {
output = [`Public key:\t\t${result.publicKey}`];
if (options.privateKey) {
output.push(`Private key:\t\t${result.private}`);
}
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`public key:\t\t${keyPair.getPublic()}...`],
data: output,
}),
);
if (options.privateKey) {
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`private key:\t\t${keyPair.getPrivate()}...`],
}),
);
}
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
9 changes: 8 additions & 1 deletion src/bin/keys/CommandSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,17 @@ class CommandSign extends CommandPolykey {
(auth) => pkClient.grpcClient.keysSign(cryptoMessage, auth),
meta,
);
const result = {
signature: response.getSignature(),
};
let output: any = result;
if (options.format === 'human') {
output = [`Signature:\t\t${result.signature}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Signature:\t\t${response.getSignature()}`],
data: output,
}),
);
} finally {
Expand Down
9 changes: 8 additions & 1 deletion src/bin/keys/CommandVerify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ class CommandVerify extends CommandPolykey {
(auth) => pkClient.grpcClient.keysVerify(cryptoMessage, auth),
meta,
);
const result = {
signatureVerified: response.getSuccess(),
};
let output: any = result;
if (options.format === 'human') {
output = [`Signature verified:\t\t${result.signatureVerified}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Signature verification:\t\t${response.getSuccess()}`],
data: output,
}),
);
} finally {
Expand Down
42 changes: 3 additions & 39 deletions src/bin/notifications/CommandRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,47 +115,11 @@ class CommandRead extends CommandPolykey {
notificationsUtils.validateNotification(notification),
);
}
if (notifications.length === 0) {
for (const notification of notifications) {
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`No notifications to display`],
}),
);
} else {
const output: any = [];
let notifCount = 1;
for (const notification of notifications) {
output.push(`${notifCount} - `);
switch (notification.data.type) {
case 'General': {
output.push(
`Message from Keynode with ID ${notification.senderId}: ${notification.data.message}`,
);
output.push('');
break;
}
case 'GestaltInvite': {
output.push(
`Keynode with ID ${notification.senderId} has invited you to join their Gestalt. Type the following command to accept their invitation: nodes claim ${notification.senderId}`,
);
output.push('');
break;
}
case 'VaultShare': {
output.push(
`Keynode with ID ${notification.senderId} has shared their vault '${notification.data.vaultName}' with you.`,
);
output.push('');
break;
}
}
notifCount++;
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
type: options.format === 'json' ? 'json' : 'dict',
data: notification,
}),
);
}
Expand Down
Loading