Skip to content

Change ScpCf modules behaviour with DwC bindings - #104

Merged
CharlesDuboisSAP merged 5 commits into
mainfrom
change-dwc-bindings-behaviour-in-scp-cf-modules
Oct 24, 2023
Merged

CharlesDuboisSAP merged 5 commits into
mainfrom
change-dwc-bindings-behaviour-in-scp-cf-modules

Conversation

@CharlesDuboisSAP

@CharlesDuboisSAP CharlesDuboisSAP commented Oct 23, 2023 •

Copy link
Copy Markdown
Contributor

Context

DwC apps cannot call ScpCfCloudPlatform without the DWC_APPLICATION env var. This was introduced in #98.

Solution

Here is the intended stacktrace from top to bottom

  • DwcConfiguration throws
  • then MegacliteServiceBinding catches and returns an empty map
  • then ScpCfCloudPlatform works normally
  • then ScpCfDestinationServiceAdapter throws if the map is empty.

Questions for the Reviewer

  • What should the message thrown by ScpCfDestinationServiceAdapter be?
    • Maybe it should be "No DWC_APPLICATION environment variable defined. Cannot determine the provider account id.". Not sure if there is a scenario in which the Adapter doesn't find tenantid while the binding is not DwC
    • Answer: A generic message is fine because a DwC error should be thrown in another operation beforehand.
  • Do the new test dependencies cause a problem?
    • Answer: No.
  • Is there still a need for DwcConfiguration to be public to help customer test their app locally without setting an env var?
    • Answer: Maybe, can be discussed.
  • Can the Exception hidden by MegacliteServiceBinding.getCredentials() cause problem for customers with broken configs?
    • Answer: No, the MegacliteServiceBinding previously returned an empty map. Also a meaningful DwC error should be thrown in another operation beforehand.

@CharlesDuboisSAP CharlesDuboisSAP self-assigned this Oct 23, 2023
Comment on lines +90 to +91
if( credentials.containsKey("tenantid") ) {
return credentials.getString("tenantid");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about extracting this hard-coded string (tenantid) to some proper constant?

(Maybe within the MegacliteServiceBinding class?)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AFAIK tenantId is used for other platforms as well.
tenantId would ne declared high up the hierarchy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I would like to but that would require adding dwc dependencies (MegacliteServiceBinding) in scp-cf modules (ScpCfDestinationServiceAdapter) or the other way around.

Comment on lines +310 to +311
// DwC: The binding doesn't have credentials, MegacliteServiceBinding either reads the DWC_APPLICATION env var
// and returns the map {tenantid: <ProviderTenantId>}, or, returns an empty map if DWC_APPLICATION is not found.

@Johannes-Schneider Johannes-Schneider Oct 23, 2023 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[question]
Has there been a decision whether we keep our old Service Binding (aka Map<String, JsonObject>) API?
Or are these changes here just to make the transition smoother?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Matthias mentioned he wanted to delete/redo this API

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good 👍

I'm still wondering about this comment... It doesn't make a lot of sense to me. Why are we mentioning the DwC case here explicitly?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm just helping the next developer that will maintain this code, I can remove it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Personally, I find it more confusing than it helps... But maybe I'm the only one 😅

@CharlesDuboisSAP
CharlesDuboisSAP marked this pull request as ready for review October 24, 2023 06:12
Comment on lines +88 to +95
final TypedMapView credentials = Try.of(() -> {
final ServiceBinding binding = serviceBindingSupplier.get();
return TypedMapView.ofCredentials(binding);
})
.getOrElseThrow(
e -> new DestinationAccessException(
"Could not resolve destination to Destination Service on behalf of provider.",
e));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[minor]
Formatting is pretty odd IMO.

How about:

Suggested change
final TypedMapView credentials = Try.of(() -> {
final ServiceBinding binding = serviceBindingSupplier.get();
return TypedMapView.ofCredentials(binding);
})
.getOrElseThrow(
e -> new DestinationAccessException(
"Could not resolve destination to Destination Service on behalf of provider.",
e));
final Try<ServiceBinding> maybeServiceBinding = Try.ofSupplier(serviceBindingSupplier);
if( maybeServiceBinding.isFailure() ) {
final String msg = "Could not resolve destination to Destination Service on behalf of provider.";
throw new DestinationAccessException(msg, maybeServiceBinding.getCause());
}
final TypedMapView credentials = TypedMapView.ofCredentials(maybeServiceBinding.get());

@CharlesDuboisSAP CharlesDuboisSAP Oct 24, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

TypedMapView.ofCredentials can throw many Exceptions, I thought it was safer this way.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

TypedMapView.ofCredentials can throw many Exceptions

True... didn't consider that.
We could change the code to something like that:

Suggested change
final TypedMapView credentials = Try.of(() -> {
final ServiceBinding binding = serviceBindingSupplier.get();
return TypedMapView.ofCredentials(binding);
})
.getOrElseThrow(
e -> new DestinationAccessException(
"Could not resolve destination to Destination Service on behalf of provider.",
e));
final Try<ServiceBinding> maybeServiceBinding = Try.ofSupplier(serviceBindingSupplier);
if( maybeServiceBinding.isFailure() ) {
final String msg = "Could not resolve destination to Destination Service on behalf of provider.";
throw new DestinationAccessException(msg, maybeServiceBinding.getCause());
}
final Try<TypedMapView> maybeCredentials = Try.of(() -> TypedMapView.ofCredentials(maybeServiceBinding.get()));
if (maybeCredentials.isFailure()) {
final String msg = "Could not extract credentials from destination to Destination Service.";
throw new DestinationAccessException(msg, maybeCredentials.getCause());
}
final TypedMapView credentials = maybeCredentials.get();

But I'm not sure whether it makes it more readable (maybe a tiny bit).

@Johannes-Schneider Johannes-Schneider left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Changes LGTM

@CharlesDuboisSAP
CharlesDuboisSAP merged commit c9623ea into main Oct 24, 2023
@CharlesDuboisSAP
CharlesDuboisSAP deleted the change-dwc-bindings-behaviour-in-scp-cf-modules branch October 24, 2023 09:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants