Back to Prefect

credentials

docs/integrations/prefect-gitlab/api-ref/prefect_gitlab-credentials.mdx

3.6.30.dev31.8 KB
Original Source

prefect_gitlab.credentials

Module used to enable authenticated interactions with GitLab

Classes

GitLabCredentials <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-gitlab/prefect_gitlab/credentials.py#L12" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Store a GitLab personal access token to interact with private GitLab repositories.

Attributes:

  • token: The personal access token to authenticate with GitLab.
  • url: URL to self-hosted GitLab instances.

Examples:

Load stored GitLab credentials:

python
from prefect_gitlab import GitLabCredentials
gitlab_credentials_block = GitLabCredentials.load("BLOCK_NAME")

Methods:

format_git_credentials <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-gitlab/prefect_gitlab/credentials.py#L41" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
format_git_credentials(self, url: str) -> str

Format and return the full git URL with GitLab credentials embedded.

Handles both personal access tokens and deploy tokens correctly:

  • Personal access tokens: prefixed with "oauth2:"
  • Deploy tokens (username:token format): used as-is
  • Already prefixed tokens: not double-prefixed

Args:

Returns:

  • Complete URL with credentials embedded

Raises:

  • ValueError: If token is not configured

get_client <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/integrations/prefect-gitlab/prefect_gitlab/credentials.py#L81" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
get_client(self) -> Gitlab

Gets an authenticated GitLab client.

Returns:

  • An authenticated GitLab client.