Table of Contents
- service_account
- ServiceAccount
- search_service_account
- get_service_account_by_id
- create_service_account
- update_service_account
- delete_service_account
- get_service_account_tokens_by_id
- create_service_account_token_by_id
- delete_service_account_token_by_id
- migrate_api_keys_to_service_accounts
- migrate_api_key_to_service_account
- get_service_account_migration_status
- hide_the_api_keys_tab
- revert_service_account_token_to_api_key
service_account
ServiceAccount Objects
class ServiceAccount()
The class includes all necessary methods to access the Grafana service account API endpoints. Be aware that the functionality inside the class only works with basic authentication (username and password) and that the authenticated user is a Grafana Admin
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_service_account
def search_service_account(results_per_page: int = 1000,
pages: int = 1,
query: str = None) -> dict
The method includes a functionality to get the service accounts specified by the optional pagination functionality
Required Permissions: Action: serviceaccounts:read Scope: global:serviceaccounts:*
Arguments:
results_per_pageint - Specify the results_per_page as integer (default 1000)pagesint - Specify the pages as integer (default 1)querystr - Specify the query (default None)
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calldict - Returns the service accounts
get_service_account_by_id
def get_service_account_by_id(id: int) -> dict
The method includes a functionality to get a service account specified by the id
Required Permissions: Action: serviceaccounts:read Scope: serviceaccounts:*
Arguments:
idint - Specify the id of the service account
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calldict - Returns the service account
create_service_account
def create_service_account(name: str, role: str) -> dict
The method includes a functionality to create a service account
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Arguments:
namestr - Specify the name of the service accountrolestr - Specify the role of the service account
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calldict - Returns the created service account
update_service_account
def update_service_account(id: int, name: str, role: str) -> dict
The method includes a functionality to update a service account specified by the id, name and role
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Arguments:
idint - Specify the id of the service accountnamestr - Specify the name of the service accountrolestr - Specify the role of the service account
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calldict - Returns the service account
delete_service_account
def delete_service_account(id: int)
The method includes a functionality to delete a service account specified by the id
Required Permissions: Action: serviceaccounts:delete Scope: serviceaccounts:id:*
Arguments:
idint - Specify the id of the service account
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
get_service_account_tokens_by_id
def get_service_account_tokens_by_id(id: int) -> list
The method includes a functionality to get a service account tokens specified by the id
Required Permissions: Action: serviceaccounts:read Scope: serviceaccounts:*
Arguments:
idint - Specify the id of the service account
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calllist - Returns the service account tokens
create_service_account_token_by_id
def create_service_account_token_by_id(id: int, name: str, role: str) -> dict
The method includes a functionality to create a service account token specified by the id
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Arguments:
idint - Specify the id of the service accountnamestr - Specify the name of the service accountrolestr - Specify the role of the service account
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
api_calldict - Returns the service account token
delete_service_account_token_by_id
def delete_service_account_token_by_id(id: int, token_id: int)
The method includes a functionality to delete a service account token specified by the id
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Arguments:
idint - Specify the id of the service account token_id (int):
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
migrate_api_keys_to_service_accounts
def migrate_api_keys_to_service_accounts()
The method includes a functionality to migrate all api keys to service accounts
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Raises:
Exception- Unspecified error by executing the API call
Returns:
None
migrate_api_key_to_service_account
def migrate_api_key_to_service_account(key_id: int)
The method includes a functionality to migrate an api key to a service account specified by the key id
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Arguments:
key_idint - Specify the api key id of the api key
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None
get_service_account_migration_status
def get_service_account_migration_status() -> bool
The method includes a functionality to get the corresponding api key migration status
Required Permissions: Action: serviceaccounts:read Scope: serviceaccounts:*
Raises:
Exception- Unspecified error by executing the API call
Returns:
api_calllist - Returns the api key migration status
hide_the_api_keys_tab
def hide_the_api_keys_tab()
The method includes a functionality to hide the api keys tab inside the UI
Required Permissions: Action: serviceaccounts:write Scope: serviceaccounts:*
Raises:
Exception- Unspecified error by executing the API call
Returns:
None
revert_service_account_token_to_api_key
def revert_service_account_token_to_api_key(id: int, key_id: int)
The method includes a functionality to revert a service account and transform it to the legacy api token specified by the service account id and the key id
Required Permissions: Action: serviceaccounts:delete Scope: serviceaccounts:id:*
Arguments:
idint - Specify the id of the service accountkey_idint - Specify the api key id of the api key
Raises:
ValueError- Missed specifying a necessary valueException- Unspecified error by executing the API call
Returns:
None