Esempio n. 1
0
 /// <summary>
 /// Creates an Amazon S3 storage provider using credentials from AWS CLI configuration file (~/.aws/credentials)
 /// </summary>
 /// <param name="factory">Factory reference</param>
 /// <param name="awsCliProfileName"></param>
 /// <param name="bucketName">Bucket name</param>
 /// <param name="region"></param>
 /// <returns>A reference to the created storage</returns>
 public static IBlobStorage AwsS3(this IBlobStorageFactory factory,
                                  string awsCliProfileName,
                                  string bucketName,
                                  string region)
 {
     return(AwsS3BlobStorage.FromAwsCliProfile(awsCliProfileName, bucketName, region));
 }
Esempio n. 2
0
        public IBlobStorage CreateBlobStorage(StorageConnectionString connectionString)
        {
            if (connectionString.Prefix == KnownPrefix.AwsS3)
            {
                string cliProfileName = connectionString.Get(KnownParameter.LocalProfileName);
                connectionString.GetRequired(KnownParameter.BucketName, true, out string bucket);
                connectionString.GetRequired(KnownParameter.Region, true, out string region);

                if (string.IsNullOrEmpty(cliProfileName))
                {
                    string keyId = connectionString.Get(KnownParameter.KeyId);
                    string key   = connectionString.Get(KnownParameter.KeyOrPassword);

                    if (string.IsNullOrEmpty(keyId) != string.IsNullOrEmpty(key))
                    {
                        throw new ArgumentException($"connection string requires both 'key' and 'keyId' parameters, or neither.");
                    }


                    if (string.IsNullOrEmpty(keyId))
                    {
                        return(new AwsS3BlobStorage(bucket, region));
                    }

                    string sessionToken = connectionString.Get(KnownParameter.SessionToken);
                    return(new AwsS3BlobStorage(keyId, key, sessionToken, bucket, region, null));
                }
#if !NET16
                else
                {
                    return(AwsS3BlobStorage.FromAwsCliProfile(cliProfileName, bucket, region));
                }
#endif
            }


            return(null);
        }