@@ -7,21 +7,12 @@ library test.integration.common_e2e;
77import 'dart:async' ;
88import 'dart:io' ;
99
10- import 'package:googleapis_auth/auth_io.dart' as auth;
1110import 'package:grpc/grpc.dart' as grpc;
1211import 'package:appengine/src/grpc_api_impl/datastore_impl.dart'
1312 as grpc_datastore_impl;
1413
15- // Environment variables for specifying the cloud project to use and the
16- // location of the service account key for that project.
14+ // Environment variable for specifying the cloud project to use
1715const String PROJECT_ENV = 'E2E_TEST_PROJECT' ;
18- const String SERVICE_KEY_LOCATION_ENV = 'E2E_TEST_KEY' ;
19-
20- // Default project and service key location used when running on the package
21- // bot.
22- const String DEFAULT_PROJECT = 'dart-gcloud-e2e' ;
23- const String DEFAULT_KEY_LOCATION =
24- 'gs://dart-archive-internal/keys/dart-gcloud-e2e.json' ;
2516
2617bool onBot () {
2718 // Check for GitHub Actions.
@@ -39,75 +30,19 @@ bool onBot() {
3930 return Platform .environment[name] == 'chrome-bot' ;
4031}
4132
42- Future <dynamic > withServiceAccount (
43- Future callback (
44- String project, auth.ServiceAccountCredentials creds)) async {
45- var project = Platform .environment[PROJECT_ENV ];
46- var serviceKeyLocation = Platform .environment[SERVICE_KEY_LOCATION_ENV ];
47-
48- if (! onBot () && (project == null || serviceKeyLocation == null )) {
49- throw Exception (
50- 'Environment variables $PROJECT_ENV and $SERVICE_KEY_LOCATION_ENV '
51- 'required when not running on the package bot' );
52- }
53-
54- project ?? = DEFAULT_PROJECT ;
55- serviceKeyLocation ?? = DEFAULT_KEY_LOCATION ;
56-
57- final keyJson = await _serviceKeyJson (serviceKeyLocation);
58- final creds = auth.ServiceAccountCredentials .fromJson (keyJson);
59- return callback (project, creds);
60- }
61-
6233Future <dynamic > withAuthenticator (
6334 List <String > scopes,
6435 Future callback (String project, grpc.HttpBasedAuthenticator authenticator),
6536) async {
6637 var project = Platform .environment[PROJECT_ENV ];
67- var serviceKeyLocation = Platform .environment[SERVICE_KEY_LOCATION_ENV ];
6838
69- if (! onBot () && project == null ) {
70- throw Exception (
71- 'Environment variables $PROJECT_ENV and $SERVICE_KEY_LOCATION_ENV '
72- 'required when not running on the package bot' );
39+ if (project == null ) {
40+ throw Exception ('Environment variable $PROJECT_ENV is required!' );
7341 }
7442
7543 // Use ADC
76- if (! onBot () && project != null && serviceKeyLocation == null ) {
77- final authenticator = await grpc.applicationDefaultCredentialsAuthenticator (
78- grpc_datastore_impl.OAuth2Scopes ,
79- );
80- return callback (project, authenticator);
81- }
82-
83- project ?? = DEFAULT_PROJECT ;
84- serviceKeyLocation ?? = DEFAULT_KEY_LOCATION ;
85-
86- final keyJson = await (_serviceKeyJson (serviceKeyLocation));
87- final authenticator = grpc.ServiceAccountAuthenticator (keyJson! , scopes);
44+ final authenticator = await grpc.applicationDefaultCredentialsAuthenticator (
45+ grpc_datastore_impl.OAuth2Scopes ,
46+ );
8847 return callback (project, authenticator);
8948}
90-
91- Future <String ?> _serviceKeyJson (String serviceKeyLocation) async {
92- if (! serviceKeyLocation.startsWith ('gs://' )) {
93- return File (serviceKeyLocation).readAsString ();
94- } else {
95- ProcessResult result;
96- if (onBot ()) {
97- // Use gsutil.py from depot_tools on the bots.
98- final gsutilPath = Platform .operatingSystem == 'windows'
99- ? 'E:\\ b\\ depot_tools\\ gsutil.py'
100- : '/b/depot_tools/gsutil.py' ;
101- result = await Process .run (
102- 'python' , [gsutilPath, 'cat' , serviceKeyLocation],
103- runInShell: true );
104- } else {
105- final gsutil = Platform .isWindows ? 'gsutil.cmd' : 'gsutil' ;
106- result = await Process .run (gsutil, ['cat' , serviceKeyLocation]);
107- }
108- if (result.exitCode != 0 ) {
109- throw Exception ('Failed to run gsutil, ${result .stderr }' );
110- }
111- return result.stdout;
112- }
113- }
0 commit comments