Beispiel #1
0
        public async Task <EntityShortRepresentation> AddAwsCredentialsAsync(AwsCredentialsConfig body, CancellationToken cancellationToken = default)
        {
            var response = await GetAwsCredentialsUrl()
                           .PostJsonAsync(body, cancellationToken)
                           .ReceiveJsonWithErrorChecking <EntityShortRepresentation>()
                           .ConfigureAwait(false);

            return(response);
        }
        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);
            }
        }
        public static AWSCredentials GetAwsCredentials()
        {
            // returning null means we're providing credentials in some other way than a credentials file
            if (string.IsNullOrEmpty(AwsCredentialsFilePath))
            {
                return(null);
            }

            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));
        }
Beispiel #4
0
        public async Task <EntityShortRepresentation> UpdateAwsCredentialsAsync(string id, AwsCredentialsConfig body, CancellationToken cancellationToken = default)
        {
            var response = await GetAwsCredentialsUrl()
                           .AppendPathSegment(id)
                           .PutJsonAsync(body, cancellationToken)
                           .ReceiveJsonWithErrorChecking <EntityShortRepresentation>()
                           .ConfigureAwait(false);

            return(response);
        }