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

com.amazonaws.auth.profile.internal.BasicProfile Maven / Gradle / Ivy

Go to download

The AWS SDK for Java - Core module holds the classes that are used by the individual service clients to interact with Amazon Web Services. Users need to depend on aws-java-sdk artifact for accessing individual client classes.

There is a newer version: 1.12.778
Show newest version
/*
 * Copyright 2011-2024 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 com.amazonaws.auth.profile.internal;

import com.amazonaws.annotation.Immutable;
import com.amazonaws.annotation.SdkInternalApi;

import java.util.Collections;
import java.util.Map;

/**
 * Represents a CLI style config profile with a name and simple properties. Provides convenient
 * access to the properties the Java SDK deals with and also raw access to all properties.
 */
@Immutable
@SdkInternalApi
public class BasicProfile {


    private final String profileName;
    private final Map properties;

    public BasicProfile(String profileName,
                        Map properties) {
        this.profileName = profileName;
        this.properties = properties;
    }

    /**
     * @return The name of this profile.
     */
    public String getProfileName() {
        return profileName;
    }

    /**
     * Returns a map of profile properties included in this Profile instance. The returned
     * properties corresponds to how this profile is described in the credential profiles file,
     * i.e., profiles with basic credentials consist of two properties {"aws_access_key_id",
     * "aws_secret_access_key"} and profiles with session credentials have three properties, with an
     * additional "aws_session_token" property.
     */
    public Map getProperties() {
        return Collections.unmodifiableMap(properties);
    }

    /**
     * Returns the value of a specific property that is included in this Profile instance.
     *
     * @see BasicProfile#getProperties()
     */
    public String getPropertyValue(String propertyName) {
        return getProperties().get(propertyName);
    }

    public String getAwsAccessIdKey() {
        return getPropertyValue(ProfileKeyConstants.AWS_ACCESS_KEY_ID);
    }

    public String getAwsSecretAccessKey() {
        return getPropertyValue(ProfileKeyConstants.AWS_SECRET_ACCESS_KEY);
    }

    public String getAwsSessionToken() {
        return getPropertyValue(ProfileKeyConstants.AWS_SESSION_TOKEN);
    }

    public String getAwsAccountId() {
        return getPropertyValue(ProfileKeyConstants.AWS_ACCOUNT_ID);
    }

    public String getRoleArn() {
        return getPropertyValue(ProfileKeyConstants.ROLE_ARN);
    }

    public String getRoleSourceProfile() {
        return getPropertyValue(ProfileKeyConstants.SOURCE_PROFILE);
    }

    public String getRoleSessionName() {
        return getPropertyValue(ProfileKeyConstants.ROLE_SESSION_NAME);
    }

    public String getRoleExternalId() {
        return getPropertyValue(ProfileKeyConstants.EXTERNAL_ID);
    }

    public String getRegion() {
        return getPropertyValue(ProfileKeyConstants.REGION);
    }

    public String getEndpointDiscovery() {
        return getPropertyValue(ProfileKeyConstants.ENDPOINT_DISCOVERY);
    }

    public String getCredentialProcess() {
        return getPropertyValue(ProfileKeyConstants.CREDENTIAL_PROCESS);
    }

    public String getWebIdentityTokenFilePath() {
        return getPropertyValue(ProfileKeyConstants.WEB_IDENTITY_TOKEN);
    }

    public boolean isRoleBasedProfile() {
        return getRoleArn() != null;
    }

    public boolean isProcessBasedProfile() {
        return getCredentialProcess() != null;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy