Exemplo n.º 1
0
Arquivo: S3V4.cs Projeto: zhabis/nfx
        public static void SetACL(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, string acl,
                                  int timeoutMs)
        {
            var queryParams = new Dictionary <string, string>()
            {
                { "acl", string.Empty }
            };

            MemoryStream aclStream = new MemoryStream(Encoding.UTF8.GetBytes(acl ?? string.Empty));

            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath, queryParams);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "PUT",
                ItemLocalPath = itemLocalPath,
                QueryParams   = queryParams,
                ContentStream = aclStream
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "PUT", aclStream, headers, timeoutMs);

            request.GetHeaders();
        }
Exemplo n.º 2
0
        public void ListBucketFiles()
        {
            Uri uri = S3V4URLHelpers.CreateURI(REGION, BUCKET);

            DateTime dateTime = new DateTime(2014, 02, 17, 10, 10, 10, DateTimeKind.Utc);

            IDictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "content-type", "text/plain" },
                { "Host", uri.Host },
                { S3V4Signer.X_AMZ_CONTENT_SHA256, S3V4Signer.EMPTY_BODY_SHA256 },
                { S3V4Signer.X_AMZ_DATE, dateTime.S3DateTimeString() }
            };

            string r = S3V4Signer.GetCanonicalRequest("GET", uri, headers);

            string expected =
                "GET\n" +
                "/\n" +
                "\n" +
                "content-type:text/plain\n" +
                "host:dxw.s3-us-west-2.amazonaws.com\n" +
                "x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n" +
                "x-amz-date:20140217T101010Z\n" +
                "\n" +
                "content-type;host;x-amz-content-sha256;x-amz-date\n" +
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";

            Assert.AreEqual(expected, r);
        }
Exemplo n.º 3
0
        public void AutorizationGetQueryParameters()
        {
            DateTime dateTime = new DateTime(2014, 02, 17, 10, 10, 10, DateTimeKind.Utc);

            IDictionary <string, string> queryParameters = new Dictionary <string, string>()
            {
                { "marker", "1" },
                { "delimiter", "/" }
            };

            S3V4Signer s3v4 = new S3V4Signer()
            {
                AccessKey       = ACCESSKEY,
                SecretKey       = SECRETKEY,
                Bucket          = BUCKET,
                Region          = REGION,
                Method          = "GET",
                RequestDateTime = dateTime,
                QueryParams     = queryParameters
            };


            string expected = "AWS4-HMAC-SHA256 Credential={0}/20140217/us-west-2/s3/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, ".Args(ACCESSKEY) +
                              "Signature=9cda8f26243f1874d921938037a3fc6839f3067092bc305dc4b41dc810a98edb";

            Assert.AreEqual(5, s3v4.Headers.Count);
            Assert.AreEqual(expected, s3v4.Headers["Authorization"]);
        }
Exemplo n.º 4
0
        public void DeleteFile()
        {
            Uri uri = S3V4URLHelpers.CreateURI(REGION, BUCKET, ITEM_RELATIVE_PATH);

            DateTime dateTime = new DateTime(2014, 02, 17, 10, 10, 10, DateTimeKind.Utc);

            string contentHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";

            IDictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "content-type", "text/plain" },
                { "Host", uri.Host },
                { S3V4Signer.X_AMZ_CONTENT_SHA256, contentHash },
                { S3V4Signer.X_AMZ_DATE, dateTime.S3DateTimeString() }
            };

            string r = S3V4Signer.GetCanonicalRequest("DELETE", uri, headers, hashedPayload: contentHash);

            string expected =
                "DELETE\n" +
                "/Folder01/Test01.txt\n" +
                "\n" +
                "content-type:text/plain\n" +
                "host:dxw.s3-us-west-2.amazonaws.com\n" +
                "x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n" +
                "x-amz-date:20140217T101010Z\n" +
                "\n" +
                "content-type;host;x-amz-content-sha256;x-amz-date\n" +
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";

            Assert.AreEqual(expected, r);
        }
