Beispiel #1
0
        /// <summary>
        /// Tries to load the specified profile data corresponding to profile type T from a named
        /// profile in the SDK account store.
        /// </summary>
        /// <param name="profileName">The name of the profile holding the settings.</param>
        /// <param name="profile">The loaded profile data.</param>
        /// <returns>Returns true if the profile exists otherwise false is returned.</returns>
        /// <remarks>
        /// Currently supported profile types: AWSCredentialsProfile and SAMLRoleProfile.
        /// </remarks>
        public static bool TryGetProfile <T>(string profileName, out T profile) where T : ProfileSettingsBase
        {
            profile = null;

            try
            {
                if (typeof(T) == typeof(AWSCredentialsProfile))
                {
                    profile = AWSCredentialsProfile.LoadFrom(profileName) as T;
                }
                else if (typeof(T) == typeof(SAMLRoleProfile))
                {
                    profile = SAMLRoleProfile.LoadFrom(profileName) as T;
                }
                else
                {
                    throw new ArgumentException("Unrecognized profile type parameter", (typeof(T).FullName));
                }
            }
            catch (Exception e)
            {
                Logger.GetLogger(typeof(ProfileManager)).Error(e, "Unable to load profile {0}, unknown profile, missing/invalid data or unrecognized profile type.", profileName);
            }

            return(profile != null);
        }
Beispiel #2
0
        /// <summary>
        /// Loads and returns all available credential profiles registered in the store.
        /// </summary>
        /// <returns>Collection of profiles.</returns>
        public static IEnumerable <ProfileSettingsBase> ListProfiles()
        {
            var profiles     = new List <ProfileSettingsBase>();
            var profileNames = ListProfileNames();

            foreach (var profileName in profileNames)
            {
                try
                {
                    if (SAMLRoleProfile.CanCreateFrom(profileName))
                    {
                        profiles.Add(SAMLRoleProfile.LoadFrom(profileName));
                    }
                    else if (AWSCredentialsProfile.CanCreateFrom(profileName))
                    {
                        profiles.Add(AWSCredentialsProfile.LoadFrom(profileName));
                    }
                }
                catch (Exception e)
                {
                    Logger.GetLogger(typeof(ProfileManager)).Error(e, "Error loading AWS credential or SAML role profile '{0}'", profileName);
                }
            }

            return(profiles);
        }
Beispiel #3
0
 /// <summary>
 /// Registers an AWS credentials profile that can later be referenced by the profileName.
 /// This profile will only be visible for the current user.
 /// </summary>
 /// <param name="profileName">Name given to the AWS credentials.</param>
 /// <param name="accessKeyId">The AWS access key id</param>
 /// <param name="secretKey">The AWS secret key</param>
 public static void RegisterProfile(string profileName, string accessKeyId, string secretKey)
 {
     AWSCredentialsProfile.Persist(profileName, accessKeyId, secretKey);
 }