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
});
asStorage
Configures the storage account as a regular storage account with optional features.
storageBuilder.asStorage({
// StorageFeatureBuilderType properties
});
asStaticWebStorage
Configures the storage account as a static web storage account.
storageBuilder.asStaticWebStorage();
withCdn
Sets the CDN properties for the storage account.
storageBuilder.withCdn({
// StorageCdnType properties
});
withContainer
Adds a container to the storage account.
storageBuilder.withContainer({
name: 'myContainer',
// other ContainerProps properties
});
withQueue
Adds a queue to the storage account.
storageBuilder.withQueue('myQueue');
withFileShare
Adds a file share to the storage account.
storageBuilder.withFileShare('myFileShare');
withPolicies
Sets the policies for the storage account.
storageBuilder.withPolicies({
// StoragePolicyType properties
});
withNetwork
Sets the network properties for the storage account.
storageBuilder.withNetwork({
// StorageNetworkType properties
});
lock
Enables or disables locking of the storage account.
storageBuilder.lock(true);
buildStorage
Creates the storage account with the specified configurations.
This method is called internally by the build
method and is not typically called directly.
buildCDN
Configures the CDN for the storage account.
This method is called internally by the build
method and is not typically called directly.
build
Builds 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.