Exemplo n.º 5
0
        public void PutFile()
        {
            Uri uri = S3V4URLHelpers.CreateURI(REGION, BUCKET, ITEM_RELATIVE_PATH);

            DateTime dateTime = new DateTime(2014, 02, 17, 10, 10, 10, DateTimeKind.Utc);

            string contentHash = "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f";

            IDictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "content-type", "text/plain" },
                { "content-length", 13.ToString() },
                { "Host", uri.Host },
                { S3V4Signer.X_AMZ_CONTENT_SHA256, contentHash },
                { S3V4Signer.X_AMZ_DATE, dateTime.S3DateTimeString() }
            };

            string r = S3V4Signer.GetCanonicalRequest("PUT", uri, headers, hashedPayload: contentHash);

            string expected =
                "PUT\n" +
                "/Folder01/Test01.txt\n" +
                "\n" +
                "content-length:13\n" +
                "content-type:text/plain\n" +
                "host:dxw.s3-us-west-2.amazonaws.com\n" +
                "x-amz-content-sha256:dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f\n" +
                "x-amz-date:20140217T101010Z\n" +
                "\n" +
                "content-length;content-type;host;x-amz-content-sha256;x-amz-date\n" +
                "dffd6021bb2bd5b0af676290809ec3a53191dd81c7f70a4b28688a362182986f";

            Assert.AreEqual(expected, r);
        }
Exemplo n.º 6
0
 public void SetUp()
 {
     initCONSTS();
     m_S3V4 = new S3V4Signer()
     {
         AccessKey = ACCESSKEY, SecretKey = SECRETKEY, Region = REGION, Bucket = BUCKET
     };
 }
Exemplo n.º 7
0
 void IRunnableHook.Prologue(Runner runner, FID id)
 {
     initCONSTS();
     m_S3V4 = new S3V4Signer()
     {
         AccessKey = ACCESSKEY, SecretKey = SECRETKEY, Region = REGION, Bucket = BUCKET
     };
 }
Exemplo n.º 8
0
Arquivo: S3V4.cs Projeto: zhabis/nfx
        public static void RemoveItem(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "DELETE",
                ItemLocalPath = itemLocalPath
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "DELETE", EMPTY_CONTENT_STREAM, headers, timeoutMs);

            request.GetHeaders(HttpStatusCode.NoContent);
        }
Exemplo n.º 9
0
Arquivo: S3V4.cs Projeto: zhabis/nfx
        public static IDictionary <string, string> GetItemMetadata(string itemLocalPath, string accessKey, string secretKey,
                                                                   string bucket, string region, int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey, SecretKey = secretKey,
                Bucket        = bucket, Region = region,
                Method        = "HEAD",
                ItemLocalPath = itemLocalPath
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "HEAD", new MemoryStream(), headers, timeoutMs);

            var resultHeaders = S3V4HttpHelpers.GetHeaders(request);

            return(resultHeaders);
        }
Exemplo n.º 10
0
Arquivo: S3V4.cs Projeto: zhabis/nfx
        public static void GetFile(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, Stream stream,
                                   int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "GET",
                ItemLocalPath = itemLocalPath
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "GET", new MemoryStream(), headers, timeoutMs);

            request.GetResponseBytes(stream);
        }
Exemplo n.º 11
0
        public void AutorizationDeleteFile()
        {
            DateTime dateTime = new DateTime(2014, 02, 17, 11, 11, 11, DateTimeKind.Utc);

            S3V4Signer s3v4 = new S3V4Signer()
            {
                AccessKey       = ACCESSKEY,
                SecretKey       = SECRETKEY,
                Bucket          = BUCKET,
                Region          = REGION,
                ItemLocalPath   = ITEM_RELATIVE_PATH,
                Method          = "DELETE",
                RequestDateTime = dateTime
            };

            string expected = "AWS4-HMAC-SHA256 Credential={0}/20140217/us-west-2/s3/aws4_request, SignedHeaders=content-type;host;x-amz-content-sha256;x-amz-date, ".Args(ACCESSKEY) +
                              "Signature=b9d74d6372c55ee54b89c9f44c866edd2577aca878d05a8eccf0cec4a921e07a";

            Assert.AreEqual(5, s3v4.Headers.Count);
            Assert.AreEqual(expected, s3v4.Headers["Authorization"]);
        }
Exemplo n.º 12
0
Arquivo: S3V4.cs Projeto: zhabis/nfx
        public static string ListBucket(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, int timeoutMs,
                                        string prefix = null, string marker = null, int?maxKeys = null)
        {
            var queryParams = new Dictionary <string, string>();

            if (prefix != null)
            {
                queryParams.Add("prefix", prefix);
            }

            if (marker != null)
            {
                queryParams.Add("marker", marker);
            }

            if (maxKeys.HasValue)
            {
                queryParams.Add("max-keys", maxKeys.Value.ToString());
            }

            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, "", queryParams);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "GET"
                , QueryParams = queryParams
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "GET", EMPTY_CONTENT_STREAM, headers, timeoutMs);

            string responseStr = request.GetResponseStr();

            return(responseStr);
        }
Exemplo n.º 13
0
        public void GetQueryParameters()
        {
            Uri uri = S3V4URLHelpers.CreateURI(REGION, BUCKET);

            DateTime dateTime = new DateTime(2014, 02, 17, 10, 10, 10, DateTimeKind.Utc);

            string contentHash = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";

            IDictionary <string, string> headers = new Dictionary <string, string>()
            {
                { "content-type", "text/plain" },
                { "Host", uri.Host },
                { S3V4Signer.X_AMZ_CONTENT_SHA256, contentHash },
                { S3V4Signer.X_AMZ_DATE, dateTime.S3DateTimeString() }
            };

            IDictionary <string, string> queryParameters = new Dictionary <string, string>()
            {
                { "marker", "1" },
                { "delimiter", "/" }
            };

            string r = S3V4Signer.GetCanonicalRequest("GET", uri, headers, queryParameters, contentHash);

            string expected =
                "GET\n" +
                "/\n" +
                "delimiter=%2F&marker=1\n" +
                "content-type:text/plain\n" +
                "host:dxw.s3-us-west-2.amazonaws.com\n" +
                "x-amz-content-sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855\n" +
                "x-amz-date:20140217T101010Z\n" +
                "\n" +
                "content-type;host;x-amz-content-sha256;x-amz-date\n" +
                "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";

            Aver.AreEqual(expected, r);
        }
Exemplo n.º 14
0
Arquivo: S3V4.cs Projeto: zhabis/nfx
        public static string PutItem(string itemLocalPath, string accessKey, string secretKey, string bucket, string region, Stream contentStream,
                                     int timeoutMs)
        {
            Uri uri = S3V4URLHelpers.CreateURI(region, bucket, itemLocalPath);

            S3V4Signer signer = new S3V4Signer()
            {
                AccessKey     = accessKey,
                SecretKey     = secretKey,
                Bucket        = bucket,
                Region        = region,
                Method        = "PUT",
                ItemLocalPath = itemLocalPath,
                ContentStream = contentStream
            };

            var headers = signer.Headers;

            var request = S3V4HttpHelpers.ConstructWebRequest(uri, "PUT", contentStream, headers, timeoutMs);

            var resultHeaders = request.GetHeaders();

            return(resultHeaders["ETag"]);
        }
Exemplo n.º 15
0
        public void AutorizationPutFile()
        {
            DateTime dateTime = new DateTime(2015, 02, 17, 11, 11, 11, DateTimeKind.Utc);

            MemoryStream contentStream = new MemoryStream(Encoding.UTF8.GetBytes(CONTENT));

            S3V4Signer s3v4 = new S3V4Signer()
            {
                AccessKey       = ACCESSKEY,
                SecretKey       = SECRETKEY,
                Bucket          = BUCKET,
                Region          = REGION,
                ItemLocalPath   = ITEM_RELATIVE_PATH,
                Method          = "PUT",
                RequestDateTime = dateTime,
                ContentStream   = contentStream
            };

            string expected = "AWS4-HMAC-SHA256 Credential={0}/20150217/us-west-2/s3/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-content-sha256;x-amz-date, ".Args(ACCESSKEY) +
                              "Signature=b0226cf0a900e16489d7f1feaace3f1c6d9e9f516fac2ebd61177b1f3d9b98ea";

            Assert.AreEqual(6, s3v4.Headers.Count);
            Assert.AreEqual(expected, s3v4.Headers["Authorization"]);
        }