From 96d839a43689488adc3ef990a193687a2a955dfa Mon Sep 17 00:00:00 2001 From: Karl Klose Date: Fri, 10 Jul 2020 09:52:38 +0000 Subject: [PATCH] [infra] Remove trailing new-line from auth token file The result from 'gcloud auth print-access-token' contains a new-line that cannot be used in the header. To make this use case easier, remove new-lines, if found. Change-Id: I44a9cc2bcfe4a8ef06e47a8495e69e116e9a6dfa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153921 Commit-Queue: Karl Klose Reviewed-by: William Hesse --- tools/bots/get_builder_status.dart | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/bots/get_builder_status.dart b/tools/bots/get_builder_status.dart index 82aca7c2b05d..e464abcf22c4 100755 --- a/tools/bots/get_builder_status.dart +++ b/tools/bots/get_builder_status.dart @@ -53,6 +53,11 @@ ${parser.usage}'''); exit(1); } +Future readGcloudAuthToken(String path) async { + String token = await File(path).readAsString(); + return token.split("\n").first; +} + main(List args) async { final parser = new ArgParser(); parser.addFlag('help', help: 'Show the program usage.', negatable: false); @@ -72,7 +77,11 @@ main(List args) async { builder = options['builder']; buildNumber = int.parse(options['build_number']); builderBase = builder.replaceFirst(RegExp('-try\$'), ''); - token = await File(options['auth_token']).readAsString(); + if (options['auth_token'] == null) { + print('Option "--auth_token (-a)" is required\n'); + usage(parser); + } + token = await readGcloudAuthToken(options['auth_token']); client = http.Client(); for (int count = 0; count < numAttempts; ++count) { if (count > 0) {