diff --git a/app/terraform/block/bridge_gitlab.py b/app/terraform/block/bridge_gitlab.py new file mode 100644 index 0000000..7930669 --- /dev/null +++ b/app/terraform/block/bridge_gitlab.py @@ -0,0 +1,27 @@ +from flask import current_app +from gitlab import Gitlab + +from app.terraform.block.bridge_reachability import BlockBridgeReachabilityAutomation + + +class BlockBridgeGitlabAutomation(BlockBridgeReachabilityAutomation): + """ + Automation task to import bridge reachability results from Gitlab. + """ + + short_name = "block_bridge_gitlab" + description = "Import bridge reachability results from Gitlab" + frequency = 30 + + def fetch(self) -> None: + credentials = {"private_token": current_app.config['GITLAB_TOKEN']} + if "GITLAB_URL" in current_app.config: + credentials['url'] = current_app.config['GITLAB_URL'] + gitlab = Gitlab(**credentials) + project = gitlab.project.get(current_app.config['GITLAB_BRIDGE_PROJECT']) + for vantage_point in current_app.config['GITHUB_BRIDGE_VANTAGE_POINTS']: + contents = project.get( + filepath=f"recentResult_{vantage_point}", + ref=current_app.config["GITLAB_BRIDGE_BRANCH"] + ) + self._lines = contents.decode().splitlines() diff --git a/app/terraform/list/gitlab.py b/app/terraform/list/gitlab.py index 6fc6e1a..d5d6da6 100644 --- a/app/terraform/list/gitlab.py +++ b/app/terraform/list/gitlab.py @@ -1,3 +1,5 @@ +from flask import current_app + from app.terraform.list import ListAutomation @@ -21,6 +23,9 @@ class ListGitlabAutomation(ListAutomation): gitlab = { source = "gitlabhq/gitlab" version = "~> 3.14.0" + {% if gitlab_url %} + url = "{{ gitlab_url }}" + {% endif %} } } } @@ -46,3 +51,8 @@ class ListGitlabAutomation(ListAutomation): {% endfor %} """ + + def __init__(self): + super().__init__() + if current_app.config['GITLAB_URL']: + self.template_parameters.append("gitlab_url") diff --git a/requirements.txt b/requirements.txt index 30e016e..ebf67a5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,4 @@ sqlalchemy tldextract wtforms pyyaml +python-gitlab