cedar-policy / cedar

Implementation of the Cedar Policy Language
https://www.cedarpolicy.com
Apache License 2.0
830 stars 71 forks source link

More ergonomic ways of writing Ids #64

Open aaronjeline opened 1 year ago

aaronjeline commented 1 year ago

Category

User level API changes

Describe the feature you'd like to request

It would be nice to have more ergonomic ways of writing down policy and entity ids. Currently you have write them as a string, and then call .parse() on them. For fully static data, this is cumbersome and delays error detection until runtime.

Describe the solution you'd like

One solution here would be to have macros for writing ids. You could image something like:

entityuid!(#r"User::"Alice""#)

Parse rules would be checked at compile time, allowing you skip calling .unwrap or handling the error, and making it compile time error if the ID was invalid.

Describe alternatives you've considered

The current situation is workable.

Additional context

This is somewhat inspired by serde_jsons json! macro.

Is this something that you'd be interested in working on?

cdisselkoen commented 1 year ago

In addition to policy and entity ids, we can also do this for Names in general.

shaobo-he-aws commented 6 months ago

I wrote a prototype in #744, which proposes a different syntax. Instead of having an argument which is the string representation of entity uids, it asks for two argument: an entity type and an eid. The eid is simply a string. This design avoids the nuance around string escaping and provides users a more flexible way to specify eids. For instance, they can use raw string syntax when they need literal backslashes like euid!(Foo, r#"\"#).