7
7
8
8
public class ServiceAccountSpecification implements SpecificationInterface {
9
9
public String name ;
10
- public String jsonKeyCredFilePath ;
10
+ public String jsonKeyDirectoryPath ;
11
+ public String jsonKeyFilename ;
11
12
12
13
public File jsonKeyFile ;
13
14
14
15
public static final String resourceDirectory = "serviceaccounts" ;
15
- public static final String keyCredFilePathEnvironmentVarName =
16
- "GOOGLE_APPLICATION_CREDENTIALS " ;
16
+ public static final String keyDirectoryPathEnvironmentVarName =
17
+ "TEST_RUNNER_SA_KEY_DIRECTORY_PATH " ;
17
18
18
19
ServiceAccountSpecification () {}
19
20
@@ -33,20 +34,20 @@ public static ServiceAccountSpecification fromJSONFile(String resourceFileName)
33
34
ServiceAccountSpecification serviceAccount =
34
35
objectMapper .readValue (inputStream , ServiceAccountSpecification .class );
35
36
36
- String credFilePathEnvVarOverride = readCredFilePathEnvironmentVariable ();
37
- if (credFilePathEnvVarOverride != null ) {
38
- serviceAccount .jsonKeyCredFilePath = credFilePathEnvVarOverride ;
37
+ String keyDirectoryPathEnvVarOverride = readKeyDirectoryPathEnvironmentVariable ();
38
+ if (keyDirectoryPathEnvVarOverride != null ) {
39
+ serviceAccount .jsonKeyDirectoryPath = keyDirectoryPathEnvVarOverride ;
39
40
}
40
41
41
42
return serviceAccount ;
42
43
}
43
44
44
- protected static String readCredFilePathEnvironmentVariable () {
45
- // look for a full file path defined for the service account credentials
45
+ protected static String readKeyDirectoryPathEnvironmentVariable () {
46
+ // look for the service account JSON key file in a directory defined by, in order:
46
47
// 1. environment variable
47
- // 2. service account jsonKeyCredFilePath property
48
- String keyCredFilePathEnvironmentVarValue = System .getenv (keyCredFilePathEnvironmentVarName );
49
- return keyCredFilePathEnvironmentVarValue ;
48
+ // 2. service account jsonKeyDirectoryPath property
49
+ String keyDirectoryPathEnvironmentVarValue = System .getenv (keyDirectoryPathEnvironmentVarName );
50
+ return keyDirectoryPathEnvironmentVarValue ;
50
51
}
51
52
52
53
/**
@@ -56,14 +57,19 @@ protected static String readCredFilePathEnvironmentVariable() {
56
57
public void validate () {
57
58
if (name == null || name .equals ("" )) {
58
59
throw new IllegalArgumentException ("Service account name cannot be empty" );
59
- } else if (jsonKeyCredFilePath == null || jsonKeyCredFilePath .equals ("" )) {
60
- throw new IllegalArgumentException ("JSON key file path cannot be empty" );
60
+ } else if (jsonKeyFilename == null || jsonKeyFilename .equals ("" )) {
61
+ throw new IllegalArgumentException ("JSON key file name cannot be empty" );
62
+ } else if (jsonKeyDirectoryPath == null || jsonKeyDirectoryPath .equals ("" )) {
63
+ throw new IllegalArgumentException ("JSON key directory path cannot be empty" );
61
64
}
62
65
63
- jsonKeyFile = new File (jsonKeyCredFilePath );
66
+ jsonKeyFile = new File (jsonKeyDirectoryPath , jsonKeyFilename );
64
67
if (!jsonKeyFile .exists ()) {
65
68
throw new IllegalArgumentException (
66
- "JSON key file does not exist: (filePath)" + jsonKeyCredFilePath );
69
+ "JSON key file does not exist: (directory)"
70
+ + jsonKeyDirectoryPath
71
+ + ", (filename)"
72
+ + jsonKeyFilename );
67
73
}
68
74
}
69
75
}
0 commit comments