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

There should be a way to re-hydrate an instance of BlobSASPermissions from JSON #9714

Closed
mocasio-MSFT opened this issue Jun 25, 2020 · 4 comments · Fixed by #12850
Closed
Assignees
Labels
APIChange This PR contains an addition or change to the API signature and must be reviewed by an architect. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. Storage Storage Service (Queues, Blobs, Files)

Comments

@mocasio-MSFT
Copy link

Is your feature request related to a problem? Please describe.
Our current solution stores an instance of BlobSasPermissions to CosmosDB in the form of JSON. See an example below:

{
    "read": true,
    "add": false,
    "create": false,
    "write": true,
    "delete": false
}

The reason this happens is because we store it as part of an object hierarchy that looks like this:

MainRequestObject:
    - BlobSasPermissionsObject

We run into an issue when calling generateBlobSASQueryParameters with a re-hydrated version of BlobSasPermissions from this JSON format as it loses it's toString() implementation in the process (and there is no way to instantiate BlobSasPermission from anything other than the simple permission string format eg. 'rwx'). So passing our re-hydrated BlobSasPermissions causes generateBlobSASQueryParameters to throw an Invalid Permissions exception.

Describe the solution you'd like
It would be ideal for us to be able to call generateBlobSASQueryParameters with the following:

const permission = JSON.parse("{
    "read": true,
    "add": false,
    "create": false,
    "write": true,
    "delete": false
}") as BlobSasPermission;

Or even:

BlobSasPermission.parse(jsonString);

Describe alternatives you've considered
Since we want to retain our database structure (for backwards compatibility), it is not desirable to change how we serialize BlobSasPermission. Right now we just recreate the BlobSasPermission.toString method in our codebase to work with an external object (remember that obj below does not have toString() since it was re-hydrated from JSON):

private getSasPermissionsString (obj: BlobSASPermissions): string {
        const permissions: string[] = [];
        if (obj.read) {
            permissions.push('r');
        }
        if (obj.add) {
            permissions.push('a');
        }
        if (obj.create) {
            permissions.push('c');
        }
        if (obj.write) {
            permissions.push('w');
        }
        if (obj.delete) {
            permissions.push('d');
        }
        return permissions.join('');
    }

Additional context
None.

@ghost ghost added needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. customer-reported Issues that are reported by GitHub users external to the Azure organization. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jun 25, 2020
@ramya-rao-a ramya-rao-a added Client This issue points to a problem in the data-plane of the library. Storage Storage Service (Queues, Blobs, Files) labels Jun 25, 2020
@ghost ghost removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Jun 25, 2020
@ghost
Copy link

ghost commented Jun 25, 2020

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @xgithubtriage.

@XiaoningLiu XiaoningLiu added the feature-request This issue requires a new behavior in the product in order be resolved. label Jun 29, 2020
@XiaoningLiu
Copy link
Member

Thanks for feedback. Mark this as feature request and will be triaged in following release schedule.

@XiaoningLiu XiaoningLiu added enhancement and removed question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Jul 15, 2020
@ramya-rao-a ramya-rao-a added this to the Backlog milestone Jul 19, 2020
@ljian3377 ljian3377 added the cross-language alignment mark issues need to be aligned across different languages label Oct 21, 2020
@ljian3377 ljian3377 modified the milestones: Backlog, [2020] December Nov 3, 2020
@ljian3377 ljian3377 added the APIChange This PR contains an addition or change to the API signature and must be reviewed by an architect. label Nov 6, 2020
@ljian3377
Copy link
Member

Probably we should have made the toString() function static.

Then you would be able to call BlobSASPermissions.toString(permissionLikeObject) to get the permission string, and then call BlobSASPermissions.parse(permissionString) to get an instance of BlobSASPermissions.

@ljian3377
Copy link
Member

from(PermissionLikeObject): BlobSASPermissions

@ljian3377 ljian3377 removed the cross-language alignment mark issues need to be aligned across different languages label Dec 2, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
APIChange This PR contains an addition or change to the API signature and must be reviewed by an architect. Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. feature-request This issue requires a new behavior in the product in order be resolved. Storage Storage Service (Queues, Blobs, Files)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants