diff --git a/datarepo-clienttests/src/main/java/runner/config/ServiceAccountSpecification.java b/datarepo-clienttests/src/main/java/runner/config/ServiceAccountSpecification.java index b4718838ac..9e6d5f0bef 100644 --- a/datarepo-clienttests/src/main/java/runner/config/ServiceAccountSpecification.java +++ b/datarepo-clienttests/src/main/java/runner/config/ServiceAccountSpecification.java @@ -7,13 +7,14 @@ public class ServiceAccountSpecification implements SpecificationInterface { public String name; - public String jsonKeyCredFilePath; + public String jsonKeyDirectoryPath; + public String jsonKeyFilename; public File jsonKeyFile; public static final String resourceDirectory = "serviceaccounts"; - public static final String keyCredFilePathEnvironmentVarName = - "GOOGLE_APPLICATION_CREDENTIALS"; + public static final String keyDirectoryPathEnvironmentVarName = + "TEST_RUNNER_SA_KEY_DIRECTORY_PATH"; ServiceAccountSpecification() {} @@ -33,20 +34,20 @@ public static ServiceAccountSpecification fromJSONFile(String resourceFileName) ServiceAccountSpecification serviceAccount = objectMapper.readValue(inputStream, ServiceAccountSpecification.class); - String credFilePathEnvVarOverride = readCredFilePathEnvironmentVariable(); - if (credFilePathEnvVarOverride != null) { - serviceAccount.jsonKeyCredFilePath = credFilePathEnvVarOverride; + String keyDirectoryPathEnvVarOverride = readKeyDirectoryPathEnvironmentVariable(); + if (keyDirectoryPathEnvVarOverride != null) { + serviceAccount.jsonKeyDirectoryPath = keyDirectoryPathEnvVarOverride; } return serviceAccount; } - protected static String readCredFilePathEnvironmentVariable() { - // look for a full file path defined for the service account credentials + protected static String readKeyDirectoryPathEnvironmentVariable() { + // look for the service account JSON key file in a directory defined by, in order: // 1. environment variable - // 2. service account jsonKeyCredFilePath property - String keyCredFilePathEnvironmentVarValue = System.getenv(keyCredFilePathEnvironmentVarName); - return keyCredFilePathEnvironmentVarValue; + // 2. service account jsonKeyDirectoryPath property + String keyDirectoryPathEnvironmentVarValue = System.getenv(keyDirectoryPathEnvironmentVarName); + return keyDirectoryPathEnvironmentVarValue; } /** @@ -56,14 +57,19 @@ protected static String readCredFilePathEnvironmentVariable() { public void validate() { if (name == null || name.equals("")) { throw new IllegalArgumentException("Service account name cannot be empty"); - } else if (jsonKeyCredFilePath == null || jsonKeyCredFilePath.equals("")) { - throw new IllegalArgumentException("JSON key file path cannot be empty"); + } else if (jsonKeyFilename == null || jsonKeyFilename.equals("")) { + throw new IllegalArgumentException("JSON key file name cannot be empty"); + } else if (jsonKeyDirectoryPath == null || jsonKeyDirectoryPath.equals("")) { + throw new IllegalArgumentException("JSON key directory path cannot be empty"); } - jsonKeyFile = new File(jsonKeyCredFilePath); + jsonKeyFile = new File(jsonKeyDirectoryPath, jsonKeyFilename); if (!jsonKeyFile.exists()) { throw new IllegalArgumentException( - "JSON key file does not exist: (filePath)" + jsonKeyCredFilePath); + "JSON key file does not exist: (directory)" + + jsonKeyDirectoryPath + + ", (filename)" + + jsonKeyFilename); } } } diff --git a/datarepo-clienttests/src/main/resources/servers/staging.json b/datarepo-clienttests/src/main/resources/servers/staging.json index 7fbee79d3a..7e8cf98694 100644 --- a/datarepo-clienttests/src/main/resources/servers/staging.json +++ b/datarepo-clienttests/src/main/resources/servers/staging.json @@ -14,7 +14,7 @@ "name": "ModularHelmChart", "parameters": ["https://raw.githubusercontent.com/broadinstitute/datarepo-helm-definitions/master/staging/datarepo-api.yaml"] }, - "testRunnerServiceAccountFile": "jade-k8-sa.json", + "testRunnerServiceAccountFile": "staging-test-runner-sa.json", "skipDeployment": true, "skipKubernetes": true } diff --git a/datarepo-clienttests/src/main/resources/serviceaccounts/jade-k8-sa.json b/datarepo-clienttests/src/main/resources/serviceaccounts/jade-k8-sa.json index 8236ef34e7..cc9e7649b3 100644 --- a/datarepo-clienttests/src/main/resources/serviceaccounts/jade-k8-sa.json +++ b/datarepo-clienttests/src/main/resources/serviceaccounts/jade-k8-sa.json @@ -1,4 +1,5 @@ { "name": "jade-k8-sa@broad-jade-dev.iam.gserviceaccount.com", - "jsonKeyCredFilePath": "/tmp/jade-dev-account.json" + "jsonKeyFilename": "jade-dev-account.json", + "jsonKeyDirectoryPath": "/tmp" } diff --git a/datarepo-clienttests/src/main/resources/serviceaccounts/staging-test-runner-sa.json b/datarepo-clienttests/src/main/resources/serviceaccounts/staging-test-runner-sa.json index 4e367000bd..0ea06036ef 100644 --- a/datarepo-clienttests/src/main/resources/serviceaccounts/staging-test-runner-sa.json +++ b/datarepo-clienttests/src/main/resources/serviceaccounts/staging-test-runner-sa.json @@ -1,4 +1,5 @@ { "name": "datarepo-jade-test-runner@terra-datarepo-staging.iam.gserviceaccount.com", - "jsonKeyCredFilePath": "/tmp/staging-test-runner.json" + "jsonKeyFilename": "staging-test-runner.json", + "jsonKeyDirectoryPath": "/tmp" }