예제 #1
0
        private static S3StoreInfo OpenS3Store(string path)
        {
            string[] parts = path.Split('/');
            if (parts.Length < 3)
            {
                throw new ArgumentException("The specified S3 resource path (" + path + ") is invalid!");
            }
            EncryptionType encryptionType;

            switch (parts[0].ToLowerInvariant())
            {
            case "s3:":
                encryptionType = EncryptionType.None;
                break;

            case "s3e:":
                encryptionType = EncryptionType.SSE_S3;
                break;

            case "s3k:":
                encryptionType = EncryptionType.SSE_KMS;
                break;

            case "s3x:":
                encryptionType = EncryptionType.SSE_C;
                break;

            default:
                throw new ArgumentException("The specified resource path (" + path + ") is not a valid S3 resource path!");
            }
            string bucket = parts[2];
            string prefix = String.Join("/", parts, 3, parts.Length - 3) + "/";

            if (!String.IsNullOrEmpty(parts[1]) || String.IsNullOrEmpty(bucket) || String.IsNullOrEmpty(prefix) || prefix.StartsWith("/"))
            {
                throw new ArgumentException("The specified resource path (" + path + ") is not a valid S3 resource path!");
            }

            int?sliceId = SystemExtensions.TryParseInt(parts[parts.Length - 1]);

            return(new S3StoreInfo(new AmazonS3Client(), sliceId, bucket, prefix, encryptionType));
        }