Skip to content

Commit

Permalink
feat: log when SHOREBIRD_TOKEN is detected and successfully parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanoltman committed Feb 12, 2025
1 parent 6165180 commit aeb5822
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/shorebird_cli/lib/src/auth/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ class Auth {
void _loadCredentials() {
final envToken = platform.environment[shorebirdTokenEnvVar];
if (envToken != null) {
logger.info('$shorebirdTokenEnvVar detected');

try {
_token = CiToken.fromBase64(envToken.trim());
} on FormatException catch (e) {
Expand All @@ -328,6 +330,8 @@ Please regenerate using `shorebird login:ci`, update the $shorebirdTokenEnvVar e
..detail(e.toString());
rethrow;
}

logger.info('$shorebirdTokenEnvVar successfully parsed');
return;
}

Expand Down
10 changes: 10 additions & 0 deletions packages/shorebird_cli/test/src/auth/auth_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ void main() {
test('logs and throws error when token string is not valid base64',
() async {
expect(buildAuth, throwsA(isFormatException));
verify(
() => logger.info('$shorebirdTokenEnvVar detected'),
).called(1);
verify(
() => logger.err(
'''
Expand All @@ -549,6 +552,9 @@ Failed to parse CI token from environment. This likely means that your CI token
Please regenerate using `shorebird login:ci`, update the $shorebirdTokenEnvVar environment variable, and try again.''',
),
).called(1);
verifyNever(
() => logger.info('$shorebirdTokenEnvVar successfully parsed'),
);
});
});

Expand Down Expand Up @@ -588,6 +594,10 @@ Please regenerate using `shorebird login:ci`, update the $shorebirdTokenEnvVar e
final client = auth.client;
expect(client, isA<http.Client>());
expect(client, isA<AuthenticatedClient>());
verify(() => logger.info('$shorebirdTokenEnvVar detected')).called(1);
verify(
() => logger.info('$shorebirdTokenEnvVar successfully parsed'),
).called(1);
});

test('returns a plain http client when credentials are not present.',
Expand Down

0 comments on commit aeb5822

Please sign in to comment.