public async Task CRUDTest() { string bucket1 = "testbucket-" + Guid.NewGuid(); string bucket2 = "testbucket-" + Guid.NewGuid(); await BucketClient.PutBucketAsync(bucket1, AwsRegion.EUWest1).ConfigureAwait(false); await BucketClient.PutBucketAsync(bucket2, AwsRegion.EUWest1).ConfigureAwait(false); List <S3Bucket> list = await ServiceClient.GetServiceAllAsync().ToListAsync().ConfigureAwait(false); Assert.True(list.Count >= 2); //Larger than because other tests might have run at the same time S3Bucket bucket1obj = Assert.Single(list, x => x.Name == bucket1); Assert.Equal(DateTime.UtcNow, bucket1obj.CreationDate.DateTime, TimeSpan.FromSeconds(5)); S3Bucket bucket2obj = Assert.Single(list, x => x.Name == bucket2); Assert.Equal(DateTime.UtcNow, bucket2obj.CreationDate.DateTime, TimeSpan.FromSeconds(5)); //Cleanup await BucketClient.DeleteBucketAsync(bucket1).ConfigureAwait(false); await BucketClient.DeleteBucketAsync(bucket2).ConfigureAwait(false); }
public async Task ListObjects() { await CreateTempBucketAsync(async bucket => { //Create 3 objects in bucket, including an incomplete multipart upload await UploadAsync(bucket, "resource1").ConfigureAwait(false); await UploadAsync(bucket, "resource2").ConfigureAwait(false); InitiateMultipartUploadResponse initResp = await ObjectClient.InitiateMultipartUploadAsync(bucket, "multipart").ConfigureAwait(false); //List the objects List <S3Object> list = await BucketClient.GetBucketRecursiveAsync(bucket, true).ToListAsync().ConfigureAwait(false); //Only 2 objects should be present, as one of them is only initiated Assert.Equal(2, list.Count); Assert.Equal("resource1", list[0].Name); Assert.Equal("resource2", list[1].Name); //List multipart transfers List <S3Upload> uploads = await BucketClient.ListAllMultipartUploadsAsync(bucket).ToListAsync().ConfigureAwait(false); S3Upload upload = Assert.Single(uploads); Assert.Equal("multipart", upload.Name); }).ConfigureAwait(false); }
public async Task PutLifecycleConfigurationTest() { await CreateTempBucketAsync(async x => { IList <S3Rule> rules = new List <S3Rule> { new S3Rule(true, "Transition logs after 30 days to StandardIa and after 60 days to OneZoneIa") { Transitions = new List <S3Transition> { new S3Transition(30, StorageClass.StandardIa), new S3Transition(60, StorageClass.OneZoneIa) }, Filter = new S3Filter { Prefix = "logs/" } }, new S3Rule(true, "Expire temp folder after 5 days") { Expiration = new S3Expiration(5), Filter = new S3Filter { Prefix = "temp/" } } }; PutBucketLifecycleConfigurationResponse putResp = await BucketClient.PutBucketLifecycleConfigurationAsync(x, rules).ConfigureAwait(false); Assert.True(putResp.IsSuccess); }).ConfigureAwait(false); }
public async Task GetPutBucketLockConfiguration(LockMode mode) { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse createResp = await BucketClient.CreateBucketAsync(tempBucketName, req => req.EnableObjectLocking = true).ConfigureAwait(false); Assert.True(createResp.IsSuccess); PutBucketLockConfigurationResponse putResp = await BucketClient.PutBucketLockConfigurationAsync(tempBucketName, true, x => { x.LockMode = mode; x.LockRetainUntil = DateTimeOffset.UtcNow.AddDays(2); }).ConfigureAwait(false); Assert.True(putResp.IsSuccess); GetBucketLockConfigurationResponse getResp = await BucketClient.GetBucketLockConfigurationAsync(tempBucketName).ConfigureAwait(false); Assert.True(getResp.IsSuccess); Assert.Equal(mode, getResp.LockMode); Assert.Equal(DateTimeOffset.UtcNow.AddDays(2 - 1).DateTime, getResp.LockRetainUntil !.Value.DateTime, TimeSpan.FromMinutes(1)); //Delete again to cleanup await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); }
public async Task GetWithPrefix() { await CreateTempBucketAsync(async bucket => { string tempObjName = "object-" + Guid.NewGuid(); string tempObjName2 = "something-" + Guid.NewGuid(); await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello").ConfigureAwait(false); await ObjectClient.PutObjectStringAsync(bucket, tempObjName2, "world!").ConfigureAwait(false); GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket, request => request.Prefix = "object").ConfigureAwait(false); Assert.True(gResp.IsSuccess); Assert.Equal(1, gResp.KeyCount); Assert.Equal(1, gResp.Objects.Count); Assert.Equal("object", gResp.Prefix); Assert.Equal(tempObjName, gResp.Objects[0].Name); Assert.Equal(DateTime.UtcNow, gResp.Objects[0].LastModified.DateTime, TimeSpan.FromSeconds(5)); Assert.Equal("\"5d41402abc4b2a76b9719d911017c592\"", gResp.Objects[0].ETag); Assert.Equal(5, gResp.Objects[0].Size); Assert.Equal(StorageClass.Standard, gResp.Objects[0].StorageClass); }).ConfigureAwait(false); }
async void OnDoneClick(object sender, EventArgs e) { if (ContentView.IsAnyRequiredFieldEmpty) { string text = "Please fill out all required fields"; ContentView.Banner.SetInformationText(text, true); return; } ContentView.CancelCrosshairMode(); PointClient.MarkerSource.Clear(); ContentView.Popup.Hide(); UIImage image = ContentView.Content.CameraField.Photo.Image; BucketResponse response1; if (image == null) { // Photo is an optional field. // Create a mock successful response, // if the user hasn't taken a photo response1 = new BucketResponse(); response1.Path = ""; } else { Stream stream = Camera.GetStreamFromImage(image); ContentView.Banner.ShowUploadingImage(); string filename = ContentView.Content.CameraField.ImageName; response1 = await BucketClient.Upload(filename, stream); } if (response1.IsOk) { ContentView.Banner.ShowUploadingData(); Data item = GetData(response1.Path); CartoResponse response2 = await Networking.Post(item); if (response2.IsOk) { ContentView.Banner.Complete(); } else { ContentView.Banner.ShowFailedCartoUpload(); SQLClient.Instance.Insert(item); } } else { ContentView.Banner.ShowFailedAmazonUpload(); Data item = GetData(Camera.LatestImageName); SQLClient.Instance.Insert(item); } ContentView.Content.Clear(); PointClient.QueryPoints(delegate { }); }
public async Task MoreThanMaxKeys() { await CreateTempBucketAsync(async bucket => { int concurrent = 10; int count = 1001; Queue <Task> tasks = new Queue <Task>(count); using (SemaphoreSlim semaphore = new SemaphoreSlim(concurrent)) { for (int i = 0; i < count; i++) { await semaphore.WaitAsync().ConfigureAwait(false); string tempObjName = "object-" + Guid.NewGuid(); tasks.Enqueue(UploadString(bucket, tempObjName, semaphore)); } await Task.WhenAll(tasks).ConfigureAwait(false); } GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket).ConfigureAwait(false); Assert.True(gResp.IsSuccess); Assert.Equal(1000, gResp.KeyCount); Assert.Equal(1000, gResp.Objects.Count); Assert.NotEmpty(gResp.NextContinuationToken); Assert.True(gResp.IsTruncated); }).ConfigureAwait(false); }
public async Task ListIncompleteParts() { await CreateTempBucketAsync(async bucket => { InitiateMultipartUploadResponse initResp = await ObjectClient.InitiateMultipartUploadAsync(bucket, nameof(ListIncompleteParts)).ConfigureAwait(false); byte[] file = new byte[5 * 1024]; using (MemoryStream ms = new MemoryStream(file)) await ObjectClient.UploadPartAsync(bucket, nameof(ListIncompleteParts), 1, initResp.UploadId, ms).ConfigureAwait(false); ListMultipartUploadsResponse listResp = await BucketClient.ListMultipartUploadsAsync(bucket).ConfigureAwait(false); Assert.Equal(bucket, listResp.Bucket); Assert.Equal("ListIncompleteParts", listResp.NextKeyMarker); Assert.NotEmpty(listResp.NextUploadIdMarker); Assert.Equal(1000, listResp.MaxUploads); Assert.False(listResp.IsTruncated); S3Upload upload = Assert.Single(listResp.Uploads); Assert.Equal(listResp.NextKeyMarker, upload.Name); Assert.Equal(listResp.NextUploadIdMarker, upload.UploadId); Assert.Equal(TestConstants.TestUsername, upload.Initiator.Name); Assert.Equal(StorageClass.Standard, upload.StorageClass); Assert.Equal(DateTime.UtcNow, upload.Initiated.DateTime, TimeSpan.FromSeconds(5)); }).ConfigureAwait(false); }
public async Task GetWhenBucketLockIsDisabled() { await CreateTempBucketAsync(async x => { GetBucketLockConfigurationResponse getResp = await BucketClient.GetBucketLockConfigurationAsync(x).ConfigureAwait(false); Assert.Equal(404, getResp.StatusCode); }).ConfigureAwait(false); }
public async Task GetEmptyBucketTagging() { await CreateTempBucketAsync(async x => { GetBucketTaggingResponse getResp = await BucketClient.GetBucketTaggingAsync(x).ConfigureAwait(false); Assert.Equal(404, getResp.StatusCode); }).ConfigureAwait(false); }
public async Task ListBuckets() { string tempBucketName = "testbucket-" + Guid.NewGuid(); await BucketClient.CreateBucketAsync(tempBucketName).ConfigureAwait(false); HeadBucketResponse headResp = await BucketClient.HeadBucketAsync(tempBucketName).ConfigureAwait(false); Assert.Equal(200, headResp.StatusCode); }
public async Task CreateBucket() { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse resp = await BucketClient.CreateBucketAsync(tempBucketName).ConfigureAwait(false); Assert.True(resp.IsSuccess); //Delete again to cleanup await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); }
public async Task GetService() { string tempBucketName = "testbucket-" + Guid.NewGuid(); await BucketClient.PutBucketAsync(tempBucketName, request => request.Region = Config.Region).ConfigureAwait(false); GetServiceResponse resp = await ServiceClient.GetServiceAsync().ConfigureAwait(false); Assert.True(resp.Buckets.Count > 0); Assert.NotNull(resp.Buckets.SingleOrDefault(x => x.Name == tempBucketName)); }
public async Task PutWithObjectLocking() { string tempBucketName = "testbucket-" + Guid.NewGuid(); PutBucketResponse pResp = await BucketClient.PutBucketAsync(tempBucketName, request => { request.EnableObjectLocking = true; request.Region = Config.Region; }).ConfigureAwait(false); Assert.True(pResp.IsSuccess); }
public async Task CreateBucketObjectLocking() { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse resp = await BucketClient.CreateBucketAsync(tempBucketName, req => req.EnableObjectLocking = true).ConfigureAwait(false); Assert.True(resp.IsSuccess); //TODO: Check locking is enabled once we have that functionality //Delete again to cleanup await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); }
public async Task CreateBucketCannedAcl() { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse resp = await BucketClient.CreateBucketAsync(tempBucketName, req => req.Acl = BucketCannedAcl.PublicReadWrite).ConfigureAwait(false); Assert.True(resp.IsSuccess); //TODO: Check ACL once we have that functionality //Delete again to cleanup await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); }
public async Task ListBuckets() { string tempBucketName = "testbucket-" + Guid.NewGuid(); await BucketClient.CreateBucketAsync(tempBucketName).ConfigureAwait(false); ListBucketsResponse listResp = await BucketClient.ListBucketsAsync().ConfigureAwait(false); Assert.True(listResp.Buckets.Count > 0); S3Bucket bucketObj = Assert.Single(listResp.Buckets, bucket => bucket.Name == tempBucketName); Assert.Equal(bucketObj.CreatedOn.UtcDateTime, DateTime.UtcNow, TimeSpan.FromSeconds(5)); }
public async Task PutAndGet() { string tempBucketName = "testbucket-" + Guid.NewGuid(); PutBucketResponse pResp = await BucketClient.PutBucketAsync(tempBucketName, request => { request.Region = Config.Region; request.Acl = BucketCannedAcl.Private; }).ConfigureAwait(false); Assert.True(pResp.IsSuccess); //We prefix with a number here to keep sort order when we download the list of objects further down string tempObjName = "object-1" + Guid.NewGuid(); string tempObjName2 = "object-2" + Guid.NewGuid(); await ObjectClient.PutObjectStringAsync(tempBucketName, tempObjName, "hello").ConfigureAwait(false); await ObjectClient.PutObjectStringAsync(tempBucketName, tempObjName2, "world!", null, request => request.StorageClass = StorageClass.OneZoneIa).ConfigureAwait(false); GetBucketResponse gResp = await BucketClient.GetBucketAsync(tempBucketName).ConfigureAwait(false); Assert.True(gResp.IsSuccess); Assert.Equal(2, gResp.KeyCount); Assert.Equal(2, gResp.Objects.Count); Assert.Equal(string.Empty, gResp.Prefix); Assert.Equal(tempObjName, gResp.Objects[0].Name); Assert.Equal(DateTime.UtcNow, gResp.Objects[0].LastModified.DateTime, TimeSpan.FromSeconds(5)); Assert.Equal("\"5d41402abc4b2a76b9719d911017c592\"", gResp.Objects[0].ETag); Assert.Equal(5, gResp.Objects[0].Size); Assert.Equal(StorageClass.Standard, gResp.Objects[0].StorageClass); Assert.Equal(tempObjName2, gResp.Objects[1].Name); Assert.Equal(DateTime.UtcNow, gResp.Objects[1].LastModified.DateTime, TimeSpan.FromSeconds(5)); Assert.Equal("\"08cf82251c975a5e9734699fadf5e9c0\"", gResp.Objects[1].ETag); Assert.Equal(6, gResp.Objects[1].Size); Assert.Equal(StorageClass.OneZoneIa, gResp.Objects[1].StorageClass); GetBucketResponse gResp2 = await BucketClient.GetBucketAsync(tempBucketName, request => request.EncodingType = EncodingType.Url).ConfigureAwait(false); Assert.True(gResp2.IsSuccess); Assert.Equal(2, gResp2.KeyCount); //The keys should be URL encoded at this point Assert.Equal(UrlHelper.UrlEncode(tempObjName), gResp.Objects[0].Name); Assert.Equal(UrlHelper.UrlEncode(tempObjName2), gResp.Objects[1].Name); }
public async Task PutGetBucketAccelerateConfiguration() { await CreateTempBucketAsync(async x => { GetBucketAccelerateConfigurationResponse getResp = await BucketClient.GetBucketAccelerateConfigurationAsync(x).ConfigureAwait(false); Assert.True(getResp.IsSuccess); Assert.False(getResp.AccelerateEnabled); PutBucketAccelerateConfigurationResponse putResp = await BucketClient.PutBucketAccelerateConfigurationAsync(x, true).ConfigureAwait(false); Assert.True(putResp.IsSuccess); getResp = await BucketClient.GetBucketAccelerateConfigurationAsync(x).ConfigureAwait(false); Assert.True(getResp.IsSuccess); Assert.True(getResp.AccelerateEnabled); }).ConfigureAwait(false); }
public async Task GetWithOwner() { await CreateTempBucketAsync(async bucket => { string tempObjName = "object-" + Guid.NewGuid(); await ObjectClient.PutObjectStringAsync(bucket, tempObjName, string.Empty, config: request => request.AclGrantFullControl.AddEmail(TestConstants.TestEmail)).ConfigureAwait(false); GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket, request => request.FetchOwner = true).ConfigureAwait(false); Assert.True(gResp.IsSuccess); Assert.Equal(1, gResp.KeyCount); S3Object obj = gResp.Objects.First(); Assert.Equal(TestConstants.TestUsername, obj.Owner.Name); Assert.Equal(TestConstants.TestUserId, obj.Owner.Id); }).ConfigureAwait(false); }
public async Task PutWithAcl() { string tempBucketName = "testbucket-" + Guid.NewGuid(); PutBucketResponse pResp = await BucketClient.PutBucketAsync(tempBucketName, request => { request.AclGrantReadAcp.AddEmail(TestConstants.TestEmail); request.AclGrantWriteAcp.AddEmail(TestConstants.TestEmail); request.AclGrantRead.AddEmail(TestConstants.TestEmail); request.AclGrantWrite.AddEmail(TestConstants.TestEmail); request.AclGrantFullControl.AddEmail(TestConstants.TestEmail); request.Region = Config.Region; }).ConfigureAwait(false); Assert.True(pResp.IsSuccess); }
public async Task GetEmptyBucketLock() { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse createResp = await BucketClient.CreateBucketAsync(tempBucketName, req => req.EnableObjectLocking = true).ConfigureAwait(false); Assert.True(createResp.IsSuccess); GetBucketLockConfigurationResponse getResp = await BucketClient.GetBucketLockConfigurationAsync(tempBucketName).ConfigureAwait(false); Assert.True(getResp.IsSuccess); Assert.Equal(LockMode.Unknown, getResp.LockMode); Assert.Null(getResp.LockRetainUntil); //Delete again to cleanup await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); }
public async Task GetWithDelimiter() { await CreateTempBucketAsync(async bucket => { string tempObjName = "object-" + Guid.NewGuid(); string tempObjName2 = "something-" + Guid.NewGuid(); await ObjectClient.PutObjectStringAsync(bucket, tempObjName, "hello").ConfigureAwait(false); await ObjectClient.PutObjectStringAsync(bucket, tempObjName2, "world!").ConfigureAwait(false); GetBucketResponse gResp = await BucketClient.GetBucketAsync(bucket, request => request.Delimiter = "-").ConfigureAwait(false); Assert.True(gResp.IsSuccess); Assert.Equal(2, gResp.KeyCount); Assert.Equal(2, gResp.CommonPrefixes.Count); Assert.Equal("object-", gResp.CommonPrefixes[0]); Assert.Equal("something-", gResp.CommonPrefixes[1]); }).ConfigureAwait(false); }
protected async Task CreateTempBucketAsync(Func <string, Task> action) { string tempBucketName = "testbucket-" + Guid.NewGuid(); PutBucketResponse putResponse = await BucketClient.PutBucketAsync(tempBucketName, request => request.Region = Config.Region).ConfigureAwait(false); Assert.True(putResponse.IsSuccess); try { await(action?.Invoke(tempBucketName)).ConfigureAwait(false); } catch (Exception) { } DeleteBucketStatus errorCode = await BucketClient.DeleteBucketRecursiveAsync(tempBucketName).ConfigureAwait(false); Assert.Equal(DeleteBucketStatus.Ok, errorCode); }
public async Task GetPutDeleteBucketTagging() { await CreateTempBucketAsync(async x => { IDictionary <string, string> tags = new Dictionary <string, string>(); tags.Add("MyKey", "MyValue"); tags.Add("MyKey2", "MyValue2"); PutBucketTaggingResponse putResp = await BucketClient.PutBucketTaggingAsync(x, tags).ConfigureAwait(false); Assert.True(putResp.IsSuccess); GetBucketTaggingResponse getResp = await BucketClient.GetBucketTaggingAsync(x).ConfigureAwait(false); Assert.True(getResp.IsSuccess); Assert.Equal(tags, getResp.Tags); DeleteBucketTaggingResponse deleteResp = await BucketClient.DeleteBucketTaggingAsync(x).ConfigureAwait(false); Assert.True(deleteResp.IsSuccess); }).ConfigureAwait(false); }
public async Task CreateBucketCustomAcl() { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse resp = await BucketClient.CreateBucketAsync(tempBucketName, req => { req.AclGrantReadAcp.AddEmail(TestConstants.TestEmail); req.AclGrantWriteAcp.AddEmail(TestConstants.TestEmail); req.AclGrantRead.AddEmail(TestConstants.TestEmail); req.AclGrantWrite.AddEmail(TestConstants.TestEmail); req.AclGrantFullControl.AddEmail(TestConstants.TestEmail); }).ConfigureAwait(false); Assert.True(resp.IsSuccess); //TODO: Check ACL once we have that functionality //Delete again to cleanup await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); }
public async Task DeleteBucket() { string tempBucketName = "testbucket-" + Guid.NewGuid(); DeleteBucketResponse delete1 = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); Assert.False(delete1.IsSuccess); Assert.Equal(ErrorCode.NoSuchBucket, delete1.Error.Code); await BucketClient.PutBucketAsync(tempBucketName, request => request.Region = Config.Region).ConfigureAwait(false); DeleteBucketResponse delete2 = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); Assert.True(delete2.IsSuccess); Assert.Equal(204, delete2.StatusCode); GetBucketResponse resp = await BucketClient.GetBucketAsync(tempBucketName).ConfigureAwait(false); Assert.False(resp.IsSuccess); Assert.Equal(404, resp.StatusCode); }
public async Task DeleteBucket() { string tempBucketName = "testbucket-" + Guid.NewGuid(); DeleteBucketResponse deleteResp1 = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); Assert.False(deleteResp1.IsSuccess); Assert.Equal(ErrorCode.NoSuchBucket, deleteResp1.Error?.Code); await BucketClient.CreateBucketAsync(tempBucketName).ConfigureAwait(false); DeleteBucketResponse deleteResp2 = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); Assert.True(deleteResp2.IsSuccess); Assert.Equal(204, deleteResp2.StatusCode); ListObjectsResponse listResp = await ObjectClient.ListObjectsAsync(tempBucketName).ConfigureAwait(false); Assert.False(listResp.IsSuccess); Assert.Equal(404, listResp.StatusCode); }
public async void OnUploadAlertOK(UIAlertAction action) { List <Data> items = SQLClient.Instance.GetAll(); int count = items.Count; ContentView.Banner.ShowUploadingEverything(count); foreach (Data item in items) { if (!item.IsUploadedToAmazon) { if (item.ImageUrl != "") { byte[] bytes = File.ReadAllBytes(FileUtils.GetFolder(item.ImageUrl)); Stream stream = new MemoryStream(bytes); BucketResponse response1 = await BucketClient.Upload(item.FileName, stream); if (response1.IsOk) { item.ImageUrl = response1.Path; Console.WriteLine("Uploaded offline image to: " + response1.Path); } } } } CartoResponse response2 = await Networking.Post(items); if (response2.IsOk) { ContentView.Banner.ShowUploadedEverything(count); SQLClient.Instance.DeleteAll(); } else { ContentView.Banner.ShowEverythingUploadFailed(count); SQLClient.Instance.UpdateAll(items); } }
protected async Task CreateTempBucketAsync(Func <string, Task> action) { string tempBucketName = "testbucket-" + Guid.NewGuid(); CreateBucketResponse createResponse = await BucketClient.CreateBucketAsync(tempBucketName).ConfigureAwait(false); Assert.True(createResponse.IsSuccess); try { await action(tempBucketName).ConfigureAwait(false); } finally { DeleteAllObjectsStatus delResp = await ObjectClient.DeleteAllObjectsAsync(tempBucketName).ConfigureAwait(false); Assert.Equal(DeleteAllObjectsStatus.Ok, delResp); DeleteBucketResponse del2Resp = await BucketClient.DeleteBucketAsync(tempBucketName).ConfigureAwait(false); Assert.True(del2Resp.IsSuccess); } }