@@ -7,21 +7,12 @@ library test.integration.common_e2e;
7
7
import 'dart:async' ;
8
8
import 'dart:io' ;
9
9
10
- import 'package:googleapis_auth/auth_io.dart' as auth;
11
10
import 'package:grpc/grpc.dart' as grpc;
12
11
import 'package:appengine/src/grpc_api_impl/datastore_impl.dart'
13
12
as grpc_datastore_impl;
14
13
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
17
15
const 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' ;
25
16
26
17
bool onBot () {
27
18
// Check for GitHub Actions.
@@ -39,75 +30,19 @@ bool onBot() {
39
30
return Platform .environment[name] == 'chrome-bot' ;
40
31
}
41
32
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
-
62
33
Future <dynamic > withAuthenticator (
63
34
List <String > scopes,
64
35
Future callback (String project, grpc.HttpBasedAuthenticator authenticator),
65
36
) async {
66
37
var project = Platform .environment[PROJECT_ENV ];
67
- var serviceKeyLocation = Platform .environment[SERVICE_KEY_LOCATION_ENV ];
68
38
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!' );
73
41
}
74
42
75
43
// 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
+ );
88
47
return callback (project, authenticator);
89
48
}
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