WeaviateEx.RBAC.Permissions (WeaviateEx v0.7.4)

View Source

Builder API for constructing RBAC permissions.

This module provides a fluent API for creating permissions that can be assigned to roles. Each builder function returns either a single Permission struct or a list of Permission structs (when multiple actions are specified).

Examples

# Full access to a collection
Permissions.collections("Article", [:create, :read, :update, :delete])

# Read data from specific tenant
Permissions.data("Article", :read, tenant: "tenant-a")

# Manage all backups
Permissions.backups(:manage)

# Verbose node info
Permissions.nodes(:verbose)

# Multiple permissions for a role
permissions = [
  Permissions.collections("Article", [:read, :update]),
  Permissions.data("Article", [:read, :create]),
  Permissions.cluster()
]

Wildcards

Use :all to create permissions that apply to all resources:

Permissions.collections(:all, :read)  # Read all collections
Permissions.data(:all, :read)         # Read data from all collections
Permissions.users(:all, :read)        # Read all users

Summary

Functions

Create alias permission(s).

Create backups permission.

Create cluster permission.

Create collections permission(s).

Create data permission(s).

Flatten a nested structure of permissions into a single list.

Create groups permission(s) (OIDC groups).

Create nodes permission.

Create replicate permission(s).

Create roles permission(s).

Create tenants permission(s).

Create users permission(s).

Types

actions()

@type actions() :: atom() | [atom()]

collection_or_all()

@type collection_or_all() :: String.t() | :all

name_or_all()

@type name_or_all() :: String.t() | :all

Functions

alias_permission(actions)

Create alias permission(s).

Named alias_permission because alias is a reserved word in Elixir.

Parameters

  • alias_name - Alias name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions

Examples

Permissions.alias_permission("my-alias", :create)
Permissions.alias_permission(:all, [:create, :read, :delete])

alias_permission(alias_name, actions)

backups(action \\ :manage)

@spec backups(atom()) :: WeaviateEx.RBAC.Permission.t()

Create backups permission.

Parameters

  • action - Action atom (typically :manage). Defaults to :manage.

Examples

Permissions.backups()
Permissions.backups(:manage)

cluster(action \\ :read)

@spec cluster(atom()) :: WeaviateEx.RBAC.Permission.t()

Create cluster permission.

Parameters

  • action - Action atom (typically :read). Defaults to :read.

Examples

Permissions.cluster()
Permissions.cluster(:read)

collections(actions)

Create collections permission(s).

Parameters

  • collection - Collection name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions

Examples

Permissions.collections("Article", :read)
Permissions.collections("Article", [:create, :read, :update])
Permissions.collections(:all, :manage)
Permissions.collections(:read)  # All collections, single action

collections(collection, actions)

data(actions)

Create data permission(s).

Parameters

  • collection - Collection name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions
  • opts - Optional filters:
    • :tenant - Filter by tenant (or :all for wildcard)
    • :object - Filter by object UUID

Examples

Permissions.data("Article", :read)
Permissions.data("Article", :read, tenant: "tenant-a")
Permissions.data("Article", [:create, :update], tenant: :all)

data(collection, actions)

data(collection, actions, opts)

flatten(permission)

Flatten a nested structure of permissions into a single list.

Useful when combining multiple permission builders.

Examples

nested = [
  Permissions.collections("A", [:read, :update]),
  [Permissions.cluster(), Permissions.nodes()]
]
Permissions.flatten(nested)
# => [%Permission{}, %Permission{}, %Permission{}, %Permission{}]

groups(actions)

Create groups permission(s) (OIDC groups).

Parameters

  • group - Group name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions

Examples

Permissions.groups("engineering", :read)
Permissions.groups(:all, :assign_and_revoke)

groups(group, actions)

nodes(verbosity \\ :minimal, opts \\ [])

@spec nodes(
  :minimal | :verbose,
  keyword()
) :: WeaviateEx.RBAC.Permission.t()

Create nodes permission.

Parameters

  • verbosity - :minimal or :verbose. Defaults to :minimal.
  • opts - Optional keyword list:
    • :collection - Filter to specific collection (only valid with :verbose)

Examples

Permissions.nodes()          # Minimal verbosity
Permissions.nodes(:minimal)
Permissions.nodes(:verbose)

# With collection filter (verbose only)
Permissions.nodes(:verbose, collection: "Article")

replicate(actions)

Create replicate permission(s).

Parameters

  • collection - Collection name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions

Examples

Permissions.replicate("Article", :create)
Permissions.replicate(:all, [:create, :read])

replicate(collection, actions)

roles(actions)

Create roles permission(s).

Parameters

  • role - Role name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions
  • opts - Optional filters:
    • :scope - Permission scope: :match or :all

Examples

Permissions.roles("admin", :read)
Permissions.roles(:all, [:create, :read, :delete])
Permissions.roles("admin", :read, scope: :match)
Permissions.roles("*", :manage, scope: :all)

roles(role, actions)

roles(role, actions, opts)

tenants(actions)

Create tenants permission(s).

Parameters

  • collection - Collection name or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions
  • opts - Optional filters:
    • :tenant - Filter by specific tenant

Examples

Permissions.tenants("MyCollection", :create)
Permissions.tenants("MyCollection", [:create, :read, :delete])
Permissions.tenants(:all, :read, tenant: "tenant-a")

tenants(collection, actions)

tenants(collection, actions, opts)

users(actions)

Create users permission(s).

Parameters

  • user - User ID or :all for wildcard. Defaults to "*".
  • actions - Single action atom or list of actions

Examples

Permissions.users("john", :read)
Permissions.users(:all, :assign_and_revoke)

users(user, actions)