run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
final args = argResults!;
final rest = args.rest;
if (rest.isEmpty) {
throw CliError('usage: grant add <principal> --role operator');
}
final roles = args['role'] as List<String>;
if (roles.isEmpty) {
throw CliError(
'name at least one --role (viewer, operator, admin, node) — a '
'credential that may do nothing is not a credential',
);
}
final client = _apiClientFrom(args);
try {
final issued = await client.issueGrant(
principal: rest.first,
roles: roles.toSet(),
note: '${args['note'] ?? ''}',
);
stdout
..writeln('principal: ${issued.grant.principal.value}')
..writeln('roles: ${issued.grant.roles.join(', ')}')
..writeln('grant id: ${issued.id} (revoke it with this)')
..writeln('')
..writeln('token: ${issued.token}')
..writeln('')
// Said out loud, because a Hub that stores a hash genuinely cannot show
// it again — and an operator who assumes otherwise finds out too late.
..writeln(
'This is the only time the token is shown: the Hub keeps a hash of '
'it, not the token.',
);
} finally {
client.close();
}
}