Bases: CredentialsBlock
Block used to manage GitHub authentication.
Attributes:
Name |
Type |
Description |
token |
SecretStr
|
the token to authenticate into GitHub.
|
Examples:
Load stored GitHub credentials:
from prefect_github import GitHubCredentials
github_credentials_block = GitHubCredentials.load("BLOCK_NAME")
Source code in prefect_github/credentials.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 | class GitHubCredentials(CredentialsBlock):
"""
Block used to manage GitHub authentication.
Attributes:
token: the token to authenticate into GitHub.
Examples:
Load stored GitHub credentials:
```python
from prefect_github import GitHubCredentials
github_credentials_block = GitHubCredentials.load("BLOCK_NAME")
```
"""
_block_type_name = "GitHub Credentials"
_logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/41971cfecfea5f79ff334164f06ecb34d1038dd4-250x250.png" # noqa
_documentation_url = "https://prefecthq.github.io/prefect-github/credentials/#prefect_github.credentials.GitHubCredentials" # noqa
token: SecretStr = Field(
default=None, description="A GitHub personal access token (PAT)."
)
def get_client(self) -> HTTPEndpoint:
"""
Gets an authenticated GitHub GraphQL HTTPEndpoint client.
Returns:
An authenticated GitHub GraphQL HTTPEndpoint client.
Example:
Gets an authenticated GitHub GraphQL HTTPEndpoint client.
```python
from prefect_github import GitHubCredentials
github_credentials = GitHubCredentials(token=token)
client = github_credentials.get_client()
```
"""
if self.token is not None:
base_headers = {"Authorization": f"Bearer {self.token.get_secret_value()}"}
else:
base_headers = None
endpoint = HTTPEndpoint(
"https://api.github.com/graphql", base_headers=base_headers
)
return endpoint
def get_endpoint(self) -> HTTPEndpoint:
"""
Gets an authenticated GitHub GraphQL HTTPEndpoint.
Returns:
An authenticated GitHub GraphQL HTTPEndpoint
Example:
Gets an authenticated GitHub GraphQL HTTPEndpoint.
```python
from prefect import flow
from prefect_github import GitHubCredentials
@flow
def example_get_endpoint_flow():
token = "token_xxxxxxx"
github_credentials = GitHubCredentials(token=token)
endpoint = github_credentials.get_endpoint()
return endpoint
example_get_endpoint_flow()
```
"""
warnings.warn(
"`get_endpoint` is deprecated and will be removed March 31st, 2023, "
"use `get_client` instead.",
DeprecationWarning,
)
return self.get_client()
|
get_client
Gets an authenticated GitHub GraphQL HTTPEndpoint client.
Returns:
Type |
Description |
HTTPEndpoint
|
An authenticated GitHub GraphQL HTTPEndpoint client.
|
Example
Gets an authenticated GitHub GraphQL HTTPEndpoint client.
from prefect_github import GitHubCredentials
github_credentials = GitHubCredentials(token=token)
client = github_credentials.get_client()
Source code in prefect_github/credentials.py
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 | def get_client(self) -> HTTPEndpoint:
"""
Gets an authenticated GitHub GraphQL HTTPEndpoint client.
Returns:
An authenticated GitHub GraphQL HTTPEndpoint client.
Example:
Gets an authenticated GitHub GraphQL HTTPEndpoint client.
```python
from prefect_github import GitHubCredentials
github_credentials = GitHubCredentials(token=token)
client = github_credentials.get_client()
```
"""
if self.token is not None:
base_headers = {"Authorization": f"Bearer {self.token.get_secret_value()}"}
else:
base_headers = None
endpoint = HTTPEndpoint(
"https://api.github.com/graphql", base_headers=base_headers
)
return endpoint
|
get_endpoint
Gets an authenticated GitHub GraphQL HTTPEndpoint.
Returns:
Type |
Description |
HTTPEndpoint
|
An authenticated GitHub GraphQL HTTPEndpoint
|
Example
Gets an authenticated GitHub GraphQL HTTPEndpoint.
from prefect import flow
from prefect_github import GitHubCredentials
@flow
def example_get_endpoint_flow():
token = "token_xxxxxxx"
github_credentials = GitHubCredentials(token=token)
endpoint = github_credentials.get_endpoint()
return endpoint
example_get_endpoint_flow()
Source code in prefect_github/credentials.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 | def get_endpoint(self) -> HTTPEndpoint:
"""
Gets an authenticated GitHub GraphQL HTTPEndpoint.
Returns:
An authenticated GitHub GraphQL HTTPEndpoint
Example:
Gets an authenticated GitHub GraphQL HTTPEndpoint.
```python
from prefect import flow
from prefect_github import GitHubCredentials
@flow
def example_get_endpoint_flow():
token = "token_xxxxxxx"
github_credentials = GitHubCredentials(token=token)
endpoint = github_credentials.get_endpoint()
return endpoint
example_get_endpoint_flow()
```
"""
warnings.warn(
"`get_endpoint` is deprecated and will be removed March 31st, 2023, "
"use `get_client` instead.",
DeprecationWarning,
)
return self.get_client()
|