rbac v0.4.0 RBAC

Documentation for Rbac.

Link to this section Summary

Functions

get_approles/2 fetches the roles for the app

`get_role_from_cache/1 retrieves a role from ets cache

`has_role/2 confirms if the person has the given role e.g: has_role(conn, "home_admin") > true has_role(conn, "potus") > false

`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 for fast access. ETS is an in-memory cache you get for Free in Elixir/Erlang. See: https://elixir-lang.org/getting-started/mix-otp/ets.html and: https://elixirschool.com/en/lessons/specifics/ets

parse_body_response/1 parses the response so your app can use the resulting JSON (list of roles).

Transform a list of maps (roles) to comma-separated string of ids.

Link to this section Functions

Link to this function

get_approles(auth_url, client_id)

get_approles/2 fetches the roles for the app

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(conn, role_name)

`has_role/2 confirms if the person has the given role e.g: has_role(conn, "home_admin") > true has_role(conn, "potus") > 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 for fast access. ETS is an in-memory cache you get for 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

parse_body_response(arg)

Specs

parse_body_response({atom(), String.t()}) :: String.t()

parse_body_response/1 parses the response so your app can use the resulting JSON (list of roles).

Link to this function

transform_role_list_to_string(roles)

Transform a list of maps (roles) to comma-separated string of ids.

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"