Пример #1
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"]);
        }
Пример #2
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"]);
        }
Пример #3
0
        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);
        }
Пример #4
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"]);
        }
Пример #5
0
        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;
        }
Пример #6
0
        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();
        }
Пример #7
0
        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);
        }
Пример #8
0
        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"];
        }
Пример #9
0
        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;
        }
Пример #10
0
 public void SetUp()
 {
     initCONSTS();
       m_S3V4 = new S3V4Signer() { AccessKey = ACCESSKEY, SecretKey = SECRETKEY, Region = REGION, Bucket = BUCKET };
 }