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

Convert a JSON object to an Entities type #1066

Open
1 of 2 tasks
muse254 opened this issue Jul 13, 2024 · 6 comments
Open
1 of 2 tasks

Convert a JSON object to an Entities type #1066

muse254 opened this issue Jul 13, 2024 · 6 comments
Labels
feature-request This issue requets a substantial new feature

Comments

@muse254
Copy link

muse254 commented Jul 13, 2024

Category

User level API features/changes

Describe the feature you'd like to request

I have tried to look into the apis provided and can't find a way to convert a JSON dynamically to an Entity.
Say I have the JSON object

{
  "name": "John Doe",
  "age": 55,
  "is_staff": true,
  "contacts": {
    "email": "example@mail.com",
    "phone": 98978
  }
}

I would like to convert this to an Entities type with a function of maybe this signature

impl Entities {
   pub fn from_payload(schema: &Schema, type: &str, payload: &[u8])-> Result<Self>
}

Expected entities representation (might be erroneous)

[
    {
        "uid": {
            "type": "User",
            "id": "..."
        },
        "attrs": {
            "name": "John Doe",
            "age": 55,
            "is_staff": true,
            "contacts": {
                "type": "Contact",
                "id": "444"
            }
        },
        "parents": []
    },
    {
        "uid": {
            "type": "Contact",
            "id": "444"
        },
        "attrs": {
            "email": "example@mail.com",
            "phone": 98978
        },
        "parents": []
    }
]

It's not possible to write an own implementation since entityType is private to the crate consumer once parsed to the Schema type and also we wouldn't want to have different implementations in the wild.

Describe alternatives you've considered

I have tried to look into the apis provided for the Schema, Entities and can't find a way to convert a JSON dynamically to an Entities type.
Also, I haven't found any docs that describe this scenario.

Additional context

No response

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

  • 👋 I may be able to implement this feature request
  • ⚠️ This feature might incur a breaking change
@muse254 muse254 added feature-request This issue requets a substantial new feature pending-triage The cedar maintainers haven't looked at this yet. Automicaly added to all new issues. labels Jul 13, 2024
@muse254 muse254 changed the title Convert a JSON object to an Entity Convert a JSON object to an Entities type Jul 13, 2024
@shaobo-he-aws
Copy link
Contributor

Thank you for your interest in Cedar. We have a JSON format for entities, whose documentation can be found here. Once you specify entities in this format, you should be able to call Entities::from_json_str to get the Rust object.

Note that you may need to translate the JSON objects into Cedar's entity JSON format. We're exploring a solution (issue, rfc) that allows you to annotate the Rust type so that objects of a type can be automatically translated to Entities.

@muse254
Copy link
Author

muse254 commented Jul 14, 2024

Could there be a possibility of making the proposed solution also have inclusion for dynamic generation of Entities for crate consumers who only get to know the schema and object they are parsing at runtime? @shaobo-he-aws
Or maybe a separate followup implementation

@john-h-kastner-aws john-h-kastner-aws added internal-improvement Refactoring, minor performance improvement, or other changes that Cedar users may never notice and removed pending-triage The cedar maintainers haven't looked at this yet. Automicaly added to all new issues. labels Jul 15, 2024
@shaobo-he-aws
Copy link
Contributor

shaobo-he-aws commented Jul 15, 2024

@muse254 Is it possible for you to depend on cedar_policy_validator? It should contain APIs you need to implement such function. In the meanwhile, we will try to make the required APIs to cedar_policy.

@john-h-kastner-aws john-h-kastner-aws added backlog and removed internal-improvement Refactoring, minor performance improvement, or other changes that Cedar users may never notice labels Jul 15, 2024
@cdisselkoen
Copy link
Contributor

(note that cedar_policy_validator is not stable and does not come with semver guarantees)

@muse254
Copy link
Author

muse254 commented Jul 17, 2024

Is it ok for me to start work on this under an experimental feature?

@aaronjeline
Copy link
Contributor

That would be great, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request This issue requets a substantial new feature
Projects
None yet
Development

No branches or pull requests

5 participants