use of software.amazon.awssdk.regions.ServiceMetadata in project aws-sdk-java-v2 by aws.
the class DefaultServiceEndpointBuilder method getServiceEndpoint.
public URI getServiceEndpoint() {
if (profileFile == null) {
profileFile = new Lazy<>(ProfileFile::defaultProfileFile)::getValue;
}
if (profileName == null) {
profileName = ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow();
}
if (dualstackEnabled == null) {
dualstackEnabled = DualstackEnabledProvider.builder().profileFile(profileFile).profileName(profileName).build().isDualstackEnabled().orElse(false);
}
if (fipsEnabled == null) {
fipsEnabled = FipsEnabledProvider.builder().profileFile(profileFile).profileName(profileName).build().isFipsEnabled().orElse(false);
}
List<EndpointTag> endpointTags = new ArrayList<>();
if (dualstackEnabled) {
endpointTags.add(EndpointTag.DUALSTACK);
}
if (fipsEnabled) {
endpointTags.add(EndpointTag.FIPS);
}
ServiceMetadata serviceMetadata = ServiceMetadata.of(serviceName).reconfigure(c -> c.profileFile(profileFile).profileName(profileName).advancedOptions(advancedOptions));
URI endpoint = addProtocolToServiceEndpoint(serviceMetadata.endpointFor(ServiceEndpointKey.builder().region(region).tags(endpointTags).build()));
if (endpoint.getHost() == null) {
String error = "Configured region (" + region + ") and tags (" + endpointTags + ") resulted in an invalid URI: " + endpoint + ". This is usually caused by an invalid region configuration.";
List<Region> exampleRegions = serviceMetadata.regions();
if (!exampleRegions.isEmpty()) {
error += " Valid regions: " + exampleRegions;
}
throw SdkClientException.create(error);
}
return endpoint;
}
Aggregations