Table of Contents
user
User Objects
class User()
The class includes all necessary methods to access the Grafana user API endpoints. Be aware that all functionalities inside the class only working with basic authentication (username and password) and that the authenticated user is a Grafana Admin.
HINT: Note Grafana Enterprise API need required permissions if fine-grained access control is enabled
Arguments:
grafana_api_modelAPIModel - Inject a Grafana API model object that includes all necessary values and information
Attributes:
grafana_api_modelAPIModel - This is where we store the grafana_api_model
search_users
def search_users(results_per_page: int = 1000,
page: int = 1,
sort: str = None) -> list
The method includes a functionality to get all Grafana system users specified by the optional results_per_page, page and sort option
Required Permissions: Action: users:read Scope: global.users:*
Arguments:
results_per_pageint - Specify the results_per_page as integer (default 1000)pageint - Specify the page as integer (default 1)sortstr - Specify the sort option. Valid values are login-asc, login-desc, email-asc, email-desc, name-asc, name-desc, lastSeenAtAge-asc and lastSeenAtAge-desc. By default, if sort is not specified, the user list will be ordered by login, email in ascending order (default None)
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calllist - Returns the list of Grafana users
search_users_with_paging
def search_users_with_paging(results_per_page: int = 1000,
page: int = 1,
query: str = None,
sort: str = None) -> dict
The method includes a functionality to get all Grafana system users specified by the optional results_per_page, page, query, sort and general paging functionality
Required Permissions: Action: users:read Scope: global.users:*
Arguments:
results_per_pageint - Specify the results_per_page as integer (default 1000)pageint - Specify the page as integer (default 1)querystr - Specify the query (default None)sortstr - Specify the sort option. Valid values are login-asc, login-desc, email-asc, email-desc, name-asc, name-desc, lastSeenAtAge-asc and lastSeenAtAge-desc. By default, if sort is not specified, the user list will be ordered by login, email in ascending order (default None)
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calldict - Returns the Grafana users
get_user_by_id
def get_user_by_id(id: int) -> dict
The method includes a functionality to get a specific user by the id
Required Permissions: Action: users:read Scope: users:*
Arguments:
idint - Specify the id of the user
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calldict - Returns the user information
get_user_by_username_or_email
def get_user_by_username_or_email(username_or_email: str) -> dict
The method includes a functionality to get a specific user by the username_or_email
Required Permissions: Action: users:read Scope: global.users:*
Arguments:
username_or_emailstr - Specify the username_or_email of the user
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calldict - Returns the user information
update_user
def update_user(id: int, user: UserObject)
The method includes a functionality to update the specified user
Required Permissions: Action: users:write Scope: users:*
Arguments:
idint - Specify the id of the useruserUserObject - Specify the used UserObject
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
get_user_organizations
def get_user_organizations(id: int) -> list
The method includes a functionality to get the specified user organizations
Required Permissions: Action: users:read Scope: users:*
Arguments:
idint - Specify the id of the user
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calllist - Returns a list of the user bound organizations
get_user_teams
def get_user_teams(id: int) -> list
The method includes a functionality to get the specified user teams
Required Permissions: Action: users.teams:read Scope: users:*
Arguments:
idint - Specify the id of the user
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calllist - Returns a list of the user bound teams
switch_specific_user_context
def switch_specific_user_context(user_id: int, org_id: int)
The method includes a functionality to switch the user context to the given organization
Arguments:
user_idint - Specify the user_idorg_idint - Specify the org_id
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
CurrentUser Objects
class CurrentUser()
The class includes all necessary methods to access the Grafana current user API endpoints. Be aware that all functionalities inside the class maybe only working with basic authentication (username and password)
Arguments:
grafana_api_modelAPIModel - Inject a Grafana API model object that includes all necessary values and information
Attributes:
grafana_api_modelAPIModel - This is where we store the grafana_api_model
get_user
def get_user() -> dict
The method includes a functionality to get the current user
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calldict - Returns the user information
update_password
def update_password(old_password: str, new_password: str,
confirm_new_password: str)
The method includes a functionality to update the current user password
Arguments:
old_passwordstr - Specify the old_passwordnew_passwordstr - Specify the new_passwordconfirm_new_passwordstr - Specify the confirm_new_password
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
switch_current_user_context
def switch_current_user_context(org_id: int)
The method includes a functionality to switch the current user context to the given organization
Arguments:
org_idint - Specify the organization id
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
get_user_organizations
def get_user_organizations() -> list
The method includes a functionality to get the current user organizations
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calllist - Returns a list of organizations
get_user_teams
def get_user_teams() -> list
The method includes a functionality to get the current user teams
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calllist - Returns a list of teams
star_a_dashboard
def star_a_dashboard(dashboard_id: int)
The method includes a functionality to star a dashboard for the current user
Arguments:
dashboard_idint - Specify the dashboard id
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
unstar_a_dashboard
def unstar_a_dashboard(dashboard_id: int)
The method includes a functionality to unstar a dashboard for the current user
Arguments:
dashboard_idint - Specify the dashboard id
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
get_auth_tokens
def get_auth_tokens() -> list
The method includes a functionality to get the auth tokens for the current user
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calllist - Returns a list of auth tokens of the current user
revoke_auth_token
def revoke_auth_token(auth_token_id: int)
The method includes a functionality to revoke a specified auth token of the current user
Arguments:
auth_token_idint - Specify the auth_token_id
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None