Commit fec7480f authored by Rostislav Dublin (EPAM)'s avatar Rostislav Dublin (EPAM)
Browse files

GONRG-1035

*Logs for Subscription exception response
*Docs improvement
parent 72f93c8a
......@@ -27,7 +27,6 @@
<relativePath>../pom.xml</relativePath>
</parent>
<groupId>org.opengroup.osdu</groupId>
<artifactId>notification-test-gcp</artifactId>
<version>1.0-SNAPSHOT</version>
<name>notification-test-gcp</name>
......@@ -51,8 +50,16 @@
<artifactId>os-core-common</artifactId>
<version>0.3.6</version>
</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>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
package org.opengroup.osdu.notification.util;
import com.google.common.base.Strings;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GCPTestUtils extends TestUtils {
public GCPTestUtils() {
......@@ -41,12 +43,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";
}
String token = new GoogleServiceAccount(serviceAccountFile).getAuthToken(audience);
String token = new GoogleServiceAccount(serviceAccountValue).getAuthToken(audience);
return "Bearer " + token;
}
}
......@@ -15,6 +15,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;
......@@ -24,14 +25,14 @@ 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(byte[] serviceAccountJson)throws IOException {
try(InputStream inputStream = new ByteArrayInputStream(serviceAccountJson)) {
public GoogleServiceAccount(String serviceAccountValue)throws IOException {
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);
}
}
......@@ -77,7 +78,6 @@ public class GoogleServiceAccount {
if(auth == null){
throw new IOException("Failed to retrieve auth token for credentials " + jwt);
}
String output = auth.getAsString();
return output;
return auth.getAsString();
}
}
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