Ben Zehavi
01/31/2024, 6:58 PMMarvin
01/31/2024, 6:59 PMrequests
to check if the repository is accessible through the GitLab API:
python
import requests
YOUR_GITLAB_API_TOKEN = "your-token-here"
gitlab_project_id = "project-id-or-path"
headers = {"PRIVATE-TOKEN": YOUR_GITLAB_API_TOKEN}
url = f"<https://gitlab.com/api/v4/projects/{gitlab_project_id}/repository/tree>"
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
# If you got here, the project is accessible
print("Repository is accessible!")
# You can check if Prefect is correctly set up to use this repository...
except requests.HTTPError as http_err:
# Repository not accessible or other HTTP errors
print(f"HTTP error occurred: {http_err}")
except Exception as err:
# Other errors
print(f"An error occurred: {err}")
Keep in mind, checking if the repository is "working" depends on what exactly you mean by working. If you need to perform more complex checks like running workflows, testing block connections, or executing tasks, you would require a more involved script that interacts with both the GitLab API and Prefect Core or Prefect Cloud.
None of this is particularly thrilling, but then again, what is? Remember to replace "your-token-here"
and "project-id-or-path"
with your actual GitLab API token and your GitLab project ID or path. Be prepared for adaptation; it's a gloomy process but necessary. Good luck, not that it usually helps.Nate
01/31/2024, 7:00 PMNate
01/31/2024, 7:00 PMBen Zehavi
01/31/2024, 7:01 PMBen Zehavi
01/31/2024, 7:02 PMBen Zehavi
01/31/2024, 7:02 PMprivate_gitlab_block = GitLabRepository(
name="my-private-gitlab-block-t1",
repository="<https://gitlab.com/org/data-pipelines/prefect-pipelines.git>",
access_token="myPAT"
)
private_gitlab_block.save(name="my-private-gitlab-block-t1")
Ben Zehavi
01/31/2024, 7:02 PMBen Zehavi
01/31/2024, 7:02 PMprefect deployment build org/flows/main.py:organization_summary_flow --name organization_summary_flow -sb gitlab/my-private-gitlab-block-t1
Ben Zehavi
01/31/2024, 7:03 PMBen Zehavi
01/31/2024, 7:03 PMValueError: Unable to find block document named my-private-gitlab-block-t1 for block type gitlab
Ben Zehavi
01/31/2024, 7:03 PMBen Zehavi
01/31/2024, 7:03 PMBen Zehavi
01/31/2024, 7:04 PMBen Zehavi
01/31/2024, 7:06 PMBen Zehavi
01/31/2024, 7:07 PMBen Zehavi
01/31/2024, 7:07 PMBen Zehavi
01/31/2024, 7:07 PMBen Zehavi
01/31/2024, 7:08 PMBen Zehavi
01/31/2024, 7:08 PMgitlab_repository_block = GitLabRepository.load("my-private-gitlab-block-t1")
print(gitlab_repository_block.get_directory())
Ben Zehavi
01/31/2024, 7:08 PMNone
which makes me believe that it's not working as expectedBen Zehavi
01/31/2024, 7:09 PMNate
01/31/2024, 7:11 PMprefect block type ls
?Nate
01/31/2024, 7:11 PMgitlab-repository
Ben Zehavi
01/31/2024, 7:11 PMNate
01/31/2024, 7:12 PMBen Zehavi
01/31/2024, 7:12 PMValueError: Unable to find block document named my-private-gitlab-block-t1 for block type gitlab-repository
Nate
01/31/2024, 7:12 PMprefect block ls | grep gitlab
?Ben Zehavi
01/31/2024, 7:13 PMNate
01/31/2024, 7:13 PMBen Zehavi
01/31/2024, 7:13 PMNate
01/31/2024, 7:13 PMBen Zehavi
01/31/2024, 7:13 PMNate
01/31/2024, 7:13 PMNate
01/31/2024, 7:14 PMprefect config view
?Ben Zehavi
01/31/2024, 7:14 PMBen Zehavi
01/31/2024, 7:14 PMPREFECT_PROFILE='default'
Nate
01/31/2024, 7:14 PMBen Zehavi
01/31/2024, 7:14 PMBen Zehavi
01/31/2024, 7:15 PMNate
01/31/2024, 7:15 PMPREFECT_API_URL
such that it points at your self hosted serverBen Zehavi
01/31/2024, 7:15 PMBen Zehavi
01/31/2024, 7:15 PMBen Zehavi
01/31/2024, 7:15 PMBen Zehavi
01/31/2024, 7:16 PMBen Zehavi
01/31/2024, 7:16 PMBen Zehavi
01/31/2024, 7:17 PMNate
01/31/2024, 7:18 PMBen Zehavi
01/31/2024, 7:19 PMNate
01/31/2024, 7:19 PMBen Zehavi
01/31/2024, 7:20 PMBen Zehavi
01/31/2024, 7:25 PMBen Zehavi
01/31/2024, 7:25 PMBen Zehavi
01/31/2024, 7:26 PM