Skip to content
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
10 changes: 6 additions & 4 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { FileSystem } from './types';
import type { PolykeyWorkerManagerInterface } from './workers/types';
import type { Host, Port } from './network/types';
import type { SeedNodes } from './nodes/types';

import type { RootKeyPairChangeData } from './keys/types';
import path from 'path';
import process from 'process';
Expand Down Expand Up @@ -303,6 +302,7 @@ class PolykeyAgent {
discovery =
discovery ??
(await Discovery.createDiscovery({
db,
keyManager,
gestaltGraph,
identitiesManager,
Expand Down Expand Up @@ -358,7 +358,7 @@ class PolykeyAgent {
await sessionManager?.stop();
await notificationsManager?.stop();
await vaultManager?.stop();
await discovery?.destroy();
await discovery?.stop();
await revProxy?.stop();
await fwdProxy?.stop();
await gestaltGraph?.stop();
Expand Down Expand Up @@ -626,6 +626,7 @@ class PolykeyAgent {
await this.nodeConnectionManager.start();
await this.nodeGraph.start({ fresh });
await this.nodeConnectionManager.syncNodeGraph();
await this.discovery.start({ fresh });
await this.vaultManager.start({ fresh });
await this.notificationsManager.start({ fresh });
await this.sessionManager.start({ fresh });
Expand All @@ -644,7 +645,7 @@ class PolykeyAgent {
await this.sessionManager?.stop();
await this.notificationsManager?.stop();
await this.vaultManager?.stop();
await this.discovery?.destroy();
await this.discovery?.stop();
await this.revProxy?.stop();
await this.fwdProxy?.stop();
await this.grpcServerAgent?.stop();
Expand All @@ -671,9 +672,9 @@ class PolykeyAgent {
await this.sessionManager.stop();
await this.notificationsManager.stop();
await this.vaultManager.stop();
await this.discovery.destroy();
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,6 +699,7 @@ class PolykeyAgent {
await this.notificationsManager.destroy();
await this.vaultManager.destroy();
await this.nodeGraph.destroy();
await this.discovery.destroy();
await this.gestaltGraph.destroy();
await this.acl.destroy();
await this.sigchain.destroy();
Expand Down
84 changes: 84 additions & 0 deletions src/bin/identities/CommandAuthenticated.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import type PolykeyClient from '../../PolykeyClient';
import type { IdentityId, ProviderId } from '../../identities/types';
import CommandPolykey from '../CommandPolykey';
import * as binOptions from '../utils/options';
import * as binUtils from '../utils';
import * as parsers from '../utils/parsers';
import * as binProcessors from '../utils/processors';

class CommandAuthenticated extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('authenticated');
this.description('Lists all authenticated identities across all providers');
this.option(
'-pi, --provider-id [providerId]',
'Digital identity provider to retrieve tokens from',
parsers.parseProviderId,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
this.action(async (options) => {
const { default: PolykeyClient } = await import('../../PolykeyClient');
const identitiesPB = await import(
'../../proto/js/polykey/v1/identities/identities_pb'
);
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
options.nodeId,
options.clientHost,
options.clientPort,
this.fs,
this.logger.getChild(binProcessors.processClientOptions.name),
);
const meta = await binProcessors.processAuthentication(
options.passwordFile,
this.fs,
);
let pkClient: PolykeyClient;
let genReadable: ReturnType<
typeof pkClient.grpcClient.identitiesAuthenticatedGet
>;
this.exitHandlers.handlers.push(async () => {
if (genReadable != null) genReadable.stream.cancel();
if (pkClient != null) await pkClient.stop();
});
try {
pkClient = await PolykeyClient.createPolykeyClient({
nodePath: options.nodePath,
nodeId: clientOptions.nodeId,
host: clientOptions.clientHost,
port: clientOptions.clientPort,
logger: this.logger.getChild(PolykeyClient.name),
});
const optionalProviderMessage = new identitiesPB.OptionalProvider();
if (options.providerId) {
optionalProviderMessage.setProviderId(options.providerId);
}
await binUtils.retryAuthentication(async (auth) => {
const genReadable = pkClient.grpcClient.identitiesAuthenticatedGet(
optionalProviderMessage,
auth,
);
for await (const val of genReadable) {
const output = {
providerId: val.getProviderId() as ProviderId,
identityId: val.getIdentityId() as IdentityId,
};
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'dict',
data: output,
}),
);
}
}, meta);
} finally {
if (pkClient! != null) await pkClient.stop();
}
});
}
}

export default CommandAuthenticated;
4 changes: 1 addition & 3 deletions src/bin/identities/CommandDiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ class CommandDiscover extends CommandPolykey {
constructor(...args: ConstructorParameters<typeof CommandPolykey>) {
super(...args);
this.name('discover');
this.description(
'Starts Discovery Process using Node or Identity as a Starting Point',
);
this.description('Adds a Node or Identity to the Discovery Queue');
this.argument(
'<gestaltId>',
'Node ID or `Provider ID:Identity ID`',
Expand Down
2 changes: 2 additions & 0 deletions src/bin/identities/CommandIdentities.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CommandAllow from './CommandAllow';
import CommandAuthenticate from './CommandAuthenticate';
import CommandAuthenticated from './CommandAuthenticated';
import CommandClaim from './CommandClaim';
import CommandDisallow from './CommandDisallow';
import CommandDiscover from './CommandDiscover';
Expand All @@ -18,6 +19,7 @@ class CommandIdentities extends CommandPolykey {
this.description('Identities Operations');
this.addCommand(new CommandAllow(...args));
this.addCommand(new CommandAuthenticate(...args));
this.addCommand(new CommandAuthenticated(...args));
this.addCommand(new CommandClaim(...args));
this.addCommand(new CommandDisallow(...args));
this.addCommand(new CommandDiscover(...args));
Expand Down
96 changes: 75 additions & 21 deletions src/bin/identities/CommandSearch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import type PolykeyClient from '../../PolykeyClient';
import type { IdentityId, ProviderId } from '../../identities/types';
import CommandPolykey from '../CommandPolykey';
import * as binOptions from '../utils/options';
import * as binUtils from '../utils';
import * as parsers from '../utils/parsers';
import * as binProcessors from '../utils/processors';

class CommandSearch extends CommandPolykey {
Expand All @@ -10,13 +12,37 @@ class CommandSearch extends CommandPolykey {
this.name('search');
this.description('Searches a Provider for any Connected Identities');
this.argument(
'<providerId>',
'Name of the digital identity provider to search on',
'[searchTerms...]',
'Search parameters to apply to connected identities',
);
this.option(
'-pi, --provider-id [providerId...]',
'Digital identity provider(s) to search on',
parsers.parseProviderIdList,
);
this.option(
'-aii, --auth-identity-id, [authIdentityId]',
'Name of your own authenticated identity to find connected identities of',
parsers.parseIdentityId,
);
this.option(
'-ii, --identity-id [identityId]',
'Name of the digital identity to search for',
parsers.parseIdentityId,
);
this.option(
'-d, --disconnected',
'Include disconnected identities in search',
);
this.option(
'-l, --limit [number]',
'Limit the number of search results to display to a specific number',
parsers.parseInteger,
);
this.addOption(binOptions.nodeId);
this.addOption(binOptions.clientHost);
this.addOption(binOptions.clientPort);
this.action(async (providerId, options) => {
this.action(async (searchTerms, options) => {
const { default: PolykeyClient } = await import('../../PolykeyClient');
const identitiesPB = await import(
'../../proto/js/polykey/v1/identities/identities_pb'
Expand All @@ -34,7 +60,11 @@ class CommandSearch extends CommandPolykey {
this.fs,
);
let pkClient: PolykeyClient;
let genReadable: ReturnType<
typeof pkClient.grpcClient.identitiesInfoConnectedGet
>;
this.exitHandlers.handlers.push(async () => {
if (genReadable != null) genReadable.stream.cancel();
if (pkClient != null) await pkClient.stop();
});
try {
Expand All @@ -45,25 +75,49 @@ class CommandSearch extends CommandPolykey {
port: clientOptions.clientPort,
logger: this.logger.getChild(PolykeyClient.name),
});
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(providerId);
const res = await binUtils.retryAuthentication(
(auth) =>
pkClient.grpcClient.identitiesInfoGet(providerMessage, auth),
meta,
);
let output = '';
if (res.getIdentityId() && res.getProviderId()) {
output = `${res.getProviderId()}:${res.getIdentityId()}`;
} else {
this.logger.info('No Connected Identities found for Provider');
const providerSearchMessage = new identitiesPB.ProviderSearch();
providerSearchMessage.setSearchTermList(searchTerms);
if (options.providerId) {
providerSearchMessage.setProviderIdList(options.providerId);
}
if (options.authIdentityId) {
providerSearchMessage.setAuthIdentityId(options.authIdentityId);
}
if (options.disconnected) {
providerSearchMessage.setDisconnected(true);
}
if (options.limit) {
providerSearchMessage.setLimit(options.limit);
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [output],
}),
);
await binUtils.retryAuthentication(async (auth) => {
if (options.identity) {
providerSearchMessage.setIdentityId(options.identity);
genReadable = pkClient.grpcClient.identitiesInfoGet(
providerSearchMessage,
auth,
);
} else {
genReadable = pkClient.grpcClient.identitiesInfoConnectedGet(
providerSearchMessage,
auth,
);
}
for await (const val of genReadable) {
const output = {
providerId: val.getProvider()!.getProviderId() as ProviderId,
identityId: val.getProvider()!.getIdentityId() as IdentityId,
name: val.getName(),
email: val.getEmail(),
url: val.getUrl(),
};
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'dict',
data: output,
}),
);
}
}, meta);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
23 changes: 6 additions & 17 deletions src/bin/identities/CommandTrust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class CommandTrust extends CommandPolykey {
const identitiesPB = await import(
'../../proto/js/polykey/v1/identities/identities_pb'
);
const permissionsPB = await import(
'../../proto/js/polykey/v1/permissions/permissions_pb'
);
const nodesPB = await import('../../proto/js/polykey/v1/nodes/nodes_pb');
const clientOptions = await binProcessors.processClientOptions(
options.nodePath,
Expand All @@ -52,32 +49,24 @@ class CommandTrust extends CommandPolykey {
port: clientOptions.clientPort,
logger: this.logger.getChild(PolykeyClient.name),
});
const action = 'notify';
const setActionMessage = new permissionsPB.ActionSet();
setActionMessage.setAction(action);
if (gestaltId.type === 'node') {
// Setting by Node
// Setting by Node.
const nodeMessage = new nodesPB.Node();
nodeMessage.setNodeId(gestaltId.nodeId);
setActionMessage.setNode(nodeMessage);
await binUtils.retryAuthentication(
(auth) =>
pkClient.grpcClient.gestaltsActionsSetByNode(
setActionMessage,
auth,
),
pkClient.grpcClient.gestaltsGestaltTrustByNode(nodeMessage, auth),
meta,
);
} else {
// Setting by Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId!);
providerMessage.setIdentityId(gestaltId.identityId!);
setActionMessage.setIdentity(providerMessage);
providerMessage.setProviderId(gestaltId.providerId);
providerMessage.setIdentityId(gestaltId.identityId);
await binUtils.retryAuthentication(
(auth) =>
pkClient.grpcClient.gestaltsActionsSetByIdentity(
setActionMessage,
pkClient.grpcClient.gestaltsGestaltTrustByIdentity(
providerMessage,
auth,
),
meta,
Expand Down
Loading