Mediate.Rbac.Coverage (mediate_rbac v0.1.0)

Copy Markdown View Source

Declared-fact coverage for a policy: every column its rules read is a declared fact. check/1 builds the rule of every protected schema for every operation the role table names, and applies it to the schema. Then it walks the query the rule became, subqueries among them, and collects every field reference by source schema. A column counts as declared in one of these cases:

  • the schema's fact names it as the column, the subject, or the object
  • the schema's relationship names it as the subject, the object, or an attribute
  • it is the primary key
  • it is the foreign key of a relation some protected schema carries, through the closure of what the carried schemas carry in turn

The walk cannot enter a fragment, so a fragment fails as the finding {:fragment, text}.

Summary

Types

An undeclared read: the schema and the column, or a fragment's text.

Functions

Ok, or the undeclared reads, sorted and without repeats.

check/1, but raises with every finding in the message.

Every read the policy's rules make, as findings, before the removal of the declared ones.

Every undeclared read across the policy's rules.

Types

finding()

@type finding() :: {module(), atom()} | {:fragment, String.t()}

An undeclared read: the schema and the column, or a fragment's text.

Functions

check(policy)

@spec check(Mediate.Rbac.Policy.t()) :: :ok | {:error, [finding()]}

Ok, or the undeclared reads, sorted and without repeats.

check!(policy)

@spec check!(Mediate.Rbac.Policy.t()) :: :ok

check/1, but raises with every finding in the message.

reads(policy)

@spec reads(Mediate.Rbac.Policy.t()) :: [finding()]

Every read the policy's rules make, as findings, before the removal of the declared ones.

undeclared(policy)

@spec undeclared(Mediate.Rbac.Policy.t()) :: [finding()]

Every undeclared read across the policy's rules.