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 OverwriteExistingLock(S3Provider provider, string _, ISimpleClient client) { await CreateTempBucketAsync(provider, client, async tempBucket => { PutBucketLockConfigurationResponse putResp = await client.PutBucketLockConfigurationAsync(tempBucket, true, r => { r.LockMode = LockMode.Compliance; r.LockRetainUntil = DateTimeOffset.UtcNow.AddDays(2); }).ConfigureAwait(false); Assert.Equal(200, putResp.StatusCode); GetBucketLockConfigurationResponse getResp = await client.GetBucketLockConfigurationAsync(tempBucket).ConfigureAwait(false); Assert.Equal(200, getResp.StatusCode); Assert.Equal(LockMode.Compliance, getResp.LockMode); Assert.Equal(DateTimeOffset.UtcNow.AddDays(2 - 1).DateTime, getResp.LockRetainUntil !.Value.DateTime, TimeSpan.FromMinutes(1)); PutBucketLockConfigurationResponse putResp2 = await client.PutBucketLockConfigurationAsync(tempBucket, true, r => { r.LockMode = LockMode.Governance; r.LockRetainUntil = DateTimeOffset.UtcNow.AddDays(5); }).ConfigureAwait(false); Assert.Equal(200, putResp2.StatusCode); GetBucketLockConfigurationResponse getResp2 = await client.GetBucketLockConfigurationAsync(tempBucket).ConfigureAwait(false); Assert.Equal(200, getResp2.StatusCode); Assert.Equal(LockMode.Governance, getResp2.LockMode); Assert.Equal(DateTimeOffset.UtcNow.AddDays(5 - 1).DateTime, getResp2.LockRetainUntil !.Value.DateTime, TimeSpan.FromMinutes(1)); }).ConfigureAwait(false); }
private static async Task PostConfigureBackBlazeB2(IBucketClient bucketClient, string bucketName) { Console.WriteLine("Adding lock configuration"); PutBucketLockConfigurationResponse putLockResp = await bucketClient.PutBucketLockConfigurationAsync(bucketName, true).ConfigureAwait(false); if (putLockResp.IsSuccess) { Console.WriteLine("Successfully applied lock configuration."); } else { Console.Error.WriteLine("Failed to apply lock configuration."); } }
public async Task GetPutBucketLockConfiguration(S3Provider provider, string _, ISimpleClient client, LockMode mode) { await CreateTempBucketAsync(provider, client, async tempBucket => { PutBucketLockConfigurationResponse putResp = await client.PutBucketLockConfigurationAsync(tempBucket, true, x => { x.LockMode = mode; x.LockRetainUntil = DateTimeOffset.UtcNow.AddDays(2); }).ConfigureAwait(false); Assert.Equal(200, putResp.StatusCode); GetBucketLockConfigurationResponse getResp = await client.GetBucketLockConfigurationAsync(tempBucket).ConfigureAwait(false); Assert.Equal(200, getResp.StatusCode); Assert.Equal(mode, getResp.LockMode); Assert.Equal(DateTimeOffset.UtcNow.AddDays(2 - 1).DateTime, getResp.LockRetainUntil !.Value.DateTime, TimeSpan.FromMinutes(1)); }, r => r.EnableObjectLocking = true).ConfigureAwait(false); }
private static async Task PostConfigureAmazonS3(IBucketClient bucketClient, string bucketName) { Console.WriteLine("Adding lock configuration"); PutBucketLockConfigurationResponse putLockResp = await bucketClient.PutBucketLockConfigurationAsync(bucketName, true).ConfigureAwait(false); if (putLockResp.IsSuccess) { Console.WriteLine("Successfully applied lock configuration."); } else { Console.Error.WriteLine("Failed to apply lock configuration."); } List <S3Rule> rules = new List <S3Rule> { new S3Rule("ExpireAll", true) { AbortIncompleteMultipartUploadDays = 1, NonCurrentVersionExpirationDays = 1, Expiration = new S3Expiration(1), Filter = new S3Filter { Prefix = "" } } }; Console.WriteLine("Adding lifecycle configuration"); PutBucketLifecycleConfigurationResponse putLifecycleResp = await bucketClient.PutBucketLifecycleConfigurationAsync(bucketName, rules).ConfigureAwait(false); if (putLifecycleResp.IsSuccess) { Console.WriteLine("Successfully applied lifecycle configuration."); } else { Console.Error.WriteLine("Failed to apply lifecycle configuration."); } }
private static async Task Main(string[] args) { IConfigurationRoot root = new ConfigurationBuilder() .AddJsonFile("Config.json", false) .Build(); ServiceCollection services = new ServiceCollection(); services.Configure <S3Config>(root); IS3ClientBuilder clientBuilder = services.AddSimpleS3(); clientBuilder.CoreBuilder.UseProfileManager() .BindConfigToDefaultProfile() .UseDataProtection(); IConfigurationSection proxySection = root.GetSection("Proxy"); if (proxySection != null && proxySection["UseProxy"].Equals("true", StringComparison.OrdinalIgnoreCase)) { clientBuilder.HttpBuilder.WithProxy(proxySection["ProxyAddress"]); } using (ServiceProvider provider = services.BuildServiceProvider()) { IProfileManager manager = provider.GetRequiredService <IProfileManager>(); IProfile? profile = manager.GetDefaultProfile(); //If profile is null, then we do not yet have a profile stored on disk. We use ConsoleSetup as an easy and secure way of asking for credentials if (profile == null) { Console.WriteLine("No profile found. Starting setup."); ConsoleSetup.SetupDefaultProfile(manager); } IBucketClient bucketClient = provider.GetRequiredService <IBucketClient>(); string bucketName = root["BucketName"]; Console.WriteLine($"Setting up bucket '{bucketName}'"); HeadBucketResponse headResp = await bucketClient.HeadBucketAsync(bucketName).ConfigureAwait(false); if (headResp.IsSuccess) { Console.WriteLine($"'{bucketName}' already exist."); } else { Console.WriteLine($"'{bucketName}' does not exist - creating."); CreateBucketResponse createResp = await bucketClient.CreateBucketAsync(bucketName, x => x.EnableObjectLocking = true).ConfigureAwait(false); if (createResp.IsSuccess) { Console.WriteLine($"Successfully created '{bucketName}'."); } else { Console.Error.WriteLine($"Failed to create '{bucketName}'. Exiting."); return; } } Console.WriteLine("Adding lock configuration"); PutBucketLockConfigurationResponse putLockResp = await bucketClient.PutBucketLockConfigurationAsync(bucketName, true).ConfigureAwait(false); if (putLockResp.IsSuccess) { Console.WriteLine("Successfully applied lock configuration."); } else { Console.Error.WriteLine("Failed to apply lock configuration."); } List <S3Rule> rules = new List <S3Rule> { new S3Rule("ExpireAll", true) { AbortIncompleteMultipartUploadDays = 1, NonCurrentVersionExpirationDays = 1, Expiration = new S3Expiration(1), Filter = new S3Filter { Prefix = "" } } }; Console.WriteLine("Adding lifecycle configuration"); PutBucketLifecycleConfigurationResponse putLifecycleResp = await bucketClient.PutBucketLifecycleConfigurationAsync(bucketName, rules).ConfigureAwait(false); if (putLifecycleResp.IsSuccess) { Console.WriteLine("Successfully applied lifecycle configuration."); } else { Console.Error.WriteLine("Failed to apply lifecycle configuration."); } } }