ServiceAccount

The ServiceAccount resource can be used to interact with Service Accounts. Various tasks can be performed by using the API Methods included in the class.

Each Service Account fetched by an API Method is represented by an instance of the ServiceAccount class that is returned to the user.

API Methods

disruptive.ServiceAccount.get_service_account(service_account_id, project_id, **kwargs)

Gets the current state of a single Service Account.

Parameters:
  • service_account_id (str) – Unique ID of the target Service Account.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

service_account – Object representing the target Service Account.

Return type:

ServiceAccount

Examples

>>> # Fetch information about a specific Service Account.
>>> sa = disruptive.ServiceAccount.get_service_account(
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
... )
disruptive.ServiceAccount.list_service_accounts(project_id, **kwargs)

Gets a list of the current state of all Service Accounts in a project.

Parameters:
  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

service_accounts – List of objects each representing a Service Account.

Return type:

list[ServiceAccount]

Examples

>>> # Fetch a list of all Service Accounts in a project.
>>> sas = disruptive.ServiceAccount.list_service_accounts(
...     project_id='<PROJECT_ID>',
... )
disruptive.ServiceAccount.create_service_account(project_id, display_name='', basic_auth_enabled=False, **kwargs)

Create a new Service Account in the specified project.

Parameters:
  • project_id (str) – Unique ID of the target project.

  • display_name (str, optional) – Sets a display name for the Service Account.

  • basic_auth_enabled (bool, optional) – Enables Basic Auth for the Service Account if True. Defaults to False.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

service_account – Object representing the newly created Service Account.

Return type:

ServiceAccount

Examples

>>> # Create a new Service Account with basic auth enabled.
>>> sa = disruptive.ServiceAccount.create_service_account(
...     project_id='<PROJECT_ID>',
...     display_name='new-service-account',
...     basic_auth_enabled=True,
... )
disruptive.ServiceAccount.update_service_account(service_account_id, project_id, display_name=None, basic_auth_enabled=None, **kwargs)

Updates the attributes of a specified Service Account.

Parameters:
  • service_account_id (str) – Unique ID of the target Service Account.

  • project_id (str) – Unique ID of the target project.

  • display_name (str, optional) – Updates the Service Account display name.

  • basic_auth_enabled (bool, optional) – If True, enables Basic Auth while False disables it.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

service_account – Object representing the updated Service Account.

Return type:

ServiceAccount

Examples

>>> # Update only the `display_name` of a Service Account.
>>> sa = disruptive.ServiceAccount.update_service_account(
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
...     display_name='new-name',
... )
>>> # Update both `display_name` and `basic_auth_enabled`.
>>> sa = disruptive.ServiceAccount.update_service_account(
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
...     display_name='new-name',
...     basic_auth_enabled=False,
... )
disruptive.ServiceAccount.delete_service_account(service_account_id, project_id, **kwargs)

Deletes the specified Service Account.

Parameters:
  • service_account_id (str) – Unique ID of the Service Account to delete.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Examples

>>> # Delete a single Service Account.
>>> disruptive.ServiceAccount.delete_service_account(
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
... )
Return type:

None

disruptive.ServiceAccount.list_keys(service_account_id, project_id, **kwargs)

Get a list of all keys for a Service Account.

Parameters:
  • service_account_id (str) – Unique ID of the target Service Account.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

keys – List of objects each representing a key.

Return type:

list[Key]

Examples

>>> # List all keys for a specific Service Account.
>>> keys = disruptive.ServiceAccount.list_keys(
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
... )
disruptive.ServiceAccount.get_key(key_id, service_account_id, project_id, **kwargs)

Get the key of a Service Account.

Parameters:
  • key_id (str) – Unique ID of the target key.

  • service_account_id (str) – Unique ID of the target Service Account.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

key – Object representing the target key.

Return type:

Key

Examples

>>> # Get information about a specific key.
>>> key = disruptive.ServiceAccount.get_key(
...     key_id='<KEY_ID>',
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
... )
disruptive.ServiceAccount.create_key(service_account_id, project_id, **kwargs)

Create a new key for the specified Service Account.

Parameters:
  • service_account_id (str) – Unique ID of the target Service Account.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Returns:

key – Object representing the newly created key.

Return type:

Key

Examples

>>> # Create a new key for a specific Service Account.
>>> key = disruptive.ServiceAccount.create_key(
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
... )
disruptive.ServiceAccount.delete_key(key_id, service_account_id, project_id, **kwargs)

Deletes a key in the specified Service Account.

Parameters:
  • key_id (str) – Unique ID of the key to delete.

  • service_account_id (str) – Unique ID of the target Service Account.

  • project_id (str) – Unique ID of the target project.

  • **kwargs – Arbitrary keyword arguments. See the Configuration page.

Examples

>>> # Delete a specific key on a Service Account.
>>> disruptive.ServiceAccount.delete_key(
...     key_id='<KEY_ID',
...     service_account_id='<SERVICE_ACCOUNT_ID>',
...     project_id='<PROJECT_ID>',
... )
Return type:

None

Class

class disruptive.ServiceAccount(service_account)

Represents a Service Account.

When a Service Account response is received, the content is unpacked and the related attributes are updated.

Variables:
  • service_account_id (str) – Unique Service Account ID.

  • email (str) – Unique Service Account email.

  • display_name (str) – The provided display name.

  • basic_auth_enabled (bool) – True if Basic Auth is enabled, otherwise False.

  • create_time (datetime) – Timestamp of when the Service Account was created.

  • update_time (datetime) – Timestamp of when the Service Account was last updated.