Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SAS Key generation service #46

Open
DimosthenisK opened this issue Oct 1, 2019 · 2 comments
Open

Add SAS Key generation service #46

DimosthenisK opened this issue Oct 1, 2019 · 2 comments

Comments

@DimosthenisK
Copy link

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

Currently, you pass the SAS key during the module registering with the withConfig method. This is undesirable, as they keys expire and you might want to change them or configure them better.

Expected behavior

There should be an option to generate the SAS key via the module, using an account name and key.

Minimal reproduction of the problem with instructions

What is the motivation / use case for changing the behavior?

SAS keys expire and there should be more control over them.

Environment


Nest version: 6.7.2

 
For Tooling issues:
- Node version: 12.10  
- Platform: Windows 

Others:

@DimosthenisK
Copy link
Author

I have already created a quick service like that, and you are free to modify it and add it to the core module. It currently looks like this:

import { Injectable } from '@nestjs/common';
import * as azure from '@azure/storage-blob';
import { ConfigService } from '../config/config.service';
import {
    AccountSASServices,
    AccountSASResourceTypes,
} from '@azure/storage-blob';

@Injectable()
export class AzureSASService {
    private credential: azure.SharedKeyCredential;
    constructor(private readonly configService: ConfigService) {
        this.credential = new azure.SharedKeyCredential(
            this.configService.get('AZURE_STORAGE_ACCOUNT'),
            this.configService.get('AZURE_STORAGE_ACCOUNT_KEY')
        );
    }
    getNewSASKey() { //We should probably add a config object here
        let expiryTime = new Date();
        let startTime = new Date();
        expiryTime.setMonth(new Date().getMonth() + 1);
        startTime.setFullYear(startTime.getFullYear() - 10);
        return (
            '?' +
            azure
                .generateAccountSASQueryParameters(
                    {
                        expiryTime,
                        services: AccountSASServices.parse('b').toString(),
                        resourceTypes: AccountSASResourceTypes.parse(
                            'sco'
                        ).toString(),
                        permissions: azure.ContainerSASPermissions.parse(
                            'racwdl'
                        ).toString(),
                        startTime,
                        ipRange: { start: '0.0.0.0', end: '255.255.255.255' },
                        protocol: azure.SASProtocol.HTTPSandHTTP,
                        version: '2018-11-09',
                    },
                    this.credential
                )
                .toString()
        );
    }
}

@Roytangrb
Copy link

May I ask if there is any update on this issue.

Granting access to resources using SAS signed url is pretty common use case of Azure Blob Storage. Sometimes we don't want to use our server bandwidth for download and upload actions. The server might only take care of access management.

I could help with drafting the feature and raise a PR if help is wanted.

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

No branches or pull requests

3 participants