Commit 829e091f authored by Riabokon Stanislav(EPAM)[GCP]'s avatar Riabokon Stanislav(EPAM)[GCP]
Browse files

Merge branch 'feature/GONRG-1111' into 'integration-master'

GONRG-1111 Support optionally encrypted credentials from file or content for DE_OPS_TESTER, DE_ADMIN_TESTER, DE_EDITOR_TESTER, DE_NO_ACCESS_TESTER accounts

Closes GONRG-1111

See merge request go3-nrg/platform/System/notification!17
parents 778bac8e 0ab2821f
Pipeline #16348 passed with stages
in 15 minutes and 46 seconds
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
<relativePath>../pom.xml</relativePath> <relativePath>../pom.xml</relativePath>
</parent> </parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>notification-test-gcp</artifactId> <artifactId>notification-test-gcp</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<name>notification-test-gcp</name> <name>notification-test-gcp</name>
...@@ -51,8 +50,16 @@ ...@@ -51,8 +50,16 @@
<artifactId>os-core-common</artifactId> <artifactId>os-core-common</artifactId>
<version>0.3.6</version> <version>0.3.6</version>
</dependency> </dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.8</version>
</dependency>
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-test-lib-gcp</artifactId>
<version>0.0.2</version>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
package org.opengroup.osdu.notification.util; package org.opengroup.osdu.notification.util;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GCPTestUtils extends TestUtils { public class GCPTestUtils extends TestUtils {
public GCPTestUtils() { public GCPTestUtils() {
...@@ -41,12 +43,13 @@ public class GCPTestUtils extends TestUtils { ...@@ -41,12 +43,13 @@ public class GCPTestUtils extends TestUtils {
} }
private String getToken(String testerEnvVar) throws Exception { 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")); String audience = System.getProperty("INTEGRATION_TEST_AUDIENCE", System.getenv("INTEGRATION_TEST_AUDIENCE"));
if (Strings.isNullOrEmpty(audience)) { if (Strings.isNullOrEmpty(audience)) {
audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com"; audience = "245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com";
} }
String token = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience); String token = new GoogleServiceAccount(serviceAccountValue).getAuthToken(audience);
return "Bearer " + token; return "Bearer " + token;
} }
} }
...@@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpPost; ...@@ -15,6 +15,7 @@ import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair; import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.opengroup.osdu.config.util.DecodedContentExtractor;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
...@@ -24,14 +25,14 @@ import java.util.Base64; ...@@ -24,14 +25,14 @@ import java.util.Base64;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.opengroup.osdu.config.util.DecodedContentExtractorUtil.NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER;
public class GoogleServiceAccount { public class GoogleServiceAccount {
public GoogleServiceAccount(String serviceAccountEncoded)throws IOException { public GoogleServiceAccount(String serviceAccountValue)throws IOException {
this(Base64.getDecoder().decode(serviceAccountEncoded)); serviceAccountValue = new DecodedContentExtractor(serviceAccountValue, NAIVE_JSON_CONTENT_ACCEPTANCE_TESTER).getContent();
}
public GoogleServiceAccount(byte[] serviceAccountJson)throws IOException {
try(InputStream inputStream = new ByteArrayInputStream(serviceAccountJson)) {
serviceAccount = ServiceAccountCredentials.fromStream(inputStream); try (InputStream inputStream = new ByteArrayInputStream(serviceAccountValue.getBytes())) {
this.serviceAccount = ServiceAccountCredentials.fromStream(inputStream);
} }
} }
...@@ -77,7 +78,6 @@ public class GoogleServiceAccount { ...@@ -77,7 +78,6 @@ public class GoogleServiceAccount {
if(auth == null){ if(auth == null){
throw new IOException("Failed to retrieve auth token for credentials " + jwt); throw new IOException("Failed to retrieve auth token for credentials " + jwt);
} }
String output = auth.getAsString(); return auth.getAsString();
return output;
} }
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment