Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ Destination loadAndParseDestination( final String destName, final DestinationOpt
{
final String servicePath = PATH_DEFAULT + destName;
final Function<DestinationRetrievalStrategy, DestinationServiceV1Response> destinationRetriever =
strategy -> resilientCall(() -> retrieveDestination(strategy, servicePath), singleDestResilience);
strategy -> resilientCall(() -> retrieveDestination(strategy, servicePath, options), singleDestResilience);

final DestinationRetrievalStrategyResolver destinationRetrievalStrategyResolver =
DestinationRetrievalStrategyResolver
Expand All @@ -145,7 +145,16 @@ Destination loadAndParseDestination( final String destName, final DestinationOpt
DestinationServiceV1Response
retrieveDestination( final DestinationRetrievalStrategy strategy, final String servicePath )
{
final String response = adapter.getConfigurationAsJson(servicePath, strategy);
return retrieveDestination(strategy, servicePath, DestinationOptions.builder().build());
}

@Nonnull
DestinationServiceV1Response retrieveDestination(
final DestinationRetrievalStrategy strategy,
final String servicePath,
final DestinationOptions options )
{
final String response = adapter.getConfigurationAsJson(servicePath, strategy, options);

return deserializeDestinationResponse(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,25 @@ String getConfigurationAsJson(
@Nonnull final DestinationRetrievalStrategy strategy )
throws DestinationAccessException,
DestinationNotFoundException
{
return getConfigurationAsJson(servicePath, strategy, DestinationOptions.builder().build());
}

@Nonnull
String getConfigurationAsJson(
@Nonnull final String servicePath,
@Nonnull final DestinationRetrievalStrategy strategy,
@Nonnull final DestinationOptions options )
throws DestinationAccessException,
DestinationNotFoundException
{
final HttpDestination serviceDestination =
Objects
.requireNonNull(
serviceDestinationLoader.apply(strategy.behalf()),
() -> "Destination for Destination Service on behalf of " + strategy.behalf() + " not found.");

final HttpUriRequest request = prepareRequest(servicePath, strategy);
final HttpUriRequest request = prepareRequest(servicePath, strategy, options);

final HttpResponse response;
try {
Expand Down Expand Up @@ -174,9 +185,20 @@ private static String handleResponse( final HttpUriRequest request, final HttpRe

private HttpUriRequest prepareRequest( final String servicePath, final DestinationRetrievalStrategy strategy )
{
return prepareRequest(servicePath, strategy, DestinationOptions.builder().build());
}

private HttpUriRequest prepareRequest(
final String servicePath,
final DestinationRetrievalStrategy strategy,
final DestinationOptions options )
{
final String apiVersion = DestinationServiceOptionsAugmenter.getApiVersion(options).getOrElse("v1");
final String basePath = "destination-configuration/" + apiVersion;

final URI requestUri;
try {
requestUri = new URI(SERVICE_PATH + servicePath);
requestUri = new URI(basePath + servicePath);
}
catch( final URISyntaxException e ) {
throw new DestinationAccessException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class DestinationServiceOptionsAugmenter implements DestinationOptionsAug
static final String DESTINATION_TOKEN_EXCHANGE_STRATEGY_KEY = "scp.cf.destinationTokenExchangeStrategy";
static final String X_REFRESH_TOKEN_KEY = "x-refresh-token";
static final String X_FRAGMENT_KEY = "X-fragment-name";
static final String DESTINATION_SERVICE_API_VERSION_KEY = "scp.cf.destinationServiceApiVersion";

private final Map<String, Object> parameters = new HashMap<>();

Expand Down Expand Up @@ -105,6 +106,22 @@ public DestinationServiceOptionsAugmenter fragmentName( @Nonnull final String fr
return this;
}

/**
* Sets the API version to use when calling the destination service. This allows opting into newer API versions. If
* not set, the default API version (v1) will be used.
*
* @param apiVersion
* The API version to use (e.g., "v1", "v2").
* @return The same augmenter that called this method.
* @since 5.22.0
*/
@Nonnull
public DestinationServiceOptionsAugmenter apiVersion( @Nonnull final String apiVersion )
{
parameters.put(DESTINATION_SERVICE_API_VERSION_KEY, apiVersion);
return this;
}

@Override
public void augmentBuilder( @Nonnull final DestinationOptions.Builder builder )
{
Expand Down Expand Up @@ -170,4 +187,22 @@ static Option<String> getFragmentName( @Nonnull final DestinationOptions options
{
return options.get(X_FRAGMENT_KEY).filter(String.class::isInstance).map(String.class::cast);
}

/**
* Retrieves the configured API version to use when calling the destination service.
*
* @param options
* The destination options instance that stores the key/value pair.
* @return An {@link Option} wrapping the API version if the parameter is present, otherwise a
* {@link io.vavr.control.Option.None}.
* @since 5.22.0
*/
@Nonnull
static Option<String> getApiVersion( @Nonnull final DestinationOptions options )
{
return options
.get(DESTINATION_SERVICE_API_VERSION_KEY)
.filter(String.class::isInstance)
.map(String.class::cast);
}
}
14 changes: 12 additions & 2 deletions release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,22 @@

### ✨ New Functionality

-
- **Destination Service API Version Support**: Added support for specifying the API version when calling the destination service. Users can now opt into newer API versions (e.g., v2) by using the new `apiVersion()` method on `DestinationServiceOptionsAugmenter`. If not specified, the default API version (v1) is used, ensuring backward compatibility.

Example usage:
```java
// Use the new v2 API
DestinationOptions options = DestinationOptions.builder()
.augmentBuilder(DestinationServiceOptionsAugmenter.augmenter().apiVersion("v2"))
.build();

Destination destination = DestinationAccessor.getDestination("my-destination", options);
```

### 📈 Improvements

-

### 🐛 Fixed Issues

-
-
Loading