Skip to content

Conversation

@sugmanue
Copy link
Contributor

Motivation and Context

Changes to make sure that all overrides using the client builder can also be applied using plugins.

Modifications

This PR changes the way we deal with the ClientOverrideConfiguration. Instead of rebuilding it from its side effect (i.e., the values in SdkClientConfiguration) we use the override configuration object that is present during client building or at request execution time. This will reflect the exact values given for this object without having any "magic" derived values to appear. For instance, the execution interceptors in the override configuration are added to the same client option EXECUTION_INTERCEPTORS but this is also filled up with default interceptors here but those are not part of the original override configuration but before this change would be present in the SdkServiceClientConfiguration.Builder object since those were copied blindly.

We also made changes to the way we set the values to avoid overwriting previously added or computed ones, this means the if a list is given (e.g., with execution interceptors) we will follow a conservative logic to avoid duplicating previously added or removing computed values. For instance:

    static <T> void setClientListOption(SdkClientConfiguration.Builder builder, ClientOption<List<T>> option, List<T> newValue) {
        if (newValue == null || newValue.isEmpty()) {
            return;
        }
        List<T> oldValue = builder.option(option);
        if (oldValue == null || oldValue.isEmpty()) {
            builder.option(option, newValue);
            return;
        }
        // Make sure that we don't override derived values or duplicate existing ones.
        List<T> result = new ArrayList<>(oldValue);
        Set<T> dedup = new HashSet<>();
        dedup.addAll(oldValue);
        for (T value : newValue) {
            if (!dedup.contains(value)) {
                result.add(value);
            }
        }
        builder.option(option, result);
    }

Testing

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn install succeeds
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in .changes/next-release with your changes.
  • My change is to implement 1.11 parity feature and I have updated LaunchChangelog

License

  • I confirm that this pull request can be released under the Apache 2 license

@sugmanue sugmanue requested a review from a team as a code owner October 10, 2023 21:29
import software.amazon.awssdk.profiles.ProfileFileSupplier;

@SdkInternalApi
public final class SdkClientConfigurationUtil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed from SdkClientConfigurationUtil.java.resource to SdkClientConfigurationUtil.resource.java to make it easier for editors to identify it as a Java file. Also removed the method copyConfigurationToOverrides which is not longer used.

@sugmanue sugmanue force-pushed the sugmanue/sra-plugins-override-configuration-tests branch from feb6701 to 823b307 Compare October 10, 2023 21:37

// Assert that we can retrieve the same value
assertThat(testCase.getter.apply(anotherBuilder)).isEqualTo(testCase.value);
if (testCase.hasDirectMapping) {
Copy link
Contributor Author

@sugmanue sugmanue Oct 10, 2023

Choose a reason for hiding this comment

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

We no longer "mirror" the client override configuration from the client configuration, therefore this test no longer works for those properties.

@sugmanue sugmanue force-pushed the sugmanue/sra-plugins-override-configuration-tests branch from 823b307 to f4e0ae5 Compare October 10, 2023 21:45

<!-- See SpotBugs bug: https://github.com/spotbugs/spotbugs/issues/600, https://github.com/spotbugs/spotbugs/issues/756 -->
<Match>
<Class name="software.amazon.awssdk.core.SdkServiceClientConfiguration$Builder"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SpotBugs gets confused about the nullability of the overrideConfiguration, probably because is looking at the default method that throws an UnsupportedOperationException. Adding this since I'm certain that this value can be null.

@sonarqubecloud
Copy link

SonarCloud Quality Gate failed.    Quality Gate failed

Bug C 9 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot E 2 Security Hotspots
Code Smell A 491 Code Smells

85.2% 85.2% Coverage
4.1% 4.1% Duplication

idea Catch issues before they fail your Quality Gate with our IDE extension sonarlint SonarLint

@sugmanue sugmanue merged commit dbc7909 into feature/master/sra-identity-auth Oct 11, 2023
@sugmanue sugmanue deleted the sugmanue/sra-plugins-override-configuration-tests branch October 11, 2023 20:53
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.

2 participants