Skip to content

Commit

Permalink
feat: at_onboarding_cli: add 'status' command to the activate cli to …
Browse files Browse the repository at this point in the history
…check the status of an atSign

build: at_onboarding_cli: updated pubspec and changelog for version 1.5.1
  • Loading branch information
gkc committed May 20, 2024
1 parent 9dda72c commit 4346674
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/at_onboarding_cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.5.1
- feat: add 'status' command to the activate cli to check the status of an
atSign
## 1.5.0
- feat: 'activate' CLI is now APKAM-aware, and supports
- onboarding (as before)
Expand Down
58 changes: 58 additions & 0 deletions packages/at_onboarding_cli/lib/src/cli/auth_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ Future<int> _main(List<String> arguments) async {
aca.parser.printAllCommandsUsage(showSubCommandParams: true);
break;

case AuthCliCommand.status:
return await status(commandArgResults);

case AuthCliCommand.onboard:
// First time an app is connecting to an atServer.
// Authenticate with cram secret
Expand Down Expand Up @@ -189,6 +192,60 @@ Future<int> _main(List<String> arguments) async {
return 0;
}

/// Check the status of an atSign - returns
/// - 4 if the atDirectory cannot be reached
/// - 3 if atDirectory is reachable but the atSign does not exist
/// - 2 if the atSign exists but the atServer cannot be reached
/// - 1 if the atServer is reachable but there is no public:publickey@<atsign>
/// - 0 if the atServer is reachable and public:publickey@<atsign> exists
Future<int> status(ArgResults ar) async {
String atSign = AtUtils.fixAtSign(ar[AuthCliArgs.argNameAtSign]);

SecondaryAddressFinder saf = CacheableSecondaryAddressFinder(
ar[AuthCliArgs.argNameAtDirectoryFqdn], 64);
try {
await saf.findSecondary(atSign);
} on SecondaryNotFoundException {
stderr.writeln('returning 3: atDirectory has no record for $atSign');
return 3;
} catch (e) {
stderr.writeln('returning 4: Caught ${e.runtimeType} : $e');
return 4;
}

String? pk;
try {
AtLookUp al = AtLookupImpl(
atSign,
ar[AuthCliArgs.argNameAtDirectoryFqdn],
64,
);
try {
pk = await al.executeCommand('lookup:publickey$atSign\n', auth: false);
} on AtLookUpException catch (e) {
final e1 = AtExceptionUtils.get(e.errorCode ?? '', e.errorMessage ?? '');
throw e1;
}
} on SecondaryServerConnectivityException catch (e) {
stderr.writeln('returning 2: atServer cannot be reached $atSign ($e)');
return 2;
} on KeyNotFoundException catch (e) {
stderr.writeln('returning 1: $e');
return 1;
} catch (e) {
stderr.writeln('returning 2: Caught unexpected ${e.runtimeType} : $e');
return 2;
}

if (pk == null || !pk.startsWith("data:")) {
stderr.writeln('returning 1: response was $pk');
return 1;
}

stderr.writeln('returning 0: found public:publickey$atSign OK');
return 0;
}

Future<AtClient> createAtClient(ArgResults ar) async {
String nameSpace = 'at_auth_cli';
String atSign = AtUtils.fixAtSign(ar[AuthCliArgs.argNameAtSign]);
Expand Down Expand Up @@ -400,6 +457,7 @@ Future<void> interactive(ArgResults argResults, AtClient atClient) async {

case AuthCliCommand.onboard:
case AuthCliCommand.interactive:
case AuthCliCommand.status:
case AuthCliCommand.enroll:
stderr.writeln('The "${cliCommand.name}" command'
' may not be used in interactive session');
Expand Down
16 changes: 16 additions & 0 deletions packages/at_onboarding_cli/lib/src/cli/auth_cli_args.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import 'package:meta/meta.dart';

enum AuthCliCommand {
help(usage: 'Show help'),
status(
usage: 'Check the status of an atSign - will return one of '
'\n 4 if the atDirectory cannot be reached'
'\n 3 if atDirectory is reachable but the atSign does not exist'
'\n 2 if the atSign exists but the atServer cannot be reached'
'\n 1 if the atServer is reachable but there is no public:publickey@<atsign>'
'\n 0 if the atServer is reachable and public:publickey@<atsign> exists'),
onboard(
usage: '"onboard" is used when first authenticating to an atServer.'
' It generates "atKeys" (stored to filesystem or keychain) which'
Expand Down Expand Up @@ -126,6 +133,9 @@ class AuthCliArgs {
@visibleForTesting
ArgParser createParserForCommand(AuthCliCommand c) {
switch (c) {
case AuthCliCommand.status:
return createStatusCommandParser();

case AuthCliCommand.help:
return createHelpCommandParser();

Expand Down Expand Up @@ -268,6 +278,12 @@ class AuthCliArgs {
return p;
}

@visibleForTesting
ArgParser createStatusCommandParser() {
ArgParser p = createSharedArgParser(hide: true);
return p;
}

/// auth otp : require atSign [, atKeys path] [, atDirectory]
@visibleForTesting
ArgParser createOtpCommandParser() {
Expand Down
2 changes: 1 addition & 1 deletion packages/at_onboarding_cli/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_onboarding_cli
description: Dart tools for initial client onboarding, subsequent client enrollment, and enrollment management.
version: 1.5.0
version: 1.5.1
repository: https://github.com/atsign-foundation/at_libraries
homepage: https://atsign.com
documentation: https://docs.atsign.com/
Expand Down

0 comments on commit 4346674

Please sign in to comment.