Skip to content

Feature Request: Create builtin to construct complex JSON objects #2181

Open
@samgurtman-zz

Description

@samgurtman-zz

Following on from #2168 it would be wonderful if OPA had a reverse walk function to build up JSON objects from sets. This would allow OPA to better service introspection type functionality such as "What things does my API Key give me access to?"

My original thought was expanding walk(x, [path, value]) so that x could be an output rather than just an input, but perhaps it needs to be a new function such as

object := map(path,value)
entitlements := permission_tree {
  permissions[[user_id, entity_type, entity_id, action]] = { ... }
  permission_tree := map([user_id, entity_type, entity_id], action[_])
}

entitlements == {
  "jim": {
    "car" : {
      "jims_suv" : ["drive","service"],
      "bobs_minivan": ["drive"]
    },
    "tea": {
      "green_tea" : ["drink", "brew"],
      "black_tea": ["brew"]
    }
  },
  "bob": {
    "car": {
      "bobs_minivan": ["drive","service"]   
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions