예제 #1
0
        public static AWSCredentials GetAwsCredentials()
        {
            var file = new FileInfo(AwsCredentialsFilePath);
            if (!file.Exists)
            {
                // Create subdirectories
                var directory = file.Directory;
                if (directory != null)
                {
                    directory.Create();
                }

                // Create new file
                CreateAwsCredentialsFile(AwsCredentialsFilePath);
            }

            var credentialsConfig = new AwsCredentialsConfig();
            using (var readStream = file.OpenRead())
            {
                var xmlSerializer = new XmlSerializer(typeof(AwsCredentialsConfig));
                try
                {
                    credentialsConfig = (AwsCredentialsConfig)xmlSerializer.Deserialize(readStream);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch
                {
                }
            }

            ValidateAwsCredentials(credentialsConfig.AwsAccessKey, credentialsConfig.AwsSecretKey);

            return new BasicAWSCredentials(credentialsConfig.AwsAccessKey, credentialsConfig.AwsSecretKey);
        }
예제 #2
0
		private static void CreateAwsCredentialsFile(string filePath)
		{
			var fileInfo = new FileInfo(filePath);
			var defaultConfig = new AwsCredentialsConfig { AwsAccessKey = string.Empty, AwsSecretKey = string.Empty };
			using (var textWriter = fileInfo.CreateText())
			{
				var xmlSerializer = new XmlSerializer(typeof(AwsCredentialsConfig));
				xmlSerializer.Serialize(textWriter, defaultConfig);
			}
		}