Skip to content

Commit fdb0611

Browse files
ADC Authentication support for Integration tests in gcsio layer (GoogleCloudDataproc#1361)
* ADC Authentication support * Removed unnecessary comments * Refactor: Centralize GCS_TEST_APPLICATION_DEFAULT_ENABLE config access Previously, GCS_TEST_APPLICATION_DEFAULT_ENABLE was retrieved directly within the code consuming it. This commit moves the retrieval logic to `TestConfiguration.java`. * Added null check for environment variable and removed whitespaces by mvn spotless:apply * Removed empty lines in the code * Resolved spotless:apply iisues * Modified nested if else block in GetCredentials and replaced it with ternary operator in GoogleCloudStorageTestHelper.java for better code readability. --------- Co-authored-by: Animesh Gupta <animgupt@google.com>
1 parent 3686c26 commit fdb0611

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

gcsio/src/test/java/com/google/cloud/hadoop/gcsio/integration/GoogleCloudStorageTestHelper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.google.api.services.storage.model.StorageObject;
3030
import com.google.auth.Credentials;
3131
import com.google.auth.oauth2.ComputeEngineCredentials;
32+
import com.google.auth.oauth2.GoogleCredentials;
3233
import com.google.auth.oauth2.ServiceAccountCredentials;
3334
import com.google.cloud.hadoop.gcsio.GoogleCloudStorage;
3435
import com.google.cloud.hadoop.gcsio.GoogleCloudStorageClientImpl;
@@ -101,7 +102,11 @@ public static Credentials getCredentials() throws IOException {
101102
String serviceAccountJsonKeyFile =
102103
TestConfiguration.getInstance().getServiceAccountJsonKeyFile();
103104
if (serviceAccountJsonKeyFile == null) {
104-
return ComputeEngineCredentials.create().createScoped(StorageScopes.CLOUD_PLATFORM);
105+
Boolean isApplicationDefaultModeEnabled =
106+
TestConfiguration.getInstance().isApplicationDefaultModeEnabled();
107+
return isApplicationDefaultModeEnabled
108+
? GoogleCredentials.getApplicationDefault()
109+
: ComputeEngineCredentials.create().createScoped(StorageScopes.CLOUD_PLATFORM);
105110
}
106111
try (FileInputStream fis = new FileInputStream(serviceAccountJsonKeyFile)) {
107112
return ServiceAccountCredentials.fromStream(fis).createScoped(StorageScopes.CLOUD_PLATFORM);

0 commit comments

Comments
 (0)