Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private createBlobService(storageAccountOrConnectionString: string, storageAccessKey: string, host: any): BlobServiceAsync {
if (!storageAccountOrConnectionString) {
throw new Error('The storageAccountOrConnectionString parameter is required.');
}
const blobService: azure.BlobService = azure.createBlobService(
storageAccountOrConnectionString,
storageAccessKey,
host
).withFilter(new azure.LinearRetryPolicyFilter(5, 500));
// create BlobServiceAsync by using denodeify to create promise wrappers around cb functions
// tslint:disable-next-line:prefer-object-spread
return Object.assign(blobService as any, {
createContainerIfNotExistsAsync: this.denodeify(blobService, blobService.createContainerIfNotExists),
deleteContainerIfExistsAsync: this.denodeify(blobService, blobService.deleteContainerIfExists),
createBlockBlobFromTextAsync: this.denodeify(blobService, blobService.createBlockBlobFromText),
getBlobMetadataAsync: this.denodeify(blobService, blobService.getBlobMetadata),
setBlobMetadataAsync: this.denodeify(blobService, blobService.setBlobMetadata),
getBlobPropertiesAsync: this.denodeify(blobService, blobService.getBlobProperties),
setBlobPropertiesAsync: this.denodeify(blobService, blobService.setBlobProperties),
getBlobToTextAsync: this.denodeify(blobService, blobService.getBlobToText),
deleteBlobIfExistsAsync: this.denodeify(blobService, blobService.deleteBlobIfExists),
listBlobsSegmentedWithPrefixAsync: this.denodeify(blobService, blobService.listBlobsSegmentedWithPrefix),
listBlobDirectoriesSegmentedWithPrefixAsync: this.denodeify(blobService, blobService.listBlobDirectoriesSegmentedWithPrefix)
private createBlobService(storageAccountOrConnectionString: string, storageAccessKey: string, host: any): BlobServiceAsync {
if (!storageAccountOrConnectionString) {
throw new Error('The storageAccountOrConnectionString parameter is required.');
}
const blobService: azure.BlobService = azure.createBlobService(
storageAccountOrConnectionString,
storageAccessKey,
host
).withFilter(new azure.LinearRetryPolicyFilter(5, 500));
// create BlobServiceAsync by using denodeify to create promise wrappers around cb functions
return {
createBlockBlobFromTextAsync: this.denodeify(blobService, blobService.createBlockBlobFromText),
createContainerIfNotExistsAsync: this.denodeify(blobService, blobService.createContainerIfNotExists),
deleteBlobIfExistsAsync: this.denodeify(blobService, blobService.deleteBlobIfExists),
deleteContainerIfExistsAsync: this.denodeify(blobService, blobService.deleteContainerIfExists),
doesBlobExistAsync: this.denodeify(blobService, blobService.doesBlobExist),
getBlobMetadataAsync: this.denodeify(blobService, blobService.getBlobMetadata),
getBlobToTextAsync: this.denodeify(blobService, blobService.getBlobToText)
} as any;
}
createBlobService(storageAccountOrConnectionString, storageAccessKey, host) {
if (!storageAccountOrConnectionString) {
throw new Error('The storageAccountOrConnectionString parameter is required.');
}
const blobService = azure.createBlobService(storageAccountOrConnectionString, storageAccessKey, host).withFilter(new azure.LinearRetryPolicyFilter(5, 500));
// create BlobServiceAsync by using denodeify to create promise wrappers around cb functions
return {
createContainerIfNotExistsAsync: this.denodeify(blobService, blobService.createContainerIfNotExists),
deleteContainerIfExistsAsync: this.denodeify(blobService, blobService.deleteContainerIfExists),
createBlockBlobFromTextAsync: this.denodeify(blobService, blobService.createBlockBlobFromText),
getBlobMetadataAsync: this.denodeify(blobService, blobService.getBlobMetadata),
getBlobToTextAsync: this.denodeify(blobService, blobService.getBlobToText),
deleteBlobIfExistsAsync: this.denodeify(blobService, blobService.deleteBlobIfExists)
};
}
// turn a cb based azure method into a Promisified one
createBlobService(storageAccountOrConnectionString, storageAccessKey, host) {
if (!storageAccountOrConnectionString) {
throw new Error('The storageAccountOrConnectionString parameter is required.');
}
const blobService = azure.createBlobService(storageAccountOrConnectionString, storageAccessKey, host).withFilter(new azure.LinearRetryPolicyFilter(5, 500));
// create BlobServiceAsync by using denodeify to create promise wrappers around cb functions
return Object.assign(blobService, {
createContainerIfNotExistsAsync: this.denodeify(blobService, blobService.createContainerIfNotExists),
deleteContainerIfExistsAsync: this.denodeify(blobService, blobService.deleteContainerIfExists),
createBlockBlobFromTextAsync: this.denodeify(blobService, blobService.createBlockBlobFromText),
getBlobMetadataAsync: this.denodeify(blobService, blobService.getBlobMetadata),
setBlobMetadataAsync: this.denodeify(blobService, blobService.setBlobMetadata),
getBlobPropertiesAsync: this.denodeify(blobService, blobService.getBlobProperties),
setBlobPropertiesAsync: this.denodeify(blobService, blobService.setBlobProperties),
getBlobToTextAsync: this.denodeify(blobService, blobService.getBlobToText),
deleteBlobIfExistsAsync: this.denodeify(blobService, blobService.deleteBlobIfExists),
listBlobsSegmentedWithPrefixAsync: this.denodeify(blobService, blobService.listBlobsSegmentedWithPrefix),
listBlobDirectoriesSegmentedWithPrefixAsync: this.denodeify(blobService, blobService['listBlobDirectoriesSegmentedWithPrefix'])
});
}
// turn a cb based azure method into a Promisified one
createFolderAndClearPromise.then(function () {
return uploadFileToAzureCdn(blobService, options, loggerCallback, destFileName, sourceFile, metadata)
}).then(function () {
eachCallback();
}).catch(function (error) {
eachCallback(error);
});
}
}, function (err) {
cb(err);
});
};
module.exports.filters = {
ExponentialRetryPolicyFilter: new azure.ExponentialRetryPolicyFilter(),
LinearRetryPolicyFilter : new azure.LinearRetryPolicyFilter(),
RetryPolicyFilter : new azure.RetryPolicyFilter()
}