Skip to content

Commit

Permalink
Implementing identities claim command
Browse files Browse the repository at this point in the history
Fix naming of `identityId` field of `Provider` proto message
Sigchain `addClaim()` method returns generated claim
"Reset" functionality for Test Provider
Replacing identities rpc exceptions with domain+client exceptions
  • Loading branch information
tegefaulkes authored and emmacasolin committed Dec 14, 2021
1 parent a5cbb0b commit 37d560a
Show file tree
Hide file tree
Showing 28 changed files with 445 additions and 163 deletions.
1 change: 1 addition & 0 deletions src/PolykeyAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ class PolykeyAgent {
notificationsManager: this.notificationsManager,
sessionManager: this.sessionManager,
vaultManager: this.vaultManager,
sigchain: this.sigchain,
grpcServerClient: this.grpcServerClient,
grpcServerAgent: this.grpcServerAgent,
fwdProxy: this.fwdProxy,
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandAllow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CommandAllow extends CommandPolykey {
// Setting By Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId);
providerMessage.setMessage(gestaltId.identityId);
providerMessage.setIdentityId(gestaltId.identityId);
setActionMessage.setIdentity(providerMessage);
await binUtils.retryAuthentication(
(auth) =>
Expand Down
6 changes: 3 additions & 3 deletions src/bin/identities/CommandAuthenticate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CommandAuthenticate extends CommandPolykey {
});
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(providerId);
providerMessage.setMessage(identityId);
providerMessage.setIdentityId(identityId);
const successMessage = await binUtils.retryAuthentication(
async (auth) => {
const stream = pkClient.grpcClient.identitiesAuthenticate(
Expand All @@ -56,7 +56,7 @@ class CommandAuthenticate extends CommandPolykey {
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [`Your device code is: ${codeMessage!.getMessage()}`],
data: [`Your device code is: ${codeMessage!.getIdentityId()}`],
}),
);
return (await stream.next()).value;
Expand All @@ -67,7 +67,7 @@ class CommandAuthenticate extends CommandPolykey {
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
`Successfully authenticated user: ${successMessage!.getMessage()}`,
`Successfully authenticated user: ${successMessage!.getIdentityId()}`,
],
}),
);
Expand Down
17 changes: 15 additions & 2 deletions src/bin/identities/CommandClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,24 @@ class CommandClaim extends CommandPolykey {
});
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(providerId);
providerMessage.setMessage(identityId);
await binUtils.retryAuthentication(
providerMessage.setIdentityId(identityId);
const response = await binUtils.retryAuthentication(
(auth) => pkClient.grpcClient.identitiesClaim(providerMessage, auth),
meta,
);
const output = [
`Published identity claim with id: ${response.getClaimId()}
on provider: ${providerId}`,
];
if (response.getUrl()) {
output.push(`See claim at: ${response.getUrl()}`);
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: output,
}),
);
} finally {
if (pkClient! != null) await pkClient.stop();
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandDisallow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CommandDisallow extends CommandPolykey {
// Setting by Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId);
providerMessage.setMessage(gestaltId.identityId);
providerMessage.setIdentityId(gestaltId.identityId);
setActionMessage.setIdentity(providerMessage);
// Trusting.
await binUtils.retryAuthentication(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandDiscover.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CommandDiscover extends CommandPolykey {
// Discovery by Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId);
providerMessage.setMessage(gestaltId.identityId);
providerMessage.setIdentityId(gestaltId.identityId);
await binUtils.retryAuthentication(
(auth) =>
pkClient.grpcClient.gestaltsDiscoveryByIdentity(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandGet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CommandGet extends CommandPolykey {
// Getting from identity.
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId);
providerMessage.setMessage(gestaltId.identityId);
providerMessage.setIdentityId(gestaltId.identityId);
res = await binUtils.retryAuthentication(
(auth) =>
pkClient.grpcClient.gestaltsGestaltGetByIdentity(
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandPermissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class CommandPermissions extends CommandPolykey {
// Getting by Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId);
providerMessage.setMessage(gestaltId.identityId);
providerMessage.setIdentityId(gestaltId.identityId);
const res = await binUtils.retryAuthentication(
(auth) =>
pkClient.grpcClient.gestaltsActionsGetByIdentity(
Expand Down
18 changes: 12 additions & 6 deletions src/bin/identities/CommandSearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,21 @@ class CommandSearch extends CommandPolykey {
pkClient.grpcClient.identitiesInfoGet(providerMessage, auth),
meta,
);
let output;
if (res.getIdentityId()) {
output = [
parsers.formatIdentityString(
res.getProviderId() as ProviderId,
res.getIdentityId() as IdentityId,
),
];
} else {
output = [`No identities found for provider ${providerId}`];
}
process.stdout.write(
binUtils.outputFormatter({
type: options.format === 'json' ? 'json' : 'list',
data: [
parsers.formatIdentityString(
res.getProviderId() as ProviderId,
res.getMessage() as IdentityId,
),
],
data: output,
}),
);
} finally {
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandTrust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CommandTrust extends CommandPolykey {
// Setting by Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId!);
providerMessage.setMessage(gestaltId.identityId!);
providerMessage.setIdentityId(gestaltId.identityId!);
setActionMessage.setIdentity(providerMessage);
await binUtils.retryAuthentication(
(auth) =>
Expand Down
2 changes: 1 addition & 1 deletion src/bin/identities/CommandUntrust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CommandUntrust extends CommandPolykey {
// Setting by Identity
const providerMessage = new identitiesPB.Provider();
providerMessage.setProviderId(gestaltId.providerId!);
providerMessage.setMessage(gestaltId.identityId!);
providerMessage.setIdentityId(gestaltId.identityId!);
setActionMessage.setIdentity(providerMessage);
await binUtils.retryAuthentication(
(auth) =>
Expand Down
2 changes: 1 addition & 1 deletion src/client/GRPCClientClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ class GRPCClientClient extends GRPCClient<ClientServiceClient> {

@ready(new clientErrors.ErrorClientClientDestroyed())
public identitiesClaim(...args) {
return grpcUtils.promisifyUnaryCall<utilsPB.EmptyMessage>(
return grpcUtils.promisifyUnaryCall<identitiesPB.Claim>(
this.client,
this.client.identitiesClaim,
)(...args);
Expand Down
5 changes: 4 additions & 1 deletion src/client/clientService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { GestaltGraph } from '../gestalts';
import type { SessionManager } from '../sessions';
import type { NotificationsManager } from '../notifications';
import type { Discovery } from '../discovery';
import type { Sigchain } from '../sigchain';
import type { GRPCServer } from '../grpc';
import type { ForwardProxy, ReverseProxy } from '../network';
import type { FileSystem } from '../types';
Expand Down Expand Up @@ -43,6 +44,7 @@ function createClientService({
sessionManager,
notificationsManager,
discovery,
sigchain,
grpcServerClient,
grpcServerAgent,
fwdProxy,
Expand All @@ -58,6 +60,7 @@ function createClientService({
sessionManager: SessionManager;
notificationsManager: NotificationsManager;
discovery: Discovery;
sigchain: Sigchain;
grpcServerClient: GRPCServer;
grpcServerAgent: GRPCServer;
fwdProxy: ForwardProxy;
Expand Down Expand Up @@ -93,7 +96,7 @@ function createClientService({
}),
...createIdentitiesRPC({
identitiesManager,
gestaltGraph,
sigchain,
nodeManager,
authenticate,
}),
Expand Down
6 changes: 6 additions & 0 deletions src/client/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ class ErrorClientInvalidNode extends ErrorClient {
exitCode: number = 70;
}

class ErrorClientInvalidProvider extends ErrorClient {
description = 'Provider Id is invalid or does not exist';
exitCode = 70;
}

export {
ErrorClient,
ErrorClientClientDestroyed,
ErrorClientAuthMissing,
ErrorClientAuthFormat,
ErrorClientAuthDenied,
ErrorClientInvalidNode,
ErrorClientInvalidProvider,
};
10 changes: 5 additions & 5 deletions src/client/rpcGestalts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const createGestaltsRPC = ({

const gestalt = await gestaltGraph.getGestaltByIdentity(
call.request.getProviderId() as ProviderId,
call.request.getMessage() as IdentityId,
call.request.getIdentityId() as IdentityId,
);
if (gestalt != null) {
response.setGestaltGraph(JSON.stringify(gestalt));
Expand Down Expand Up @@ -129,7 +129,7 @@ const createGestaltsRPC = ({
// Constructing identity info.
const gen = discovery.discoverGestaltByIdentity(
info.getProviderId() as ProviderId,
info.getMessage() as IdentityId,
info.getIdentityId() as IdentityId,
);
for await (const _ of gen) {
// Empty
Expand Down Expand Up @@ -180,7 +180,7 @@ const createGestaltsRPC = ({
call.sendMetadata(metadata);

const providerId = info.getProviderId() as ProviderId;
const identityId = info.getMessage() as IdentityId;
const identityId = info.getIdentityId() as IdentityId;
const result = await gestaltGraph.getGestaltActionsByIdentity(
providerId,
identityId,
Expand Down Expand Up @@ -258,7 +258,7 @@ const createGestaltsRPC = ({
// Setting the action.
const action = makeGestaltAction(info.getAction());
const providerId = info.getIdentity()?.getProviderId() as ProviderId;
const identityId = info.getIdentity()?.getMessage() as IdentityId;
const identityId = info.getIdentity()?.getIdentityId() as IdentityId;
await gestaltGraph.setGestaltActionByIdentity(
providerId,
identityId,
Expand Down Expand Up @@ -329,7 +329,7 @@ const createGestaltsRPC = ({
// Setting the action.
const action = makeGestaltAction(info.getAction());
const providerId = info.getIdentity()?.getProviderId() as ProviderId;
const identityId = info.getIdentity()?.getMessage() as IdentityId;
const identityId = info.getIdentity()?.getIdentityId() as IdentityId;
await gestaltGraph.unsetGestaltActionByIdentity(
providerId,
identityId,
Expand Down
Loading

0 comments on commit 37d560a

Please sign in to comment.