StorageBuilder Class OverviewThe StorageBuilder class is designed to build and configure an Azure Storage Account with specific configurations such as containers, queues, file shares, CDN, network settings, and policies.
Initializes the StorageBuilder with the provided arguments.
const storageBuilder = new StorageBuilder({
name: 'myStorageAccount',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
});
asStorageConfigures the storage account as a regular storage account with optional features.
storageBuilder.asStorage({
// StorageFeatureBuilderType properties
});
asStaticWebStorageConfigures the storage account as a static web storage account.
storageBuilder.asStaticWebStorage();
withCdnSets the CDN properties for the storage account.
storageBuilder.withCdn({
// StorageCdnType properties
});
withContainerAdds a container to the storage account.
storageBuilder.withContainer({
name: 'myContainer',
// other ContainerProps properties
});
withQueueAdds a queue to the storage account.
storageBuilder.withQueue('myQueue');
withFileShareAdds a file share to the storage account.
storageBuilder.withFileShare('myFileShare');
withPoliciesSets the policies for the storage account.
storageBuilder.withPolicies({
// StoragePolicyType properties
});
withNetworkSets the network properties for the storage account.
storageBuilder.withNetwork({
// StorageNetworkType properties
});
lockEnables or disables locking of the storage account.
storageBuilder.lock(true);
buildStorageCreates the storage account with the specified configurations.
This method is called internally by the build method and is not typically called directly.
buildCDNConfigures the CDN for the storage account.
This method is called internally by the build method and is not typically called directly.
buildBuilds the storage account and returns the resource information.
const resourceInfo = storageBuilder.build();
console.log(resourceInfo);
Here is a full example demonstrating how to use the StorageBuilder class:
import StorageBuilder from './Builder/StorageBuilder';
import { StorageBuilderArgs } from './types';
const args: StorageBuilderArgs = {
name: 'myStorageAccount',
group: { resourceGroupName: 'myResourceGroup' },
// other necessary arguments
};
const storageBuilder = new StorageBuilder(args);
storageBuilder
.asStorage({
// StorageFeatureBuilderType properties
})
.withCdn({
// StorageCdnType properties
})
.withContainer({
name: 'myContainer',
// other ContainerProps properties
})
.withQueue('myQueue')
.withFileShare('myFileShare')
.withPolicies({
// StoragePolicyType properties
})
.withNetwork({
// StorageNetworkType properties
})
.lock(true);
const resourceInfo = storageBuilder.build();
console.log(resourceInfo);
This guideline should help developers understand and reuse the methods in the StorageBuilder class effectively.