Skip to content
Snippets Groups Projects
Commit bc168792 authored by Rostislav Dublin (EPAM)'s avatar Rostislav Dublin (EPAM) Committed by Riabokon Stanislav(EPAM)[GCP]
Browse files

GONRG-1110 Optionally encrypted credentials from file or content for...

GONRG-1110 Optionally encrypted credentials from file or content for DE_OPS_TESTER, DE_ADMIN_TESTER, DE_EDITOR_TESTER, DE_NO_ACCESS_TESTER accounts
parent c92aa926
No related branches found
No related tags found
5 merge requests!73Register Service: Audit Logs Implementation (GONRG-1761),!71Logging Enhancements for GCP modules (GONRG-1735, GONRG-1779),!67GCP release/0.5 - fix GSA Challenge (GONRG-1796),!56Gcp fix sonar comments (GONRG-1370),!40GCP Flexible ENV VARS (DE_OPS_TESTER, DE_ADMIN_TESTER, DE_EDITOR_TESTER, DE_NO_ACCESS_TESTER) ingestion logic (GONRG-1110)
......@@ -27,12 +27,11 @@
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.opengroup.osdu.register</groupId>
<artifactId>register-test-gcp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Register service GCP integration tests </description>
<description>Register service GCP integration tests</description>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
......@@ -108,6 +107,11 @@
<artifactId>core-lib-gcp</artifactId>
<version>0.1.21</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-test-lib-gcp</artifactId>
<version>0.0.2</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu.register</groupId>
<artifactId>register-test-core</artifactId>
......
package org.opengroup.osdu.register.util;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.NullArgumentException;
@Slf4j
public class GCPTestUtils extends TestUtils {
@Override
......@@ -38,12 +40,13 @@ public class GCPTestUtils extends TestUtils {
}
private String getToken(String testerEnvVar) throws Exception {
String serviceAccountFile = System.getProperty(testerEnvVar, System.getenv(testerEnvVar));
log.info("Get {}} credentials", testerEnvVar);
String serviceAccountValue = System.getProperty(testerEnvVar, System.getenv(testerEnvVar));
String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE", System.getenv("INTEGRATION_TEST_AUDIENCE"));
if (Strings.isNullOrEmpty(audience)) {
audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com";
}
return new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience);
return new GoogleServiceAccount(serviceAccountValue).getAuthToken(audience);
}
}
......@@ -30,6 +30,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.opengroup.osdu.config.util.DecodedContentExtractor;
import java.io.ByteArrayInputStream;
import java.io.IOException;
......@@ -39,15 +40,15 @@ import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import static org.opengroup.osdu.config.util.DecodedContentExtractorUtil.NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER;
public class GoogleServiceAccount {
public GoogleServiceAccount(String serviceAccountEncoded) throws IOException {
this(Base64.getDecoder().decode(serviceAccountEncoded));
}
public GoogleServiceAccount(String serviceAccountValue) throws IOException {
public GoogleServiceAccount(byte[] serviceAccountJson) throws IOException {
try (InputStream inputStream = new ByteArrayInputStream(serviceAccountJson)) {
serviceAccountValue = new DecodedContentExtractor(serviceAccountValue, NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER).getContent();
serviceAccount = ServiceAccountCredentials.fromStream(inputStream);
try (InputStream inputStream = new ByteArrayInputStream(serviceAccountValue.getBytes())) {
this.serviceAccount = ServiceAccountCredentials.fromStream(inputStream);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment