Skip to content

Commit 0846a04

Browse files
author
serverpod_cloud
committed
feat: 2924a5e5770f5459f3ef709412249df618ab828a
1 parent ea4d9d0 commit 0846a04

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

serverpod_cloud_cli/lib/command_runner/cloud_cli_command_runner.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,14 @@ enum GlobalOption<V> implements OptionDefinition<V> {
373373
hide: true,
374374
defaultsTo: false,
375375
),
376+
),
377+
authToken(
378+
StringOption(
379+
argName: 'auth-token',
380+
envName: 'SERVERPOD_CLOUD_AUTH_TOKEN',
381+
helpText: 'The authentication token to use for the Serverpod Cloud API.',
382+
hide: true,
383+
),
376384
);
377385

378386
const GlobalOption(this.option);
@@ -428,4 +436,6 @@ class GlobalConfiguration extends Configuration<GlobalOption> {
428436
String get consoleServer => value(GlobalOption.consoleServer);
429437

430438
bool get skipConfirmation => value(GlobalOption.skipConfirmation);
439+
440+
String? get authToken => optionalValue(GlobalOption.authToken);
431441
}

serverpod_cloud_cli/lib/command_runner/helpers/cloud_cli_service_provider.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:serverpod_cloud_cli/command_logger/command_logger.dart';
22
import 'package:serverpod_cloud_cli/command_runner/cloud_cli_command_runner.dart';
3+
import 'package:serverpod_cloud_cli/persistent_storage/models/serverpod_cloud_data.dart';
34
import 'package:serverpod_cloud_cli/util/cli_authentication_key_manager.dart';
45
import 'package:ground_control_client/ground_control_client.dart';
56

@@ -55,11 +56,17 @@ class CloudCliServiceProvider {
5556
final address =
5657
serverAddress.endsWith('/') ? serverAddress : '$serverAddress/';
5758

59+
final authTokenOverride = _globalConfiguration.authToken;
60+
final cloudDataOverride = authTokenOverride != null
61+
? ServerpodCloudData(authTokenOverride)
62+
: null;
63+
5864
cloudApiClient = Client(
5965
address,
6066
authenticationKeyManager: CliAuthenticationKeyManager(
6167
logger: _logger,
6268
localStoragePath: localStoragePath.path,
69+
cloudDataOverride: cloudDataOverride,
6370
),
6471
connectionTimeout: _globalConfiguration.connectionTimeout,
6572
);

serverpod_cloud_cli/test_integration/serverpod_cloud_cli_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,27 @@ void main() async {
4949
),
5050
);
5151
});
52+
53+
group(
54+
'Given a cli command runner '
55+
'when running any command with the auth token option ', () {
56+
setUp(() async {
57+
await cli.run(['version', '--auth-token', 'test-token']);
58+
});
59+
60+
test('then the auth token is set in the global configuration.', () {
61+
expect(
62+
cli.globalConfiguration.authToken,
63+
'test-token',
64+
);
65+
});
66+
67+
test('then the auth token is set in the authentication key manager.',
68+
() async {
69+
await expectLater(
70+
cli.serviceProvider.cloudApiClient.authenticationKeyManager?.get(),
71+
completion('test-token'),
72+
);
73+
});
74+
});
5275
}

0 commit comments

Comments
 (0)