public static BlobContainerProperties BlobContainerProperties( DateTimeOffset lastModified, ETag eTag, LeaseState?leaseState, LeaseDurationType?leaseDuration, PublicAccessType?publicAccess, LeaseStatus?leaseStatus, bool?hasLegalHold, string defaultEncryptionScope, bool?preventEncryptionScopeOverride, IDictionary <string, string> metadata, bool?hasImmutabilityPolicy) => new BlobContainerProperties() { LastModified = lastModified, ETag = eTag, LeaseState = leaseState, LeaseDuration = leaseDuration, PublicAccess = publicAccess, LeaseStatus = leaseStatus, HasLegalHold = hasLegalHold, DefaultEncryptionScope = defaultEncryptionScope, PreventEncryptionScopeOverride = preventEncryptionScopeOverride, Metadata = metadata, HasImmutabilityPolicy = hasImmutabilityPolicy, };
public async Task <DisposingFileSystem> GetNewFileSystem( DataLakeServiceClient service = default, string fileSystemName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default, bool premium = default) => await DataLakeClientBuilder.GetNewFileSystem(service, fileSystemName, metadata, publicAccessType, premium);
/// <summary> /// Creates a new FileSystemProperties instance for mocking. /// </summary> public static FileSystemProperties FileSystemProperties( DateTimeOffset lastModified = default, DataLakeLeaseStatus?leaseStatus = default, DataLakeLeaseState?leaseState = default, DataLakeLeaseDuration?leaseDuration = default, PublicAccessType?publicAccess = default, bool?hasImmutabilityPolicy = default, bool?hasLegalHold = default, ETag eTag = default, IDictionary <string, string> metadata = default, DateTimeOffset?deletedOn = default, int?remainingRetentionDays = default) => new FileSystemProperties() { LastModified = lastModified, LeaseStatus = leaseStatus, LeaseState = leaseState, LeaseDuration = leaseDuration, PublicAccess = publicAccess, HasImmutabilityPolicy = hasImmutabilityPolicy, HasLegalHold = hasLegalHold, ETag = eTag, Metadata = metadata, DeletedOn = deletedOn, RemainingRetentionDays = remainingRetentionDays };
/// <inheritdoc/> public async ValueTask <BlobContainerClient> GetBlobContainerClientFromTenantAsync( ITenant tenant, string v2ConfigurationKey, string v3ConfigurationKey, string?containerName, BlobClientOptions?blobClientOptions, CancellationToken cancellationToken) { bool v3ConfigWasAvailable = false; PublicAccessType?publicAccessType = null; if (tenant.Properties.TryGet(v3ConfigurationKey, out BlobContainerConfiguration v3Configuration)) { v3ConfigWasAvailable = true; v3Configuration = AddContainerNameIfNotInConfig(v3Configuration, containerName); } else if (tenant.Properties.TryGet(v2ConfigurationKey, out LegacyV2BlobStorageConfiguration legacyConfiguration)) { v3Configuration = V3ConfigurationFromLegacy(tenant, containerName, legacyConfiguration); publicAccessType = legacyConfiguration.AccessType switch { LegacyV2BlobContainerPublicAccessType.Blob => PublicAccessType.Blob, LegacyV2BlobContainerPublicAccessType.Container => PublicAccessType.BlobContainer, _ => PublicAccessType.None, }; } else { throw new InvalidOperationException("Tenant did not contain blob storage configuration under specified v2 or v3 keys"); } if (v3Configuration.Container == null) { throw new InvalidOperationException($"When the configuration does not specify a Container, you must supply a non-null {nameof(containerName)}"); } BlobContainerClient result = await this.blobContainerSource.GetStorageContextAsync( v3Configuration, blobClientOptions, cancellationToken) .ConfigureAwait(false); // If the settings say to create a new V3 config if there wasn't already one, it's important // that we don't do this until after successfully creating the container, because in the world // of V3, apps are supposed to create containers before they create the relevant configuration. // (There's a wrinkle here: if an application is using multiple logical containers per // tenant, then what are they supposed to do? Should we offer a "create all the containers" // option?) if (!v3ConfigWasAvailable) { if (publicAccessType.HasValue) { await result.CreateIfNotExistsAsync( publicAccessType.Value, cancellationToken : cancellationToken).ConfigureAwait(false); } } return(result); }
public async Task <DisposingContainer> GetTestContainerAsync( BlobServiceClient service = default, string containerName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default, bool premium = default) => await BlobsClientBuilder.GetTestContainerAsync(service, containerName, metadata, publicAccessType, premium);
internal ContainerProperties(DateTimeOffset lastModified, string etag, LeaseStatusType?leaseStatus, LeaseStateType?leaseState, LeaseDurationType?leaseDuration, PublicAccessType?publicAccess) { LastModified = lastModified; Etag = etag; LeaseStatus = leaseStatus; LeaseState = leaseState; LeaseDuration = leaseDuration; PublicAccess = publicAccess; }
/// <summary> /// The <see cref="CreateBlobContainer"/> operation creates a new /// container under the specified account. If the container with the /// same name already exists, the operation fails. /// /// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"/>. /// </summary> /// <param name="containerName"> /// The name of the container to create. /// </param> /// <param name="publicAccessType"> /// Optionally specifies whether data in the container may be accessed /// publicly and the level of access. <see cref="PublicAccessType.Container"/> /// specifies full public read access for container and blob data. /// Clients can enumerate blobs within the container via anonymous /// request, but cannot enumerate containers within the storage /// account. <see cref="PublicAccessType.Blob"/> specifies public /// read access for blobs. Blob data within this container can be /// read via anonymous request, but container data is not available. /// Clients cannot enumerate blobs within the container via anonymous /// request. If this parameter is null, container data is private to /// the account owner. /// </param> /// <param name="metadata"> /// Optional custom metadata to set for this container. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Task{Response{BlobContainerClient}}"/> referencing the /// newly created container. /// </returns> /// <remarks> /// A <see cref="StorageRequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual Response <BlobContainerClient> CreateBlobContainer( string containerName, PublicAccessType?publicAccessType = default, Metadata metadata = default, CancellationToken cancellationToken = default) { var container = this.GetBlobContainerClient(containerName); var response = container.Create(publicAccessType, metadata, cancellationToken); return(new Response <BlobContainerClient>(response.GetRawResponse(), container)); }
/// <summary> /// The <see cref="CreateBlobContainerAsync"/> operation creates a new /// container under the specified account. If the container with the /// same name already exists, the operation fails. /// /// For more information, see <see href="https://docs.microsoft.com/rest/api/storageservices/create-container"/>. /// </summary> /// <param name="containerName"> /// The name of the container to create. /// </param> /// <param name="publicAccessType"> /// Optionally specifies whether data in the container may be accessed /// publicly and the level of access. <see cref="PublicAccessType.Container"/> /// specifies full public read access for container and blob data. /// Clients can enumerate blobs within the container via anonymous /// request, but cannot enumerate containers within the storage /// account. <see cref="PublicAccessType.Blob"/> specifies public /// read access for blobs. Blob data within this container can be /// read via anonymous request, but container data is not available. /// Clients cannot enumerate blobs within the container via anonymous /// request. If this parameter is null, container data is private to /// the account owner. /// </param> /// <param name="metadata"> /// Optional custom metadata to set for this container. /// </param> /// <param name="cancellationToken"> /// Optional <see cref="CancellationToken"/> to propagate /// notifications that the operation should be cancelled. /// </param> /// <returns> /// A <see cref="Task{Response{BlobContainerClient}}"/> referencing the /// newly created container. /// </returns> /// <remarks> /// A <see cref="StorageRequestFailedException"/> will be thrown if /// a failure occurs. /// </remarks> public virtual async Task <Response <BlobContainerClient> > CreateBlobContainerAsync( string containerName, PublicAccessType?publicAccessType = default, Metadata metadata = default, CancellationToken cancellationToken = default) { var container = this.GetBlobContainerClient(containerName); var response = await container.CreateAsync(publicAccessType, metadata, cancellationToken).ConfigureAwait(false); return(new Response <BlobContainerClient>(response.GetRawResponse(), container)); }
public IDisposable GetNewContainer( out BlobContainerClient container, BlobServiceClient service = default, string containerName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default) { containerName ??= this.GetNewContainerName(); service ??= this.GetServiceClient_SharedKey(); container = this.InstrumentClient(service.GetBlobContainerClient(containerName)); return(new DisposingContainer( container, metadata ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase), publicAccessType ?? PublicAccessType.Container)); }
internal ContainerPropertiesInternal(DateTimeOffset lastModified, string etag, LeaseStatus?leaseStatus, LeaseState?leaseState, LeaseDurationType?leaseDuration, PublicAccessType?publicAccess, bool?hasImmutabilityPolicy, bool?hasLegalHold, string defaultEncryptionScope, bool?preventEncryptionScopeOverride, DateTimeOffset?deletedTime, int?remainingRetentionDays) { LastModified = lastModified; Etag = etag; LeaseStatus = leaseStatus; LeaseState = leaseState; LeaseDuration = leaseDuration; PublicAccess = publicAccess; HasImmutabilityPolicy = hasImmutabilityPolicy; HasLegalHold = hasLegalHold; DefaultEncryptionScope = defaultEncryptionScope; PreventEncryptionScopeOverride = preventEncryptionScopeOverride; DeletedTime = deletedTime; RemainingRetentionDays = remainingRetentionDays; }
public static IDisposable GetNewContainer( out BlobContainerClient container, BlobServiceClient service = default, string containerName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default) { containerName = containerName ?? TestHelper.GetNewContainerName(); service = service ?? GetServiceClient_SharedKey(); var result = new DisposingContainer(service.GetBlobContainerClient(containerName), metadata ?? new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase), publicAccessType ?? PublicAccessType.Container); container = result.ContainerClient; return(result); }
public static async Task <DisposingFileSystem> GetNewFileSystem( this DataLakeClientBuilder clientBuilder, DataLakeServiceClient service = default, string fileSystemName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default, bool premium = default, bool hnsEnabled = true) { fileSystemName ??= clientBuilder.GetNewFileSystemName(); service ??= hnsEnabled?clientBuilder.GetServiceClient_Hns() : clientBuilder.GetServiceClient_NonHns(); if (publicAccessType == default) { publicAccessType = premium ? PublicAccessType.None : PublicAccessType.FileSystem; } DataLakeFileSystemClient fileSystem = clientBuilder.AzureCoreRecordedTestBase.InstrumentClient(service.GetFileSystemClient(fileSystemName)); // due to a service issue, if the initial container creation request times out, subsequent requests // can return a ContainerAlreadyExists code even though the container doesn't really exist. // we delay until after the service cache timeout and then attempt to create the container one more time. // If this attempt still fails, we mark the test as inconclusive. // TODO Remove this handling after the service bug is fixed https://github.com/Azure/azure-sdk-for-net/issues/9399 try { await StorageTestBase <DataLakeTestEnvironment> .RetryAsync( clientBuilder.AzureCoreRecordedTestBase.Recording.Mode, async() => await fileSystem.CreateAsync(metadata: metadata, publicAccessType: publicAccessType.Value), ex => ex.ErrorCode == Blobs.Models.BlobErrorCode.ContainerAlreadyExists, retryDelay : TestConstants.DataLakeRetryDelay, retryAttempts : 1); } catch (RequestFailedException storageRequestFailedException) when(storageRequestFailedException.ErrorCode == Blobs.Models.BlobErrorCode.ContainerAlreadyExists) { // if we still get this error after retrying, mark the test as inconclusive TestContext.Out.WriteLine( $"{TestContext.CurrentContext.Test.Name} is inconclusive due to hitting " + $"the DataLake service bug described in https://github.com/Azure/azure-sdk-for-net/issues/9399"); Assert.Inconclusive(); // passing the message in Inconclusive call doesn't show up in Console output. } return(new DisposingFileSystem(fileSystem)); }
public async Task <DisposingContainer> GetTestContainerAsync( BlobServiceClient service = default, string containerName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default, bool premium = default) { containerName ??= GetNewContainerName(); service ??= GetServiceClient_SharedKey(); if (publicAccessType == default) { publicAccessType = premium ? PublicAccessType.None : PublicAccessType.BlobContainer; } BlobContainerClient container = InstrumentClient(service.GetBlobContainerClient(containerName)); await container.CreateAsync(metadata : metadata, publicAccessType : publicAccessType.Value); return(new DisposingContainer(container)); }
/// <summary> /// Creates a new FileSystemProperties instance for mocking. /// </summary> public static FileSystemProperties FileSystemProperties( DateTimeOffset lastModified, LeaseStatus?leaseStatus, LeaseState?leaseState, LeaseDurationType?leaseDuration, PublicAccessType?publicAccess, bool?hasImmutabilityPolicy, bool?hasLegalHold, ETag eTag) => new FileSystemProperties() { LastModified = lastModified, LeaseStatus = leaseStatus, LeaseState = leaseState, LeaseDuration = leaseDuration, PublicAccess = publicAccess, HasImmutabilityPolicy = hasImmutabilityPolicy, HasLegalHold = hasLegalHold, ETag = eTag };
public static async Task <DisposingContainer> GetTestContainerAsync( this BlobsClientBuilder clientBuilder, BlobServiceClient service = default, string containerName = default, IDictionary <string, string> metadata = default, PublicAccessType?publicAccessType = default, bool premium = default) { containerName ??= clientBuilder.GetNewContainerName(); service ??= clientBuilder.GetServiceClient_SharedKey(); if (publicAccessType == default) { publicAccessType = premium ? PublicAccessType.None : PublicAccessType.BlobContainer; } BlobContainerClient container = clientBuilder.AzureCoreRecordedTestBase.InstrumentClient(service.GetBlobContainerClient(containerName)); await container.CreateIfNotExistsAsync(metadata : metadata, publicAccessType : publicAccessType.Value); return(new DisposingContainer(container)); }
public static BlobContainerProperties BlobContainerProperties( DateTimeOffset lastModified, ETag eTag, LeaseStatus?leaseStatus, LeaseState?leaseState, LeaseDurationType?leaseDuration, PublicAccessType?publicAccess, bool?hasImmutabilityPolicy, bool?hasLegalHold, IDictionary <string, string> metadata) => new BlobContainerProperties() { LastModified = lastModified, ETag = eTag, LeaseState = leaseState, LeaseDuration = leaseDuration, PublicAccess = publicAccess, LeaseStatus = leaseStatus, HasLegalHold = hasLegalHold, Metadata = metadata, HasImmutabilityPolicy = hasImmutabilityPolicy, };