Search in sources :

Example 1 with ServiceMetadata

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;
}
Also used : Lazy(software.amazon.awssdk.utils.Lazy) EndpointTag(software.amazon.awssdk.regions.EndpointTag) ArrayList(java.util.ArrayList) Region(software.amazon.awssdk.regions.Region) URI(java.net.URI) ServiceMetadata(software.amazon.awssdk.regions.ServiceMetadata) ProfileFile(software.amazon.awssdk.profiles.ProfileFile)

Aggregations

URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 ProfileFile (software.amazon.awssdk.profiles.ProfileFile)1 EndpointTag (software.amazon.awssdk.regions.EndpointTag)1 Region (software.amazon.awssdk.regions.Region)1 ServiceMetadata (software.amazon.awssdk.regions.ServiceMetadata)1 Lazy (software.amazon.awssdk.utils.Lazy)1