Skip to content

Commit fb0d1d6

Browse files
committed
Check if container is allowed to execute against private repository
1 parent ec60ea3 commit fb0d1d6

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

app/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ PyGithub==2.3.0
22
click==8.1.7
33
requests==2.32.3
44
sentry-sdk==2.5.1
5+
tcms-api==13.3

app/vendors/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@
1515

1616
import click
1717
from app.utils import strtobool
18+
from tcms_api.xmlrpc import TCMSXmlrpc
19+
20+
21+
class AnonymousRpc(TCMSXmlrpc): # pylint: disable=too-few-public-methods
22+
def _do_login(self):
23+
pass
24+
25+
26+
def anonymous_rpc_client(url):
27+
return AnonymousRpc(None, None, url).server
1828

1929

2030
class TriggerEvent:
@@ -31,6 +41,7 @@ class TriggerEvent:
3141
"end-success": "+1",
3242
"end-failure": "-1",
3343
}
44+
rpc = anonymous_rpc_client("https://public.tenant.kiwitcms.org/xml-rpc/")
3445
stdout = []
3546

3647
def __init__(self, file_path):
@@ -65,3 +76,6 @@ def __exit__(self, exc_type, exc_value, tb):
6576
self.create_reaction(self.reactions["end-failure"])
6677
else:
6778
self.create_reaction(self.reactions["end-success"])
79+
80+
def can_run(self, repository_url):
81+
return self.rpc.GitOps.allow(repository_url)

app/vendors/github.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ def __init__(self, file_path):
2626
base_url=os.environ["GITHUB_API_URL"],
2727
)
2828

29-
if self.private:
29+
if (
30+
os.environ.get("GITHUB_SERVER_URL", "") != "https://github.com"
31+
or self.private
32+
) and not self.can_run(self.payload["repository"]["html_url"]):
3033
raise RuntimeError(
3134
"See https://kiwitcms.org/#subscriptions for running against private repositories!"
3235
)

0 commit comments

Comments
 (0)