-
Notifications
You must be signed in to change notification settings - Fork 68
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
feat: replace regions with v2 api #164
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
src/main/java/software/amazon/msk/auth/iam/CompatibilityHelper.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/software/amazon/msk/auth/iam/internals/utils/RegionUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package software.amazon.msk.auth.iam.internals.utils; | ||
|
||
import software.amazon.awssdk.regions.Region; | ||
import software.amazon.awssdk.regions.providers.DefaultAwsRegionProviderChain; | ||
|
||
public class RegionUtils { | ||
|
||
/** | ||
* Try to extract the region from the host. If the region is not found, return the default region | ||
* from the DefaultAwsRegionProviderChain. | ||
* | ||
* @param host The host to extract the region from. | ||
* @return The region extracted from the host. | ||
*/ | ||
public static Region extractRegionFromHost(String host) { | ||
return Region.regions().stream() | ||
.filter(region -> host.contains(region.id())) | ||
.findFirst() | ||
.orElseGet(() -> DefaultAwsRegionProviderChain.builder().build().getRegion()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/software/amazon/msk/auth/iam/internals/utils/URIUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package software.amazon.msk.auth.iam.internals.utils; | ||
|
||
import static java.util.stream.Collectors.mapping; | ||
import static java.util.stream.Collectors.toList; | ||
|
||
import java.io.UnsupportedEncodingException; | ||
import java.net.URI; | ||
import java.net.URLDecoder; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.AbstractMap.SimpleImmutableEntry; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.LinkedHashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public class URIUtils { | ||
|
||
/** | ||
* Parse the query parameters from the URI. | ||
* | ||
* @param url The URI to parse. | ||
* @return A map of query parameters. | ||
*/ | ||
public static Map<String, List<String>> parseQueryParams(URI url) { | ||
if (url.getQuery() == null || url.getQuery().isEmpty()) { | ||
return Collections.emptyMap(); | ||
} | ||
return Arrays.stream(url.getQuery().split("&")) | ||
.map(URIUtils::splitQueryParameter) | ||
.collect(Collectors.groupingBy(SimpleImmutableEntry::getKey, LinkedHashMap::new, | ||
mapping(Map.Entry::getValue, toList()))); | ||
} | ||
|
||
private static SimpleImmutableEntry<String, String> splitQueryParameter(String it) { | ||
final int idx = it.indexOf("="); | ||
final String key = idx > 0 ? it.substring(0, idx) : it; | ||
final String value = idx > 0 && it.length() > idx + 1 ? it.substring(idx + 1) : null; | ||
return new SimpleImmutableEntry<>(decodeSilently(key), decodeSilently(value)); | ||
} | ||
|
||
private static String decodeSilently(String s) { | ||
try { | ||
return URLDecoder.decode(s, StandardCharsets.UTF_8.name()); | ||
} catch (UnsupportedEncodingException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we use this anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sidyag , by removing AWS SDK V1, some transitive dependencies have been removed, then
NameValuePair
andURLEncodedUtils
are no more available. I can have access again by addingorg.apache.httpcomponents:httpclient:4.5.+
dependency if needed. I re-implemented the method to avoid adding the whole dependency