public async Task BlobSnapshotSas_AllPermissions() { // Arrange await using DisposingContainer test = await GetTestContainerAsync(); string blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); await blob.CreateAsync(); Response <BlobSnapshotInfo> snapshotResponse = await blob.CreateSnapshotAsync(); BlobSasBuilder blobSasBuilder = new BlobSasBuilder() { ExpiresOn = Recording.UtcNow.AddDays(1), BlobContainerName = test.Container.Name, BlobName = blobName, Snapshot = snapshotResponse.Value.Snapshot }; blobSasBuilder.SetPermissions(SnapshotSasPermissions.All); BlobUriBuilder blobUriBuilder = new BlobUriBuilder(blob.Uri) { Snapshot = snapshotResponse.Value.Snapshot, Sas = blobSasBuilder.ToSasQueryParameters(GetNewSharedKeyCredentials()) }; // Act AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions())); await sasBlobClient.GetPropertiesAsync(); }
public async Task AccountSas_AllPermissions() { // Arrange await using DisposingContainer test = await GetTestContainerAsync(); string blobName = GetNewBlobName(); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); await blob.CreateAsync(); AccountSasBuilder accountSasBuilder = new AccountSasBuilder( permissions: AccountSasPermissions.All, expiresOn: Recording.UtcNow.AddDays(1), services: AccountSasServices.Blobs, resourceTypes: AccountSasResourceTypes.Object); Uri accountSasUri = test.Container.GetParentBlobServiceClient().GenerateAccountSasUri(accountSasBuilder); BlobUriBuilder blobUriBuilder = new BlobUriBuilder(accountSasUri) { BlobContainerName = test.Container.Name, BlobName = blobName }; // Assert AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions())); await sasBlobClient.GetPropertiesAsync(); }
private static readonly int MaxBlocksOnBlobBeforeRoll = 49500; //small margin to the practical max of 50k, in case of many multiple writers to the same blob public async Task <AppendBlobClient> GetCloudBlobAsync(BlobServiceClient blobServiceClient, string blobContainerName, string blobName, bool bypassBlobCreationValidation, long?blobSizeLimitBytes = null) { // Check if the current known blob is the targeted blob if (currentAppendBlobClient != null && currentBlobName.Equals(blobName, StringComparison.OrdinalIgnoreCase)) { // Before performing validate first fetch attributes for current file size Response <BlobProperties> propertiesResponse = await currentAppendBlobClient.GetPropertiesAsync().ConfigureAwait(false); BlobProperties properties = propertiesResponse.Value; // Check if the current blob is within the block count and file size limits if (ValidateBlobProperties(properties, blobSizeLimitBytes)) { return(currentAppendBlobClient); } // The blob is correct but needs to be rolled over currentBlobRollSequence++; await GetAppendBlobClientAsync(blobServiceClient, blobContainerName, blobName, bypassBlobCreationValidation); } else { //first time to get a cloudblob or the blobname has changed currentBlobRollSequence = 0; await GetAppendBlobClientAsync(blobServiceClient, blobContainerName, blobName, bypassBlobCreationValidation, blobSizeLimitBytes); } return(currentAppendBlobClient); }
public async Task CreateAppendBlob_ImmutableStorageWithVersioning() { // Arrange await using DisposingImmutableStorageWithVersioningContainer vlwContainer = await GetTestVersionLevelWormContainer(TestConfigOAuth); AppendBlobClient appendBlob = InstrumentClient(vlwContainer.Container.GetAppendBlobClient(GetNewBlobName())); BlobImmutabilityPolicy immutabilityPolicy = new BlobImmutabilityPolicy { ExpiresOn = Recording.UtcNow.AddMinutes(5), PolicyMode = BlobImmutabilityPolicyMode.Unlocked }; // The service rounds Immutability Policy Expiry to the nearest second. DateTimeOffset expectedImmutabilityPolicyExpiry = RoundToNearestSecond(immutabilityPolicy.ExpiresOn.Value); AppendBlobCreateOptions options = new AppendBlobCreateOptions { ImmutabilityPolicy = immutabilityPolicy, HasLegalHold = true }; // Act Response <BlobContentInfo> createResponse = await appendBlob.CreateAsync(options); // Assert Response <BlobProperties> propertiesResponse = await appendBlob.GetPropertiesAsync(); Assert.AreEqual(expectedImmutabilityPolicyExpiry, propertiesResponse.Value.ImmutabilityPolicy.ExpiresOn); Assert.AreEqual(immutabilityPolicy.PolicyMode, propertiesResponse.Value.ImmutabilityPolicy.PolicyMode); Assert.IsTrue(propertiesResponse.Value.HasLegalHold); }
public async Task CreateAsync_Metadata() { await using DisposingContainer test = await GetTestContainerAsync(); // Arrange AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(GetNewBlobName())); IDictionary <string, string> metadata = BuildMetadata(); // Act await blob.CreateAsync( metadata : metadata); // Assert Response <BlobProperties> response = await blob.GetPropertiesAsync(); AssertMetadataEquality(metadata, response.Value.Metadata); }
private async Task GetAppendBlobClientAsync(BlobServiceClient blobServiceClient, string blobContainerName, string blobName, bool bypassBlobCreationValidation, long?blobSizeLimitBytes = null) { //try to get a reference to a AppendBlobClient which is below the max blocks threshold. for (int i = currentBlobRollSequence; i < 999; i++) { string rolledBlobName = GetRolledBlobName(blobName, i); AppendBlobClient newAppendBlobClient = await GetBlobReferenceAsync(blobServiceClient, blobContainerName, rolledBlobName, bypassBlobCreationValidation); var blobPropertiesResponse = await newAppendBlobClient.GetPropertiesAsync(); var blobProperties = blobPropertiesResponse.Value; if (ValidateBlobProperties(blobProperties, blobSizeLimitBytes)) { currentAppendBlobClient = newAppendBlobClient; currentBlobName = blobName; currentBlobRollSequence = i; break; } } }
public async Task BlobSnapshotIdentitySas_AllPermissions() { // Arrange BlobServiceClient oauthService = GetServiceClient_OauthAccount(); string containerName = GetNewContainerName(); string blobName = GetNewBlobName(); await using DisposingContainer test = await GetTestContainerAsync(containerName : containerName, service : oauthService); Response <UserDelegationKey> userDelegationKey = await oauthService.GetUserDelegationKeyAsync( startsOn : null, expiresOn : Recording.UtcNow.AddHours(1)); AppendBlobClient blob = InstrumentClient(test.Container.GetAppendBlobClient(blobName)); await blob.CreateAsync(); Response <BlobSnapshotInfo> snapshotResponse = await blob.CreateSnapshotAsync(); BlobSasBuilder blobSasBuilder = new BlobSasBuilder() { ExpiresOn = Recording.UtcNow.AddDays(1), BlobContainerName = test.Container.Name, BlobName = blobName, Snapshot = snapshotResponse.Value.Snapshot }; blobSasBuilder.SetPermissions(SnapshotSasPermissions.All); BlobUriBuilder blobUriBuilder = new BlobUriBuilder(blob.Uri) { Snapshot = snapshotResponse.Value.Snapshot, Sas = blobSasBuilder.ToSasQueryParameters(userDelegationKey.Value, oauthService.AccountName) }; // Act AppendBlobClient sasBlobClient = InstrumentClient(new AppendBlobClient(blobUriBuilder.ToUri(), GetOptions())); await sasBlobClient.GetPropertiesAsync(); }