How to use the @azure/storage-blob.SharedKeyCredential function in @azure/storage-blob

To help you get started, we’ve selected a few @azure/storage-blob examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-iot-sdk-node / device / samples / upload_to_blob_v12.js View on Github external
async function uploadToBlob(client) {
  // OUR CODE
  const content = "hello";
  const blobName = "newblob" + new Date().getTime();
  const containerName = `newcontainer${new Date().getTime()}`;
  
  let blobInfo = await client.getBlobSharedAccessSignature(blobName);
  if (!blobInfo) { 
    throw new errors.ArgumentError('Invalid upload parameters');
  }
  
  // STORAGE BLOB CODE
  const sharedKeyCredential = new SharedKeyCredential(account, accountKey);
  let i = 1;
  for await (const container of blobServiceClient.listContainers()) {
    console.log(`Container ${i++}: ${container.name}`);
  }
  const blobServiceClient = new BlobServiceClient(
    // When using AnonymousCredential, following url should include a valid SAS or support public access
    `https://${account}.blob.core.windows.net`,
    sharedKeyCredential
    );
    
    
    // Create a container
    const containerClient = blobServiceClient.getContainerClient(containerName);
    const blobClient = containerClient.getBlobClient(blobName);
    const blockBlobClient = blobClient.getBlockBlobClient();
github HomecareHomebase / azure-bake / ingredient / ingredient-storage / src / plugin.ts View on Github external
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
github Azure / azure-sdk-for-js / common / smoke-test / BlobStorage.ts View on Github external
static async Run() {
    console.log(BlobStorage.dedent`
        ------------------------
        Storage - Blobs
        ------------------------
        1) Upload Blob
        2) Delete Blob (Clean up the resource)
        `);

    const account = process.env["STORAGE_ACCOUNT_NAME"] || "";
    const accountKey = process.env["STORAGE_ACCOUNT_KEY"] || "";
    const containerName = "mycontainer";
    BlobStorage.blobName = `JSNewBlob-${uuidv1()}.txt`;

    const credential = new SharedKeyCredential(account, accountKey);
    const serviceClient = new BlobServiceClient(
      `https://${account}.blob.core.windows.net`,
      credential
    );
    BlobStorage.ContainerClient = serviceClient.getContainerClient(containerName);

    //Ensure that the blob does not already existis
    try {
      await BlobStorage.CleanUp();
    } catch { }

    await BlobStorage.UploadBlob();
    await BlobStorage.CleanUp();
  }
github Azure-Samples / azure-storage-js-v10-quickstart / v10 / index.js View on Github external
async function execute() {

    const containerName = "demo";
    const blobName = "quickstart.txt";
    const content = "Hello Node SDK";
    const localFilePath = "../readme.md";

    const credentials = new SharedKeyCredential(STORAGE_ACCOUNT_NAME, ACCOUNT_ACCESS_KEY);
    const pipeline = StorageURL.newPipeline(credentials);
    const serviceURL = new ServiceURL(`https://${STORAGE_ACCOUNT_NAME}.blob.core.windows.net`, pipeline);
    
    const containerURL = ContainerURL.fromServiceURL(serviceURL, containerName);
    const blockBlobURL = BlockBlobURL.fromContainerURL(containerURL, blobName);
    
    const aborter = Aborter.timeout(30 * ONE_MINUTE);

    await containerURL.create(aborter);
    console.log(`Container: "${containerName}" is created`);

    console.log("Containers:");
    await showContainerNames(aborter, serviceURL);

    await blockBlobURL.upload(aborter, content, content.length);
    console.log(`Blob "${blobName}" is uploaded`);
github serverless / serverless-azure-functions / src / services / azureBlobStorageService.ts View on Github external
public async initialize() {
    if (this.storageCredential) {
      return;
    }
    this.storageCredential = (this.authType === AzureStorageAuthType.SharedKey)
      ?
      new SharedKeyCredential(this.storageAccountName, await this.getKey())
      :
      new TokenCredential(await this.getToken());
  }