From 35556a25fe1cf5a3258ad0abb2e71cfecb1e79b6 Mon Sep 17 00:00:00 2001 From: malealva <162203997+malealva@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:02:57 -0300 Subject: [PATCH] Add support to Github Enterprise --- README.md | 1 + snyk/models.py | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c73d231..b4cdb33 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,7 @@ The client supports a high-level `import_project` method on organizations for ad ```python org = client.organizations.first() org.import_project("github.com/user/project@branch") +org.import_project("api.github.com/user/project@branch") # Github Enterprise org.import_project("docker.io/repository:tag") ``` diff --git a/snyk/models.py b/snyk/models.py index 5b0e8df..0f4206c 100644 --- a/snyk/models.py +++ b/snyk/models.py @@ -200,12 +200,12 @@ def integrations(self) -> Manager: and files, and better errors, would be required. """ - def import_project(self, url, files: Optional[List[str]] = None) -> bool: +self def import_project(self, url, files: Optional[List[str]] = []) -> bool: try: components = url.split("/") service = components[0] - if service == "github.com": + if service in ("github.com", "api.github.com"): owner = components[1] name = components[2] parts = name.split("@") @@ -222,7 +222,11 @@ def import_project(self, url, files: Optional[List[str]] = None) -> bool: except ValueError: raise SnykError try: - integrations = {"github.com": "github", "docker.io": "docker-hub"} + integrations = { + "github.com": "github", + "api.github.com": "github-enterprise", + "docker.io": "docker-hub" + } integration_name = integrations[service] except KeyError: raise SnykError @@ -231,13 +235,15 @@ def import_project(self, url, files: Optional[List[str]] = None) -> bool: return self.integrations.filter(name=integration_name)[0].import_image( name ) - else: + elif service in ("github.com", "api.github.com"): integration = self.integrations.filter(name=integration_name)[0] if files: return integration.import_git(owner, name, branch, files) else: return integration.import_git(owner, name, branch) + else: + raise SnykNotImplementedError except KeyError: raise SnykError