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); }
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(); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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"]); }