Skip to content

Commit

Permalink
refactor!: Moved the rest clients and helpers
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Genov <stefan.genov@broadcom.com>
  • Loading branch information
Michaelpalacce committed Dec 17, 2024
1 parent 4b0e807 commit 0a6074a
Show file tree
Hide file tree
Showing 49 changed files with 120 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.vmware.pscoe.iac.artifact.model.abx.AbxPackageContent;
import com.vmware.pscoe.iac.artifact.model.abx.AbxPackageDescriptor;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgSecret;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import org.apache.commons.lang3.NotImplementedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.vmware.pscoe.iac.artifact.model.abx.AbxAction;
import com.vmware.pscoe.iac.artifact.model.abx.AbxActionVersion;
import com.vmware.pscoe.iac.artifact.model.abx.AbxPackageDescriptor;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;

public class AbxReleaseManager {
private final Logger logger = LoggerFactory.getLogger(AbxReleaseManager.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.configuration.ConfigurationVraNg;
import com.vmware.pscoe.iac.artifact.cli.CliManagerFactory;
import com.vmware.pscoe.iac.artifact.cli.CliManagerVrops;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageAdapter;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageContent;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.store.VraNgTypeStoreFactory;

import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.rest;
package com.vmware.pscoe.iac.artifact.aria.rest;

import java.io.File;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -73,7 +73,7 @@ public class RestClientVraNg extends RestClientVraNgPrimitive {
* @param configuration configuration vra
* @param restTemplate rest template
*/
protected RestClientVraNg(final ConfigurationVraNg configuration, final RestTemplate restTemplate) {
public RestClientVraNg(final ConfigurationVraNg configuration, final RestTemplate restTemplate) {
super(configuration, restTemplate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
* This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file.
* #L%
*/
package com.vmware.pscoe.iac.artifact.rest;
package com.vmware.pscoe.iac.artifact.aria.rest;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.jsonpath.DocumentContext;
import com.jayway.jsonpath.JsonPath;
import com.vmware.pscoe.iac.artifact.aria.configuration.ConfigurationVraNg;
import com.vmware.pscoe.iac.artifact.rest.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.*;
Expand Down Expand Up @@ -47,7 +48,7 @@ public class RestClientVraNgAuthNInterceptor extends RestClientRequestIntercepto
private String tokenType;
private LocalDateTime tokenExpirationDate;

protected RestClientVraNgAuthNInterceptor(ConfigurationVraNg configuration, RestTemplate restTemplate) {
public RestClientVraNgAuthNInterceptor(ConfigurationVraNg configuration, RestTemplate restTemplate) {
super(configuration, restTemplate);
this.tokenType = DEFAULT_TOKEN_TYPE;
}
Expand All @@ -60,9 +61,9 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp
acquireToken(request);
}
if (this.token != null) {
request.getHeaders().add("Authorization", this.tokenType + " " + this.token);
request.getHeaders().add("Authorization", this.tokenType + " " + this.token);
}

return execution.execute(request, body);
} catch (Exception e) {
throw new RuntimeException(e);
Expand All @@ -77,7 +78,8 @@ private void acquireToken(HttpRequest request) throws JsonProcessingException {
} else {
logger.info("Acquiring refresh token with credentials");
ResponseEntity<String> requestWithCredentialsResponse = this.requestWithCredentials(request);
DocumentContext requestWithCredentialsResponseBody = JsonPath.parse(requestWithCredentialsResponse.getBody());
DocumentContext requestWithCredentialsResponseBody = JsonPath
.parse(requestWithCredentialsResponse.getBody());
refreshToken = requestWithCredentialsResponseBody.read("$.refresh_token");
}

Expand All @@ -87,16 +89,18 @@ private void acquireToken(HttpRequest request) throws JsonProcessingException {
final int expiresIn = responseBody.jsonString().contains("expires_in") ? responseBody.read("$.expires_in") : 0;
this.tokenExpirationDate = now.plus(expiresIn, ChronoField.SECOND_OF_MINUTE.getBaseUnit());
this.token = responseBody.jsonString().contains("access_token") ? responseBody.read("$.access_token") : null;
String tokenTypeFromResponse = responseBody.jsonString().contains("token_type") ? responseBody.read("$.token_type") : null;
String tokenTypeFromResponse = responseBody.jsonString().contains("token_type")
? responseBody.read("$.token_type")
: null;
this.setTokenType(tokenTypeFromResponse);
}

private ResponseEntity<String> requestWithRefreshToken(HttpRequest request, String refreshToken) {
final URI tokenUri = UriComponentsBuilder.newInstance()
.scheme(request.getURI().getScheme())
.host(this.getConfiguration().getAuthHost())
.port(this.getConfiguration().getPort())
.path(SERVICE_REFRESH_TOKEN).build().toUri();
.scheme(request.getURI().getScheme())
.host(this.getConfiguration().getAuthHost())
.port(this.getConfiguration().getPort())
.path(SERVICE_REFRESH_TOKEN).build().toUri();

logger.info("Token URI: {}", tokenUri);
// Prepare Headers
Expand All @@ -114,12 +118,12 @@ private ResponseEntity<String> requestWithRefreshToken(HttpRequest request, Stri

private ResponseEntity<String> requestWithCredentials(HttpRequest request) throws JsonProcessingException {
final URI tokenUri = UriComponentsBuilder.newInstance()
.scheme(request.getURI().getScheme())
.host(this.getConfiguration().getAuthHost())
.port(this.getConfiguration().getPort())
.path(SERVICE_CREDENTIALS)
.queryParam("access_token")
.build().toUri();
.scheme(request.getURI().getScheme())
.host(this.getConfiguration().getAuthHost())
.port(this.getConfiguration().getPort())
.path(SERVICE_CREDENTIALS)
.queryParam("access_token")
.build().toUri();

logger.info("Auth URL: {}", tokenUri);

Expand Down Expand Up @@ -147,7 +151,8 @@ private ResponseEntity<String> requestWithCredentials(HttpRequest request) throw
}

private boolean isRequestInBlackList(HttpRequest request) {
return request.getURI().getPath().contains(SERVICE_REFRESH_TOKEN) || request.getURI().getPath().contains(SERVICE_CREDENTIALS);
return request.getURI().getPath().contains(SERVICE_REFRESH_TOKEN)
|| request.getURI().getPath().contains(SERVICE_CREDENTIALS);
}

private boolean hasValidToken() {
Expand All @@ -161,7 +166,7 @@ private boolean isValidTokenType(String tokenType) {
private void setTokenType(String newTokenType) {
if (this.isValidTokenType(newTokenType)) {
// Capitalized for case sensitive Auth schemes
this.tokenType = newTokenType.substring(0,1).toUpperCase() + newTokenType.substring(1).toLowerCase();
this.tokenType = newTokenType.substring(0, 1).toUpperCase() + newTokenType.substring(1).toLowerCase();
} else if (this.tokenType == null) {
this.tokenType = DEFAULT_TOKEN_TYPE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* Package.
*/
package com.vmware.pscoe.iac.artifact.rest;
package com.vmware.pscoe.iac.artifact.aria.rest;

import java.io.File;
import java.io.IOException;
Expand All @@ -38,7 +38,7 @@
import com.vmware.pscoe.iac.artifact.model.abx.AbxAction;
import com.vmware.pscoe.iac.artifact.model.abx.AbxActionVersion;
import com.vmware.pscoe.iac.artifact.model.abx.AbxConstant;

import com.vmware.pscoe.iac.artifact.rest.RestClient;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgApprovalPolicy;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgBlueprint;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgCatalogEntitlement;
Expand Down Expand Up @@ -68,7 +68,7 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgSubscription;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgWorkflowContentSource;

import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;

import org.apache.commons.lang3.StringUtils;
import org.apache.hc.core5.net.URIBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgIntegration;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.utils.VraNgIntegrationUtils;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgIntegrationUtils;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.gson.stream.JsonReader;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgApprovalPolicy;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.stream.JsonReader;
import com.vmware.pscoe.iac.artifact.VraNgReleaseManager;
import com.vmware.pscoe.iac.artifact.aria.store.helpers.VraNgReleaseManager;
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgBlueprint;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFolderFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgContentSourceBase;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgItem;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;

public class VraNgContentSharingPolicyStore extends AbstractVraNgStore {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgWorkflow;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgWorkflowContentSource;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgIntegrationUtils;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgIntegrationUtils;
import org.apache.commons.lang3.StringUtils;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgCustomResource;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.utils.VraNgProjectUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgProjectUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.gson.stream.JsonReader;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgDay2ActionsPolicy;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import com.google.gson.stream.JsonReader;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgDeploymentLimitPolicy;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgContentSourceType;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgProject;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import org.apache.commons.lang3.StringUtils;
import org.yaml.snakeyaml.DumperOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import java.util.List;
import java.util.Map;

import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPropertyGroup;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;

import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;

import static com.vmware.pscoe.iac.artifact.aria.store.VraNgDirs.DIR_PROPERTY_GROUPS;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgResourceAction;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgProjectUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgProjectUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgResourceQuotaPolicy;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;

import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgProject;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgSubscription;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.store.filters.CustomFolderFileFilter;
import com.vmware.pscoe.iac.artifact.utils.VraNgOrganizationUtil;
import com.vmware.pscoe.iac.artifact.aria.utils.VraNgOrganizationUtil;

import org.apache.commons.io.FileUtils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.vmware.pscoe.iac.artifact.model.Package;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageContent;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageDescriptor;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;

import static com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageContent.ContentType.APPROVAL_POLICY;
import static com.vmware.pscoe.iac.artifact.aria.model.VraNgPackageContent.ContentType.BLUEPRINT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.vmware.pscoe.iac.artifact.aria.model.VraNgContentSource;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgContentSourceBase;
import com.vmware.pscoe.iac.artifact.aria.model.VraNgContentSourceType;
import com.vmware.pscoe.iac.artifact.rest.RestClientVraNg;
import com.vmware.pscoe.iac.artifact.aria.rest.RestClientVraNg;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Loading

0 comments on commit 0a6074a

Please sign in to comment.