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

PermissionEffect type conflict #26

Closed
kl5331 opened this issue Nov 9, 2019 · 5 comments
Closed

PermissionEffect type conflict #26

kl5331 opened this issue Nov 9, 2019 · 5 comments

Comments

@kl5331
Copy link

kl5331 commented Nov 9, 2019

In most of your examples, I see "effect: 'allow'" when creating a new permission. I.E

store
  .addPermissionToRole(Role.CUSTOMER, {
    id: 'CustomerCreatePostPolicy',
    effect: 'allow',
    resource: 'posts',
    action: 'create',
    condition: {
      stringEquals: {
        forAllValues: {
          bodyAttributes: ['title', 'content']
        }
      }
    }
  })

But when I'm coding, TypeScript gives an error since I am not using PermissionEffect.allow. I have created a working database interface(dynamodb) but it relies on strings mostly. Is there a way to add policies with "effect: string"?

@SylvainEstevez
Copy link
Collaborator

Hi @kl5331, the only two possible values for effect are allow or deny. Any other value would not be understood by the condition evaluator hence why the type is forced to this enum.
I’m not sure what you are trying to do? Are you using the memory store with DynamoDB behind it?

@SylvainEstevez
Copy link
Collaborator

Also, which version of typescript are you using?

@kl5331
Copy link
Author

kl5331 commented Nov 9, 2019

Thanks for the quick reply! Yes, I am using the memory store with DDB behind it. The version is Version 3.6.3. One solution I was thinking was creating an interface that accepts the DynamoDB data(a policy) and convert the effect:"allow" (because everything is stored as a string, number, object, etc in Dynamo) to effect:PermissionEffect.allow.

Is that the best route?

@SylvainEstevez
Copy link
Collaborator

I can't think of a better way without writing your own class @kl5331. One question for you: is your dynamoDB driver synchronous? I'm surprised to see that you're connecting to a database with the MemoryStore since all of its methods are synchronous.

@kl5331
Copy link
Author

kl5331 commented Nov 27, 2019

Sorry for the late reply. I'm pretty new to just about everything so I'm not sure what synchronous entails. Most of my dynamoDB calls(policies for example) are async/await calls that are then stored in their respective type. Also, I just tested the effect and it does in fact work as you stated. Must have been a mishap on my end. Thanks again for the quick response!

@kl5331 kl5331 closed this as completed Nov 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants