Skip to content

Feature/policy classes#891

Merged
bplatz merged 7 commits intomainfrom
feature/policy-classes
Sep 13, 2024
Merged

Feature/policy classes#891
bplatz merged 7 commits intomainfrom
feature/policy-classes

Conversation

@bplatz
Copy link
Contributor

@bplatz bplatz commented Sep 13, 2024

Adds two features needed for Nexus (and generally useful)

  1. Adds wrap-class-policy API to the existing wrap-policy and wrap-identity-policy for enforcing policy on a db. This addition allows you to pass one or more class IRIs to enforce policy, which will query the db for policies of those class(es) and apply them. This feature provides a similar capability to v2's 'roles' option.
  2. Allows new policy features to be utilized from the query-connection API which Nexus primarily uses. In the 'opts' for a query, you can now include the following keys:
    a) policyClass - which performs the feature as described in (1) above.
    b) policy - which allows you to pass in any json-ld policy definitions and will call wrap-policy on your behalf
    c) policyValues - which allows you to pass in a values map that policy enforcement will inject into the policy queries (via the policy query's values key).

*note - in the case of policy and policyClass, json-ld/expand will be called on them utilizing the query's @context. In the process added the expansion to the existing did option which previously was never attempted to expand.

@bplatz bplatz requested a review from a team September 13, 2024 14:47
Copy link
Contributor

@zonotope zonotope left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥘

#?(:clj (set! *warn-on-reflection* true))

(defprotocol Restrictable
(wrap-policy [db policy-rules values-map])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification of this protocol

{:status 400
:error :db/invalid-values-map}))))

(defn expanded?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but I would prefer more robust code paths where we only call this function with data we already know is expanded. That has its own benefits, and this method introduces a dependency on the proprietary :idx key and limits our flexibility with respect to expansion going forward. Making the code paths more robust is probably a much larger refactor, so I'm ok with this for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I ran into this issue when using with fluree/server so added a quick fix.

I just fixed it up property and removed this.

@bplatz bplatz merged commit 672b16c into main Sep 13, 2024
@bplatz bplatz deleted the feature/policy-classes branch September 13, 2024 18:40
@bplatz bplatz mentioned this pull request Sep 20, 2024
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

Successfully merging this pull request may close these issues.

2 participants