Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private async ConfigureDiagnosticSettings(params: any, util: any) {
let accountName: string;
let accountKey: string;
//Get blob storage properties
accountName = params["storageAccountName"].value;
const storageUtils = new StorageUtils(this._ctx);
accountKey = await storageUtils.get_primary_key(accountName, await util.resource_group())
const credentials = new SharedKeyCredential(accountName, accountKey);
const pipeline = StorageURL.newPipeline(credentials, {
// Enable logger when debugging
// logger: new ConsoleHttpPipelineLogger(HttpPipelineLogLevel.INFO)
});
const blobPrimaryURL = `https://${accountName}.blob.core.windows.net/`;
var serviceURL = new ServiceURL(blobPrimaryURL, pipeline)
const serviceProperties = await serviceURL.getProperties(Aborter.none);
//Get Bake variables for diagnostic settings. Default to "true" (enabled) and 10 days data retention.
let blobDiagnosticHourlyMetricsEnabled: string = await util.variable("blobDiagnosticHourlyMetricsEnabled") || "true"
let blobDiagnosticHourlyMetricsRetentionDays = await util.variable("blobDiagnosticHourlyMetricsRetentionDays") || 10
let blobDiagnosticMinuteMetricsEnabled: string = await util.variable("blobDiagnosticMinuteMetricsEnabled") || "true"
let blobDiagnosticMinuteMetricsRetentionDays = await util.variable("blobDiagnosticMinuteMetricsRetentionDays") || 10
let blobDiagnosticLoggingEnabled: string = await util.variable("blobDiagnosticLoggingEnabled") || "true"
let blobDiagnosticLoggingRetentionDays = await util.variable("blobDiagnosticLoggingRetentionDays") || 10
//Workaround due to issues using boolean data type for Bake variables
var boolBlobDiagnosticHourlyMetricsEnabled: boolean = (blobDiagnosticHourlyMetricsEnabled == "true") ? true : false;
var boolBlobDiagnosticMinuteMetricsEnabled: boolean = (blobDiagnosticMinuteMetricsEnabled == "true") ? true : false;
var boolBlobDiagnosticLoggingEnabled: boolean = (blobDiagnosticLoggingEnabled == "true") ? true : false;
//Debug logging of Bake variables
this._logger.debug("blobDiagnosticHourlyMetricsEnabled:" + boolBlobDiagnosticHourlyMetricsEnabled)
async function showBlobNames(aborter, containerURL) {
let marker = undefined;
do {
const listBlobsResponse = await containerURL.listBlobFlatSegment(Aborter.none, marker);
marker = listBlobsResponse.nextMarker;
for (const blob of listBlobsResponse.segment.blobItems) {
console.log(` - ${ blob.name }`);
}
} while (marker);
}
export const loadFile = ({containerUrl}) => async key => {
const blobURL = BlobURL.fromContainerURL(
containerUrl, key);
const downloadBlockBlobResponse =
await blobURL.download(Aborter.none, 0);
return downloadBlockBlobResponse
.readableStreamBody
.read(content.length)
.toString();
};
public async writeText(blobName: string, content: string | Buffer) {
const blockBlobURL = this.getBlockBlobURL(blobName);
await blockBlobURL.upload(
Aborter.none,
content,
content.length,
);
}
export const createFile = ({containerUrl}) => async (key, content) => {
const blobURL = BlobURL.fromContainerURL(containerURL, key);
const blockBlobURL = BlockBlobURL.fromBlobURL(blobURL);
await blockBlobURL.upload(
Aborter.none,
content,
content.length
);
};
public async read(opts: ReadBlobOptions): Promise {
const containerURL = ContainerURL.fromServiceURL(this.service, opts.container);
const blobURL = BlobURL.fromContainerURL(containerURL, opts.path);
const stream = await blobURL.download(Aborter.none, 0)
return stream.readableStreamBody
}
}
public async listContainers() {
this.checkInitialization();
const result: string[] = [];
let marker;
do {
const listContainersResponse = await this.getServiceURL().listContainersSegment(
Aborter.none,
marker,
);
marker = listContainersResponse.nextMarker;
for (const container of listContainersResponse.containerItems) {
result.push(container.name);
}
} while (marker);
return result;
}
read: boolBlobDiagnosticLoggingEnabled,
retentionPolicy: {
days: blobDiagnosticLoggingRetentionDays,
enabled: true
},
version: "2.0",
write: boolBlobDiagnosticLoggingEnabled
};
//Workaround for bug in Azure Javascript SDK. https://github.com/Azure/azure-sdk-for-js/issues/2909
if (!serviceProperties.cors) {
serviceProperties.cors = undefined;
}
//Post blob service properties back to Azure
await serviceURL.setProperties(Aborter.none, serviceProperties);
}
}