Skip to content

prefect_gitlab.credentials

Module used to enable authenticated interactions with GitLab

Classes

GitLabCredentials

Bases: Block

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

Attributes:

Name Type Description
token SecretStr

The personal access token to authenticate with GitLab.

url str

URL to self-hosted GitLab instances.

Examples:

Load stored GitLab credentials:

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

Source code in prefect_gitlab/credentials.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
class GitLabCredentials(Block):
    """
    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")
        ```
    """

    _block_type_name = "GitLab Credentials"
    _logo_url = HttpUrl(
        url="https://images.ctfassets.net/gm98wzqotmnx/55edIimT4g9gbjhkh5a3Sp/dfdb9391d8f45c2e93e72e3a4d350771/gitlab-logo-500.png?h=250",  # noqa
        scheme="https",
    )

    token: SecretStr = Field(
        name="Personal Access Token",
        default=None,
        description="A GitLab Personal Access Token with read_repository scope.",
    )
    url: str = Field(
        default=None, title="URL", description="URL to self-hosted GitLab instances."
    )

    def get_client(self) -> Gitlab:
        """
        Gets an authenticated GitLab client.

        Returns:
            An authenticated GitLab client.
        """
        # ref: https://python-gitlab.readthedocs.io/en/stable/
        gitlab = Gitlab(url=self.url, oauth_token=self.token.get_secret_value())
        gitlab.auth()
        return gitlab

Functions

get_client

Gets an authenticated GitLab client.

Returns:

Type Description
Gitlab

An authenticated GitLab client.

Source code in prefect_gitlab/credentials.py
45
46
47
48
49
50
51
52
53
54
55
def get_client(self) -> Gitlab:
    """
    Gets an authenticated GitLab client.

    Returns:
        An authenticated GitLab client.
    """
    # ref: https://python-gitlab.readthedocs.io/en/stable/
    gitlab = Gitlab(url=self.url, oauth_token=self.token.get_secret_value())
    gitlab.auth()
    return gitlab