All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.s3.internal.settingproviders.UseArnRegionProviderChain Maven / Gradle / Ivy

Go to download

The AWS Java SDK for Amazon S3 module holds the client classes that are used for communicating with Amazon Simple Storage Service

There is a newer version: 2.28.3
Show newest version
/*
 * 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.s3.internal.settingproviders;

import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import software.amazon.awssdk.annotations.SdkInternalApi;
import software.amazon.awssdk.profiles.ProfileFile;
import software.amazon.awssdk.profiles.ProfileFileSystemSetting;
import software.amazon.awssdk.utils.Logger;

/**
 * {@link UseArnRegionProvider} implementation that chains together multiple useArnRegion providers.
 */
@SdkInternalApi
public final class UseArnRegionProviderChain implements UseArnRegionProvider {
    private static final Logger log = Logger.loggerFor(UseArnRegionProvider.class);

    private final List providers;

    private UseArnRegionProviderChain(List providers) {
        this.providers = providers;
    }

    /**
     * Creates a default {@link UseArnRegionProviderChain}.
     *
     * 

* AWS use arn region provider that looks for the useArnRegion in this order: * *

    *
  1. Check if 'aws.s3UseArnRegion' system property is set.
  2. *
  3. Check if 'AWS_USE_ARN_REGION' environment variable is set.
  4. *
  5. Check if 's3_use_arn_region' profile file configuration is set.
  6. *
*/ public static UseArnRegionProviderChain create() { return create(ProfileFile::defaultProfileFile, ProfileFileSystemSetting.AWS_PROFILE.getStringValueOrThrow()); } public static UseArnRegionProviderChain create(ProfileFile profileFile, String profileName) { return new UseArnRegionProviderChain(Arrays.asList(SystemsSettingsUseArnRegionProvider.create(), ProfileUseArnRegionProvider.create(profileFile, profileName))); } public static UseArnRegionProviderChain create(Supplier profileFile, String profileName) { return new UseArnRegionProviderChain(Arrays.asList(SystemsSettingsUseArnRegionProvider.create(), ProfileUseArnRegionProvider.create(profileFile, profileName))); } @Override public Optional resolveUseArnRegion() { for (UseArnRegionProvider provider : providers) { try { Optional useArnRegion = provider.resolveUseArnRegion(); if (useArnRegion.isPresent()) { return useArnRegion; } } catch (Exception ex) { log.warn(() -> "Failed to retrieve useArnRegion from " + provider, ex); } } return Optional.empty(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy