コード例 #1
0
        public AmazonStorageProvider(AmazonProviderOptions options)
        {
            _serviceUrl = string.IsNullOrEmpty(options.ServiceUrl) ? DefaultServiceUrl : options.ServiceUrl;
            _bucket     = options.Bucket;
            _serverSideEncryptionMethod = options.ServerSideEncryptionMethod;
            var s3Config = new AmazonS3Config
            {
                ServiceURL = _serviceUrl,
                Timeout    = options.Timeout ?? ClientConfig.MaxTimeout,
            };

            _s3Client = new AmazonS3Client(ReadAwsCredentials(options), s3Config);
        }
コード例 #2
0
        private AWSCredentials ReadAwsCredentials(AmazonProviderOptions options)
        {
            if (!string.IsNullOrWhiteSpace(options.ProfileName))
            {
                var credentialProfileStoreChain = new CredentialProfileStoreChain();
                if (credentialProfileStoreChain.TryGetAWSCredentials(options.ProfileName, out var defaultCredentials))
                {
                    return(defaultCredentials);
                }

                throw new AmazonClientException("Unable to find a default profile in CredentialProfileStoreChain.");
            }

            if (!string.IsNullOrEmpty(options.PublicKey) && !string.IsNullOrWhiteSpace(options.SecretKey))
            {
                return(new BasicAWSCredentials(options.PublicKey, options.SecretKey));
            }
            return(new EnvironmentVariablesAWSCredentials());
        }