rbac v0.5.2 RBAC

Documentation for Rbac.

Link to this section Summary

Functions

get_approles/2 fetches the roles for the app from auth server.

get_role_from_cache/1 retrieves a role from ets cache

has_role?/2 confirms if the person has the given role accept Plug.Conn as first argument to simply application code. e.g: has_role?(conn, "home_admin") true

has_role_any/2 checks if the person has any one (or more) of the roles listed. Allows multiple roles to access content. e.g: has_role_any?(conn, ["home_admin", "building_owner") true

init_roles/2 fetches the list of roles for an app from the auth app (auth_url) based on the client_id and caches the list in-memory (ETS) for fast access.

insert_roles_into_ets_cache/1 inserts the list of roles into an ETS in-memroy cache for fast access at run-time. ETS is a high performance cache included Free in Elixir/Erlang. See: https://elixir-lang.org/getting-started/mix-otp/ets.html and: https://elixirschool.com/en/lessons/specifics/ets

list_approles lists all the roles in the current role cache.

parse_role_string/1 extracts the roles from String and makes a List of integers.

transform_role_list_to_string/1 transforms a list of maps (roles) to comma-separated string of ids (minimal data use) which is JSON-compatible and can thus be used in the JWT in auth.

Link to this section Functions

Link to this function

get_approles(auth_url, client_id)

get_approles/2 fetches the roles for the app from auth server.

Link to this function

get_role_from_cache(term)

get_role_from_cache/1 retrieves a role from ets cache

Link to this function

has_role?(roles, role)

has_role?/2 confirms if the person has the given role accept Plug.Conn as first argument to simply application code. e.g: has_role?(conn, "home_admin") true

has_role?(conn, "potus") false

Link to this function

has_role_any?(roles, roles_list)

has_role_any/2 checks if the person has any one (or more) of the roles listed. Allows multiple roles to access content. e.g: has_role_any?(conn, ["home_admin", "building_owner") true

has_role_any?(conn, ["potus", "el_presidente") false

Link to this function

init_roles_cache(auth_url, client_id)

init_roles/2 fetches the list of roles for an app from the auth app (auth_url) based on the client_id and caches the list in-memory (ETS) for fast access.

Link to this function

insert_roles_into_ets_cache(roles)

insert_roles_into_ets_cache/1 inserts the list of roles into an ETS in-memroy cache for fast access at run-time. ETS is a high performance cache included Free in Elixir/Erlang. See: https://elixir-lang.org/getting-started/mix-otp/ets.html and: https://elixirschool.com/en/lessons/specifics/ets

Link to this function

list_approles()

list_approles lists all the roles in the current role cache.

Link to this function

parse_role_string(roles)

parse_role_string/1 extracts the roles from String and makes a List of integers.

Example

iex> RBAC.parse_role_string("1,2,3")
[1,2,3]
Link to this function

transform_role_list_to_string(roles)

transform_role_list_to_string/1 transforms a list of maps (roles) to comma-separated string of ids (minimal data use) which is JSON-compatible and can thus be used in the JWT in auth.

Examples

iex> RBAC.transform_role_list_to_string([%{id: 1}, %{id: 2}, %{id: 3}])
"1,2,3"

iex> RBAC.transform_role_list_to_string("1,2,3")
"1,2,3"

iex> RBAC.transform_role_list_to_string(%{name: "sub", id: 1, revoked: nil})
"1"

iex> RBAC.transform_role_list_to_string([%{id: 1, revoked: 1}, %{id: 3}])
"3"