Skip to content

Commit

Permalink
Handled comments
Browse files Browse the repository at this point in the history
  • Loading branch information
joviegas committed Dec 27, 2024
1 parent 5292681 commit a7cc13e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@


import java.util.Arrays;
import java.util.Collections;
import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
Expand All @@ -31,7 +32,6 @@
import software.amazon.awssdk.utils.StringUtils;
import software.amazon.awssdk.utils.Validate;


@SdkProtectedApi
public final class Sigv4aSigningRegionSetProvider {
private final Supplier<ProfileFile> profileFile;
Expand Down Expand Up @@ -59,28 +59,26 @@ public Set<String> resolveRegionSet() {
private Set<String> regionSet() {
Optional<String> setting = SdkSystemSetting.AWS_SIGV4A_SIGNING_REGION_SET.getStringValue();
if (setting.isPresent()) {
return parseRegionSet(setting.get()).orElse(null);
return parseRegionSet(setting.get());
}

ProfileFile file = this.profileFile.get();
Optional<Profile> profile = file.profile(profileName());
return profile
.flatMap(p -> p.property(ProfileProperty.SIGV4A_SIGNING_REGION_SET))
.flatMap(this::parseRegionSet)
.map(this::parseRegionSet)
.orElse(null);
}

private Optional<Set<String>> parseRegionSet(String value) {
private Set<String> parseRegionSet(String value) {
if (StringUtils.isBlank(value)) {
return Optional.empty();
return null;
}

Set<String> regions = Arrays.stream(value.split(","))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.toSet());

return regions.isEmpty() ? Optional.empty() : Optional.of(regions);
return regions.isEmpty() ? null : Collections.unmodifiableSet(regions);
}

private String profileName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
package software.amazon.awssdk.services;
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.services.auth;

import static org.assertj.core.api.Assertions.assertThat;

Expand Down

0 comments on commit a7cc13e

Please sign in to comment.