Skip to content

Commit 35c2d25

Browse files
author
Andrei Neagu
committed
added credentails stripping to vcs string
1 parent 1a4dcea commit 35c2d25

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

packages/service-integration/requirements/_base.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ jsonschema # pytest-plugin
1313
pytest # pytest-plugin
1414
pyyaml
1515
typer[all]
16+
yarl

packages/service-integration/requirements/_base.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ idna==3.7
3535
# via
3636
# email-validator
3737
# requests
38+
# yarl
3839
iniconfig==2.0.0
3940
# via pytest
4041
jinja2==3.1.4
@@ -57,6 +58,8 @@ markupsafe==2.1.5
5758
# via jinja2
5859
mdurl==0.1.2
5960
# via markdown-it-py
61+
multidict==6.1.0
62+
# via yarl
6063
orjson==3.10.7
6164
# via
6265
# -c requirements/../../../packages/models-library/requirements/../../../requirements/constraints.txt
@@ -121,3 +124,5 @@ urllib3==2.2.2
121124
# -c requirements/../../../requirements/constraints.txt
122125
# docker
123126
# requests
127+
yarl==1.12.1
128+
# via -r requirements/_base.in

packages/service-integration/src/service_integration/cli/_compose_spec.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import yaml
99
from models_library.utils.labels_annotations import to_labels
1010
from rich.console import Console
11+
from yarl import URL
1112

1213
from ..compose_spec_model import ComposeSpecification
1314
from ..errors import UndefinedOciImageSpecError
@@ -34,9 +35,17 @@ def _run_git(*args) -> str:
3435
).stdout.strip()
3536

3637

38+
def _strip_credentials(url: str) -> str:
39+
yarl_url = URL(url)
40+
if yarl_url.is_absolute():
41+
stripped_url = URL(url).with_user(None).with_password(None)
42+
return f"{stripped_url}"
43+
return url
44+
45+
3746
def _run_git_or_empty_string(*args) -> str:
3847
try:
39-
return _run_git(*args)
48+
return _strip_credentials(_run_git(*args))
4049
except FileNotFoundError as err:
4150
error_console.print(
4251
"WARNING: Defaulting label to emtpy string",
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import pytest
2+
from service_integration.cli._compose_spec import _strip_credentials
3+
4+
5+
@pytest.mark.parametrize(
6+
"url, expected_url",
7+
[
8+
(
9+
"schema.veshttps://user:[email protected]/some/repo.git",
10+
"schema.veshttps://example.com/some/repo.git",
11+
),
12+
(
13+
"https://user:[email protected]/some/repo.git",
14+
"https://example.com/some/repo.git",
15+
),
16+
(
17+
"ssh://user:[email protected]/some/repo.git",
18+
"ssh://example.com/some/repo.git",
19+
),
20+
(
21+
"[email protected]:some/repo.git",
22+
"[email protected]:some/repo.git",
23+
),
24+
],
25+
)
26+
def test__strip_credentials(url: str, expected_url: str):
27+
assert _strip_credentials(url) == expected_url

0 commit comments

Comments
 (0)