Skip to content
This repository has been archived by the owner on May 2, 2020. It is now read-only.

support for non anonymous blob containers #2

Open
noopkat opened this issue Sep 28, 2017 · 1 comment
Open

support for non anonymous blob containers #2

noopkat opened this issue Sep 28, 2017 · 1 comment

Comments

@noopkat
Copy link
Collaborator

noopkat commented Sep 28, 2017

Having non anonymous sources for firmware files would be a common use case.

This could potentially be supported with zero changes to the public API interface.

Some rough pseudo code to give you an idea of a suggested approach:

// from lib/downloader.js

function downloadFirmware(uriToFile, options = {}) {
    const parsedUri = url.parse(uriToFile);

    const accountName = parsedUri.hostname.split('.')[0].replace('-secondary', '');
    // it's too late at night for wrestling with javascript date formatting T^T
    const canonicalizedHeaders = ['x-ms-date:Fri, 11 Oct 2017 21:49:13 GMT', 'x-ms-version:2009-09-19'].join('\n');
    const canonicalizedResource = `/${accountname}${parsedUri.path.replace(/\/$/, '')}`;
    const toSign = `GET\n\n\n\n\n\n\n\n\n\n\n\n${canonicalizedHeaders}\n${canonicalizedResource}`;
    const signed = someFancyHmacSigningFunction(toSign);
    const signature = toBase64(signed);

    var requestInfo = {
        hostname: parsedUri.hostname,
        port: 443,
        path: parsedUri.path,
        method: 'GET',
        headers: {
           Authorization: `SharedKey ${accountName}:${signature}`
        },
        //disable session caching
        agent: new https.Agent({
            maxCachedSessions: 0
        })
    };
...

bitmoji

@jsturtevant
Copy link
Owner

This looks great. There is a similar implementation you can borrow from at: https://github.com/Azure-Samples/functions-node-sas-token

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants