-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
creating new branch for #267 changed message to identity_id in provider message updating all commands that use provider message updated everything on the agent side for augment command started tests and debugging augment command identities claim working in client service test wrote test for command in identities
- Loading branch information
1 parent
9200b11
commit 0346fc5
Showing
7 changed files
with
196 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { clientPB, utils as clientUtils } from '../../client'; | ||
import { createCommand, outputFormatter } from '../utils'; | ||
import Logger, { LogLevel, StreamHandler } from '@matrixai/logger'; | ||
import PolykeyClient from '../../PolykeyClient'; | ||
import { errors } from '../../grpc'; | ||
import * as utils from '../../utils'; | ||
|
||
const claim = createCommand('claim', { | ||
description: { | ||
description: 'Claim an identity for this keynode.', | ||
args: { | ||
providerId: 'Provider that identity is linked to', | ||
identityId: 'Identitiy to augment the keynode with', | ||
}, | ||
}, | ||
verbose: true, | ||
format: true, | ||
nodePath: true, | ||
}); | ||
claim.arguments('<providerId> <identityId>'); | ||
claim.alias('aug'); | ||
claim.action(async (providerId, identitiyId, options) => { | ||
const clientConfig = {}; | ||
clientConfig['logger'] = new Logger('CLI Logger', LogLevel.WARN, [ | ||
new StreamHandler(), | ||
]); | ||
if (options.verbose) { | ||
clientConfig['logger'].setLevel(LogLevel.DEBUG); | ||
} | ||
clientConfig['nodePath'] = options.nodePath | ||
? options.nodePath | ||
: utils.getDefaultNodePath(); | ||
|
||
const client = await PolykeyClient.createPolykeyClient(clientConfig); | ||
|
||
try { | ||
//Starting client | ||
await client.start({}); | ||
const grpcClient = client.grpcClient; | ||
|
||
//Constructing message. | ||
const providerMessage = new clientPB.ProviderMessage(); | ||
providerMessage.setProviderId(providerId); | ||
providerMessage.setIdentityId(identitiyId); | ||
|
||
//Sending message. | ||
const pCall = grpcClient.identitiesClaim(providerMessage); | ||
const { p, resolveP } = utils.promise(); | ||
pCall.call.on('metadata', async (meta) => { | ||
await clientUtils.refreshSession(meta, client.session); | ||
resolveP(null); | ||
}); | ||
const response = await pCall; | ||
await p; | ||
|
||
const output = [`Successfully published identity claim with id: ${response.getClaimId()} | ||
on provider: ${providerId}`]; | ||
|
||
if (response.getUrl()) { | ||
output.push(`See claim at: ${response.getUrl()}`); | ||
} | ||
|
||
process.stdout.write( | ||
outputFormatter({ | ||
type: options.format === 'json' ? 'json' : 'list', | ||
data: output, | ||
}), | ||
); | ||
|
||
} catch (err) { | ||
if (err instanceof errors.ErrorGRPCClientTimeout) { | ||
process.stderr.write(`${err.message}\n`); | ||
} | ||
if (err instanceof errors.ErrorGRPCServerNotStarted) { | ||
process.stderr.write(`${err.message}\n`); | ||
} else { | ||
process.stdout.write( | ||
outputFormatter({ | ||
type: options.format === 'json' ? 'json' : 'list', | ||
data: ['Error:', err.message], | ||
}), | ||
); | ||
} | ||
throw err; | ||
} finally { | ||
await client.stop(); | ||
options.nodePath = undefined; | ||
options.verbose = undefined; | ||
options.format = undefined; | ||
} | ||
}); | ||
|
||
export default claim; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.