Skip to content

create_workspace_service_account_token async

create_workspace_service_account_token(
    name: ServiceAccountTokenName,
    seconds_to_live: int,
    service_account_id: str,
    workspace_id: WorkspaceId,
    *,
    config_overrides: Optional[AsyncgrafanaClientConfig] = None,
) -> CreateWorkspaceServiceAccountTokenResponse

Creates a token that can be used to authenticate and authorize Grafana HTTP API operations for the given workspace service account. The service account acts as a user for the API operations, and defines the permissions that are used by the API.

When you create the service account token, you will receive a key that is used when calling Grafana APIs. Do not lose this key, as it will not be retrievable again.

If you do lose the key, you can delete the token and recreate it to receive a new key. This will disable the initial key.

Service accounts are only available for workspaces that are compatible with Grafana version 9 and above.

Parameters:

  • name (ServiceAccountTokenName) –

    A name for the token to create.

  • seconds_to_live (int) –

    Sets how long the token will be valid, in seconds. You can set the time up to 30 days in the future.

  • service_account_id (str) –

    The ID of the service account for which to create a token.

  • workspace_id (WorkspaceId) –

    The ID of the workspace the service account resides within.

Raises:

Source code in docs_src/capo_grafana/_services/async_grafana.py
async def create_workspace_service_account_token(
    self,
    name: "capo_grafana.types.service_account_token_name.ServiceAccountTokenName",
    seconds_to_live: int,
    service_account_id: str,
    workspace_id: "capo_grafana.types.workspace_id.WorkspaceId",
    *,
    config_overrides: Optional[AsyncgrafanaClientConfig] = None,
) -> "capo_grafana.types.create_workspace_service_account_token_response.CreateWorkspaceServiceAccountTokenResponse":
    """<p>Creates a token that can be used to authenticate and authorize Grafana HTTP API operations for the given <a href="https://docs.aws.amazon.com/grafana/latest/userguide/service-accounts.html">workspace service account</a>. The service account acts as a user for the API operations, and defines the permissions that are used by the API.</p> <important> <p>When you create the service account token, you will receive a key that is used when calling Grafana APIs. Do not lose this key, as it will not be retrievable again.</p> <p>If you do lose the key, you can delete the token and recreate it to receive a new key. This will disable the initial key.</p> </important> <p>Service accounts are only available for workspaces that are compatible with Grafana version 9 and above.</p>

    Args:
        name: <p>A name for the token to create.</p>
        seconds_to_live: <p>Sets how long the token will be valid, in seconds. You can set the time up to 30 days in the future.</p>
        service_account_id: <p>The ID of the service account for which to create a token.</p>
        workspace_id: <p>The ID of the workspace the service account resides within.</p>

    Raises:
        capo_grafana.errors.access_denied_exception.AccessDeniedException: <p>You do not have sufficient permissions to perform this action. </p>
        capo_grafana.errors.conflict_exception.ConflictException: <p>A resource was in an inconsistent state during an update or a deletion.</p>
        capo_grafana.errors.internal_server_exception.InternalServerException: <p>Unexpected error while processing the request. Retry the request.</p>
        capo_grafana.errors.resource_not_found_exception.ResourceNotFoundException: <p>The request references a resource that does not exist.</p>
        capo_grafana.errors.service_quota_exceeded_exception.ServiceQuotaExceededException: <p>The request would cause a service quota to be exceeded.</p>
        capo_grafana.errors.throttling_exception.ThrottlingException: <p>The request was denied because of request throttling. Retry the request.</p>
        capo_grafana.errors.validation_exception.ValidationException: <p>The value of a parameter in the request caused an error.</p>
        capo_grafana.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_grafana.types.create_workspace_service_account_token_request.CreateWorkspaceServiceAccountTokenRequest]",
    ) -> AsyncOperationResponse[
        "capo_grafana.types.create_workspace_service_account_token_response.CreateWorkspaceServiceAccountTokenResponse"
    ]:
        import capo_grafana._operations.aws_grafana_control_plane.create_workspace_service_account_token

        (
            output,
            http_response,
        ) = await capo_grafana._operations.aws_grafana_control_plane.create_workspace_service_account_token.async_create_workspace_service_account_token(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    def _redact_output(
        output: "capo_grafana.types.create_workspace_service_account_token_response.CreateWorkspaceServiceAccountTokenResponse",
    ) -> dict[str, Any]:
        import capo_grafana.types.create_workspace_service_account_token_response

        return capo_grafana.types.create_workspace_service_account_token_response.redact_sensitive(
            output
        )

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging(
            "CreateWorkspaceServiceAccountToken", redact_output=_redact_output
        ),
    )
    input_: capo_grafana.types.create_workspace_service_account_token_request.CreateWorkspaceServiceAccountTokenRequest = {
        "name": name,
        "seconds_to_live": seconds_to_live,
        "service_account_id": service_account_id,
        "workspace_id": workspace_id,
    }

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output