Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issue 586 #611

Merged
merged 11 commits into from
Jul 19, 2024
19 changes: 15 additions & 4 deletions packages/at_onboarding_cli/lib/src/activate_cli/activate_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import 'package:at_onboarding_cli/src/util/at_onboarding_exceptions.dart';
import 'package:at_utils/at_logger.dart';

Future<void> main(List<String> arguments) async {
int exitCode = await wrappedMain(arguments);
exit(exitCode);
}

Future<int> wrappedMain(List<String> arguments) async {
//defaults
String rootServer = 'root.atsign.org';
String registrarUrl = 'my.atsign.com';
Expand Down Expand Up @@ -40,7 +45,7 @@ Future<void> main(List<String> arguments) async {

if (argResults.wasParsed('help')) {
stdout.writeln(parser.usage);
return;
return 0;
}

if (!argResults.wasParsed('atsign')) {
Expand All @@ -49,10 +54,10 @@ Future<void> main(List<String> arguments) async {
throw IllegalArgumentException('atSign is required');
}

await activate(argResults);
return await activate(argResults);
}

Future<void> activate(ArgResults argResults,
Future<int> activate(ArgResults argResults,
{AtOnboardingService? atOnboardingService}) async {
stdout.writeln('[Information] Root server is ${argResults['rootServer']}');
stdout.writeln(
Expand All @@ -70,21 +75,27 @@ Future<void> activate(ArgResults argResults,
AtOnboardingServiceImpl(argResults['atsign'], atOnboardingPreference);
stdout.writeln(
'[Information] Activating your atSign. This may take up to 2 minutes.');
int retCode = 0;
try {
await atOnboardingService.onboard();
} on InvalidDataException catch (e) {
stderr.writeln(
'[Error] Activation failed. Invalid data provided by user. Please try again\nCause: ${e.message}');
retCode = 1;
} on InvalidRequestException catch (e) {
stderr.writeln(
'[Error] Activation failed. Invalid data provided by user. Please try again\nCause: ${e.message}');
retCode = 2;
} on AtActivateException catch (e) {
stdout.writeln('[Error] ${e.message}');
} on Exception catch (e) {
retCode = 3;
} catch (e) {
stderr.writeln(
'[Error] Activation failed. It looks like something went wrong on our side.\n'
'Please try again or contact [email protected]\nCause: $e');
retCode = 4;
} finally {
await atOnboardingService.close();
}
return retCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,13 @@ class AtOnboardingServiceImpl implements AtOnboardingService {

@override
Future<void> close() async {
logger.info('Closing');
if (_atLookUp != null) {
await (_atLookUp as AtLookupImpl).close();
}
_atLookUp = null;
atClient = null;
logger.info('Closing current instance of at_onboarding_cli (exit code: 0)');
exit(0);
logger.info('Closed');
}

@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Register {
.start();

await activate_cli
.main(['-a', params['atsign']!, '-c', params['cramkey']!]);
.wrappedMain(['-a', params['atsign']!, '-c', params['cramkey']!]);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ final String atKeysFilePath = '${Platform.environment['HOME']}/.atsign/keys';
Map<String, bool> keysCreatedMap = {};
void main() {
AtSignLogger.root_level = 'WARNING';

// These group of tests run on docker container with only cram key available on secondary
// Perform cram auth and update keys manually.
Future<void> _createKeys(String atSign) async {
Expand Down Expand Up @@ -177,7 +178,7 @@ void main() {
'vip.ve.atsign.zone'
];
// perform activation of atSign
await activate_cli.main(args);
await activate_cli.wrappedMain(args);

expect(await onboardingService.authenticate(), true);
// Authenticate atSign with the .atKeys file generated via the activate_cli tool.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void main() {
var deleteResponse = await atClient?.delete(key);
stdout.writeln('[Test] Got Delete Response: $deleteResponse');
expect(deleteResponse, true);
});
}, skip: true);

tearDown(() async {
await tearDownFunc();
Expand Down