Skip to content

Commit

Permalink
Reset datarepo-clienttests - didn't work to use a single service account
Browse files Browse the repository at this point in the history
  • Loading branch information
snf2ye committed Dec 17, 2024
1 parent f9c2158 commit cc8d08c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}

Expand All @@ -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;
}

/**
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "[email protected]",
"jsonKeyCredFilePath": "/tmp/jade-dev-account.json"
"jsonKeyFilename": "jade-dev-account.json",
"jsonKeyDirectoryPath": "/tmp"
}
Original file line number Diff line number Diff line change
@@ -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"
}

0 comments on commit cc8d08c

Please sign in to comment.