Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix vrealize:push fails for vCD 10.5, API version 38.0 #183

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [packages/ecmascript] IAC-803 / Updated `Array.from()` to create shallow clone and to properly handle string, Map and Set input.
* [artifact-manager] IAC-799 / Wrong unix file path separators when creating backup path.
* [artifact-manager] IAC-778 / Backup only works with current package version, otherwise throws exception 404 not found.
* [vCD-NG] 166 / fix VMware Cloud Director API version 38.0 and later do not support the /api/sessions API login endpoint

## v2.36.0 - 16 Nov 2023

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public class RestClientVcdBasicAuthInterceptor extends RestClientRequestIntercep
private MediaType contentType;

/**
* session api path.
* Provider session api path.
*/
private static final String URL_SESSION = "/api/sessions";
private static final String PROVIDER_URL_SESSION = "/cloudapi/1.0.0/sessions/provider";

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest to make both the REST endpoint backward compatible with old API version, for example check the vCD API version and if it is >= 38.0 then use the PROVIDER_URL_SESSION otherwise to use URL_SESSION

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your feedback.
According to the API documentation is available since API v33 - https://developer.vmware.com/apis/vmware-cloud-director/latest/cloudapi/1.0.0/sessions/provider/post/

From these docs we can see v33 is mapped to VCD 10, which is deprecated -> https://developer.vmware.com/docs/14143/vmware-cloud-director-api-programming-guide/

Should we support deprecated versions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @akantchev 's idea is to have support for backwards compatibility in case the user is running on an older vCD version which supports just the old api

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see the second link isn't working properly - I am attaching another one - https://docs.vmware.com/en/VMware-Cloud-Director/index.html
VCD API version <=34 is deprecated and not supported, and this change supports =>33

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changing should be fine. The old endpoint will be for very old VCD versions that are out of support for more than an year (10.1 (v34) EOL is 2022-04-09)

/**
* version api path.
Expand Down Expand Up @@ -102,7 +102,7 @@ protected RestClientVcdBasicAuthInterceptor(ConfigurationVcd configuration, Rest
apiVersion = API_VERSION_37;
}

this.contentType = VcdApiHelper.buildMediaType("application/*+json", apiVersion);
this.contentType = VcdApiHelper.buildMediaType("application/json", apiVersion);
}

/**
Expand All @@ -116,8 +116,8 @@ protected RestClientVcdBasicAuthInterceptor(ConfigurationVcd configuration, Rest
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) {
try {
if (!request.getURI().getPath().contains(URL_SESSION) && !request.getURI().getPath().contains(URL_VERSION)) {
if (this.vcloudToken == null) {
if (!request.getURI().getPath().contains(PROVIDER_URL_SESSION) && !request.getURI().getPath().contains(URL_VERSION)) {
if (this.bearerToken == null) {
logger.info("Aquiring vCD auth token...");
acquireToken(request);
logger.info("vCD auth token aquired");
Expand All @@ -135,7 +135,7 @@ public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttp

private void acquireToken(HttpRequest request) throws JsonProcessingException {
final URI tokenUri = UriComponentsBuilder.newInstance().scheme(request.getURI().getScheme())
.host(request.getURI().getHost()).port(request.getURI().getPort()).path(URL_SESSION).build().toUri();
.host(request.getURI().getHost()).port(request.getURI().getPort()).path(PROVIDER_URL_SESSION).build().toUri();

// Prepare Headers
final HttpHeaders headers = new HttpHeaders();
Expand All @@ -153,7 +153,7 @@ private void acquireToken(HttpRequest request) throws JsonProcessingException {

final ResponseEntity<String> response = getRestTemplate().exchange(tokenUri, HttpMethod.POST, entity,
String.class);
this.vcloudToken = response.getHeaders().get(HEADER_VCLOUD_TOKEN).get(0);
this.vcloudToken = response.getHeaders().get(HEADER_VCLOUD_TOKEN) == null ? null : response.getHeaders().get(HEADER_VCLOUD_TOKEN).get(0);
this.bearerToken = response.getHeaders().get(HEADER_BEARER_TOKEN).get(0);
}

Expand Down
23 changes: 21 additions & 2 deletions docs/versions/latest/Release.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
[//]: # (You can utilize internal links /e.g. link to the upgrade procedure, link to the improvement|deprecation that introduced this/)

## Deprecations
[//]: # (### *Deprecation*)
[//]: # (Explain what is deprecated and suggest alternatives)
### `vrealize:push` is no longer supported for vCloud Director for Service Providers 9.7 (API version 32.0) - officially unsupported
The new authorization endpoint cloudapi/1.0.0/sessions/provider/post is available after API Version 33.0
Reference:
[VMware Cloud Director API Programming Guide](https://developer.vmware.com/docs/14143/vmware-cloud-director-api-programming-guide)
[VMware Cloud Director OpenAPI Sessions](https://developer.vmware.com/apis/vmware-cloud-director/latest/cloudapi/1.0.0/sessions/provider/post/)

### Deprecating SQLDatabaseManager.getDatabase() function

SQLDatabaseManager.getDatabase() function is removed in vRA 7.6 / Aria Automation 8 and above. The function uses name as parameter to retrieve a database. Use getDatabaseById() or getDatabases() and filter by name instead.

[//]: # (Features -> New Functionality)
## Features
Expand Down Expand Up @@ -73,6 +80,18 @@ Back up of vRO packages now works by:
[//]: # (Optional But higlhy recommended Specify *NONE* if missing)
[//]: # (#### Relevant Documentation:)

### Support `vrealize:push` for VMware Cloud Director 10.5 (API version 38.0)

#### Previous Behavior
The /api/sessions API login endpoint is deprecated since VMware Cloud Director API version 33.0. For version 38.0 and later, the /api/sessions API login endpoint is no longer supported. You can use the VMware Cloud Director OpenAPI login endpoints to access VMware Cloud Director.

#### New Behavior
Service provider access to the system organization- POST cloudapi/1.0.0/sessions/provider
Tenant access to all other organizations apart from the system organization- POST cloudapi/1.0.0/sessions

As per the backward compatibility commitment of VMware Cloud Director, versions 37.2 and earlier continue to support the /api/sessions API login endpoint.
Reference: [VMware Cloud Director 10.5 Release Notes](https://docs.vmware.com/en/VMware-Cloud-Director/10.5/rn/vmware-cloud-director-105-release-notes/index.html)

### Fix vRA Catalog Items Paging Issue when Fetching Catalog Items from Server

#### Previous Behavior
Expand Down