/// <summary>
        /// Creates a new profile in the AWS SDK Store for storing credentials in encrypted form.
        /// </summary>
        /// <remarks>
        /// The encrypted credentials in the SDK Store are located in the'%LOCALAPPDATA%\AWSToolkit'
        /// folder in the RegisteredAccounts.json file.
        /// </remarks>
        /// <param name="profileName">Profile name to associate with credentials.</param>
        /// <param name="accessKey">The access key to store with <paramref name="profileName"/>.</param>
        /// <param name="secretKey">The secret key to store with <paramref name="profileName"/>.</param>
        /// <param name="region">The AWS region to associate with <paramref name="profileName"/>.</param>
        /// <returns>Successful or not result.</returns>
        private static bool RegisterAccount(string profileName, string accessKey, string secretKey, string region)
        {
            var chain = new CredentialProfileStoreChain();

            if (chain.ListProfiles().Any(p => p.Name.Equals(profileName,
                                                            StringComparison.InvariantCultureIgnoreCase)))
            {
                MessageBox.Show("The profile name already exists in one or more locations.",
                                Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }

            var options = new CredentialProfileOptions
            {
                AccessKey = accessKey,
                SecretKey = secretKey
            };

            var profile    = new CredentialProfile(profileName, options);
            var netSdkFile = new NetSDKCredentialsFile();

            profile.Region = RegionEndpoint.GetBySystemName(region);
            netSdkFile.RegisterProfile(profile);

            MessageBox.Show("AWS account was stored successfully.",
                            Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            return(true);
        }
Beispiel #2
0
        public AwsCredentials GetCredentials()
        {
            var chain    = new CredentialProfileStoreChain();
            var profiles = chain.ListProfiles();
            CredentialProfile profile = profiles.FirstOrDefault();

            if (profile == null)
            {
                return(null);
            }

            var credentials = profile.GetAWSCredentials(chain).GetCredentials();
            var credential  = new AwsCredentials {
                AccessKey = credentials.AccessKey, SecretKey = credentials.SecretKey, Token = credentials.Token
            };

            return(new AwsCredentials
            {
                AccessKey = credential.AccessKey,
                SecretKey = credential.SecretKey,
                Token = credential.Token
            });
        }
        internal List <CredentialProfile> ListProfiles()
        {
            CredentialProfileStoreChain configFile = new CredentialProfileStoreChain();

            return(configFile.ListProfiles());
        }