Commit 4e889f04 authored by Auto GO3-NRG Ticket's avatar Auto GO3-NRG Ticket
Browse files

Auto commit when pipeline succeeds

parents f258d5a4 5d9c6cd0
......@@ -17,11 +17,7 @@ variables:
OSDU_GCP_SERVICE: delivery
OSDU_GCP_VENDOR: gcp
OSDU_GCP_APPLICATION_NAME: os-delivery
OSDU_GCP_REDIS_HOST: 10.234.198.27
OSDU_GCP_SEARCH_QUERY_URL: https://os-search-dot-nice-etching-277309.uc.r.appspot.com//api/search/v2/query
OSDU_GCP_ENV_VARS: GCP_ENTITLEMENTS_URL=$OSDU_GCP_ENTITLEMENTS_URL,GCP_SEARCH_QUERY_URL=$OSDU_GCP_SEARCH_QUERY_URL,GCP_REDIS_HOST=$OSDU_GCP_REDIS_HOST --vpc-connector=$OSDU_GCP_VPC_CONNECTOR
OSDU_GCP_PORT: 8080
# --- end of osud gcp specific variables ---
OSDU_GCP_ENV_VARS: GCP_ENTITLEMENTS_URL=$OSDU_GCP_ENTITLEMENTS_URL,GCP_SEARCH_QUERY_URL=$OSDU_GCP_SEARCH_QUERY_URL,GCP_REDIS_HOST=$REDIS_GROUP_HOST --vpc-connector=$OSDU_GCP_VPC_CONNECTOR
include:
- project: 'osdu/platform/ci-cd-pipelines'
......@@ -57,3 +53,6 @@ include:
eslint-sast:
rules:
- when: never
osdu-gcp-test:
allow_failure: false
......@@ -157,6 +157,19 @@
<artifactId>log4j-to-slf4j</artifactId>
<version>2.11.2</version>
</dependency>
<!--Utilising AzureServicePrinciple class from Core Lib Azure Library -->
<dependency>
<groupId>org.opengroup.osdu</groupId>
<artifactId>core-lib-azure</artifactId>
<version>0.0.28</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>com.azure</groupId>
<artifactId>azure-core-http-netty</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
......
......@@ -14,75 +14,15 @@
package org.opengroup.osdu.util;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import org.opengroup.osdu.azure.util.AzureServicePrincipal;
class JwtTokenUtil {
static String getAccessToken() throws Exception {
return getAccessToken(AzureTestConfig.getsp_id(), AzureTestConfig.getsp_secret(), AzureTestConfig.getTenant_id(), AzureTestConfig.getApp_resource_id());
}
static String getAccessToken(String sp_id, String sp_secret, String tenant_id, String app_resource_id) throws Exception {
String aad_endpoint = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenant_id);
URL url = new URL(aad_endpoint);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
Map<String, String> parameters = new HashMap<>();
parameters.put("grant_type", "client_credentials");
parameters.put("client_id", sp_id);
parameters.put("client_secret", sp_secret);
parameters.put("resource", app_resource_id);
con.setDoOutput(true);
DataOutputStream out = new DataOutputStream(con.getOutputStream());
out.writeBytes(getParamsString(parameters));
out.flush();
out.close();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
in.close();
con.disconnect();
Gson gson = new Gson();
JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class);
String token = jobj.get("access_token").getAsString();
return token;
return new AzureServicePrincipal().getIdToken(AzureTestConfig.getsp_id(), AzureTestConfig.getsp_secret(), AzureTestConfig.getTenant_id(), AzureTestConfig.getApp_resource_id());
}
private static String getParamsString(Map<String, String> params)
throws UnsupportedEncodingException {
StringBuilder result = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
result.append("=");
result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
result.append("&");
}
String resultString = result.toString();
return resultString.length() > 0
? resultString.substring(0, resultString.length() - 1)
: resultString;
}
}
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