Skip to content

Commit 7b7f15d

Browse files
committed
add validation that tf url is populated
1 parent c4bc6d7 commit 7b7f15d

4 files changed

Lines changed: 12 additions & 9 deletions

File tree

package/cloudshell/iac/terraform/downloaders/downloader.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ def __init__(self, shell_helper: ShellHelperObject):
1414

1515
def download_terraform_module(self) -> str:
1616
url = self._shell_helper.attr_handler.get_attribute(ATTRIBUTE_NAMES.GIT_TERRAFORM_MODULE_URL)
17+
if not url:
18+
raise ValueError(f"Must populate attribute '{ATTRIBUTE_NAMES.GIT_TERRAFORM_MODULE_URL}'")
19+
1720
token_enc = self._shell_helper.attr_handler.get_attribute(ATTRIBUTE_NAMES.GIT_TOKEN)
1821
token = self._shell_helper.api.DecryptPassword(token_enc).Value
1922
branch = self._shell_helper.attr_handler.get_attribute(ATTRIBUTE_NAMES.BRANCH)

package/cloudshell/iac/terraform/downloaders/gitlab_downloader.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,18 @@ class GitLabApiUrlData(CommonGitLabUrlData):
2828
api_endpoint: str
2929

3030

31-
def extract_data_from_natural_url(url) -> GitLabNaturalUrlData:
31+
def extract_data_from_raw_url(url) -> GitLabNaturalUrlData:
3232
"""
3333
Take api style url and extract data
34-
Sample Natural url: "http://192.168.85.26/quali_natti/terraformstuff/-/tree/test-branch/rds"
34+
Sample Raw Browser url: "http://192.168.85.26/quali_natti/terraformstuff/-/tree/test-branch/rds"
3535
"""
3636

3737
pattern = (r'^(?P<protocol>https?)://(?P<domain>[^/]+)/(?P<user>[^/]+)/(?P<project>[^/]+)/'
3838
r'(-/tree/(?P<branch>[^/]+))?(?P<path>/.*)?$')
3939

4040
match = re.match(pattern, url)
4141
if not match:
42-
raise ValueError(f"No GitLab Natural URL match found for url '{url}'")
42+
raise ValueError(f"No GitLab URL Data found in RAW url '{url}'")
4343

4444
groups = match.groupdict()
4545
return GitLabNaturalUrlData(protocol=groups['protocol'],
@@ -62,7 +62,7 @@ def extract_data_from_api_url(url) -> GitLabApiUrlData:
6262

6363
match = re.match(pattern, url)
6464
if not match:
65-
raise ValueError(f"No GitLab API URL match found for url '{url}'")
65+
raise ValueError(f"No GitLab url data found in API url '{url}'")
6666

6767
groups = match.groupdict()
6868
return GitLabApiUrlData(protocol=groups['protocol'],
@@ -101,7 +101,7 @@ def download_repo(self, url: str, token: str, branch: str = "") -> str:
101101
if is_api_url:
102102
url_data = extract_data_from_api_url(url)
103103
else:
104-
url_data = extract_data_from_natural_url(url)
104+
url_data = extract_data_from_raw_url(url)
105105
is_https = True if url_data.protocol == "https" else False
106106
api_handler = GitlabApiHandler(host=url_data.domain, token=token, is_https=is_https)
107107
project_id = url_data.project_id if is_api_url else api_handler.get_project_id_from_name(url_data.project_name)

package/tests/integration_tests/test_gitlab_downloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_api_url_download(self):
2020
self.working_dir = working_dir
2121
assert working_dir
2222

23-
def test_natural_url_download(self):
23+
def test_raw_url_download(self):
2424
working_dir = self.downloader.download_repo(url=self.gitlab_vars.natural_url,
2525
token=self.gitlab_vars.token,
2626
branch=self.gitlab_vars.branch)

package/tests/unit_tests/test_gitlab_url_extractor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ class TestGitlabDownloader(unittest.TestCase):
66
NATURAL_URL = "http://192.168.85.26/quali_natti/terraformstuff/-/tree/test-branch/rds"
77
API_URL = "http://192.168.85.26/api/v4/projects/2/repository/archive.zip?path=rds"
88

9-
def test_natural_url(self):
10-
url_data = gitlab_downloader.extract_data_from_natural_url(self.NATURAL_URL)
9+
def test_raw_url(self):
10+
url_data = gitlab_downloader.extract_data_from_raw_url(self.NATURAL_URL)
1111
assert url_data
1212

1313
def test_api_url_extract(self):
@@ -21,4 +21,4 @@ def test_api_validate(self):
2121
def test_raises(self):
2222
url_arg = ""
2323
self.assertRaises(ValueError, gitlab_downloader.extract_data_from_api_url, url_arg)
24-
self.assertRaises(ValueError, gitlab_downloader.extract_data_from_natural_url, url_arg)
24+
self.assertRaises(ValueError, gitlab_downloader.extract_data_from_raw_url, url_arg)

0 commit comments

Comments
 (0)