diff --git a/prowler/providers/github/PoC.py b/prowler/providers/github/PoC.py deleted file mode 100644 index 144cf18f3b..0000000000 --- a/prowler/providers/github/PoC.py +++ /dev/null @@ -1,11 +0,0 @@ -from os import getenv - -from github import Auth, Github - -TOKEN = getenv("GITHUB_PERSONAL_ACCESS_TOKEN") - -auth = Auth.Token(TOKEN) -g = Github(auth=auth) - -for repo in g.get_user().get_repos(): - print(repo) diff --git a/prowler/providers/github/lib/service/service.py b/prowler/providers/github/lib/service/service.py index f1a30785ea..e113e5a480 100644 --- a/prowler/providers/github/lib/service/service.py +++ b/prowler/providers/github/lib/service/service.py @@ -10,7 +10,7 @@ class GithubService: service: str, provider: GithubProvider, ): - self.clients = self.__set_clients__( + self.client = self.__set_client__( provider.identity, provider.session, service, @@ -19,8 +19,7 @@ class GithubService: self.audit_config = provider.audit_config self.fixer_config = provider.fixer_config - def __set_clients__(self, session): - client = {} + def __set_client__(self, session): try: auth = Auth.Token(session.token) client = Github(auth=auth) @@ -28,5 +27,4 @@ class GithubService: logger.error( f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" ) - else: - return client + return client diff --git a/prowler/providers/github/services/account/account_service.py b/prowler/providers/github/services/account/account_service.py deleted file mode 100644 index 707cb7fa9a..0000000000 --- a/prowler/providers/github/services/account/account_service.py +++ /dev/null @@ -1,31 +0,0 @@ -from pydantic import BaseModel - -from prowler.lib.logger import logger -from prowler.providers.github.github_provider import GithubProvider -from prowler.providers.github.lib.service.service import GithubService - - -class GitHubAccount(GithubService): - def __init__(self, provider: GithubProvider): - super().__init__("GitHubAccount", provider) - self.account = Account( - name=provider.identity.account_name, id=provider.identity.account_id - ) - self._get_ssh_keys_status() - - def _get_ssh_keys_status(self): - try: - user = self.client.get_user() - keys = self.client.get_user_keys(user.login) - self.account.ssh_keys = keys.totalCount > 0 - - except Exception as error: - logger.error( - f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" - ) - - -class Account(BaseModel): - name: str - id: str - ssh_keys: bool = False diff --git a/prowler/providers/github/services/account/__init__.py b/prowler/providers/github/services/repository/__init__.py similarity index 100% rename from prowler/providers/github/services/account/__init__.py rename to prowler/providers/github/services/repository/__init__.py diff --git a/prowler/providers/github/services/repository/repository_client.py b/prowler/providers/github/services/repository/repository_client.py new file mode 100644 index 0000000000..232f8ddf81 --- /dev/null +++ b/prowler/providers/github/services/repository/repository_client.py @@ -0,0 +1,4 @@ +from prowler.providers.common.provider import Provider +from prowler.providers.github.services.repository.repository_client import Repository + +repository_client = Repository(Provider.get_global_provider()) diff --git a/prowler/providers/github/services/repository/repository_public_has_securitymd_file/__init__.py b/prowler/providers/github/services/repository/repository_public_has_securitymd_file/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/prowler/providers/github/services/repository/repository_service.py b/prowler/providers/github/services/repository/repository_service.py new file mode 100644 index 0000000000..8292702ab4 --- /dev/null +++ b/prowler/providers/github/services/repository/repository_service.py @@ -0,0 +1,44 @@ +from typing import Optional + +from pydantic import BaseModel + +from prowler.lib.logger import logger +from prowler.providers.github.lib.service.service import GithubService + + +class Repository(GithubService): + def __init__(self, provider): + super().__init__(__class__.__name__, provider) + self.repositories = {} + self.__threading_call__(self._list_repositories) + + def _list_repositories(self): + logger.info("Repository - Listing Repositories...") + try: + for repo in self.client.get_user().get_repos(): + self.repositories[repo.id] = Repo( + id=repo.id, + name=repo.name, + full_name=repo.full_name, + private=repo.private, + description=repo.description, + securitymd=repo.get_contents("SECURITY.md") is not None, + ) + except Exception as error: + logger.error( + f"{error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}" + ) + + def get_repositories(self): + return self.repositories + + +class Repo(BaseModel): + """Model for Github Repository""" + + id: int + name: str + full_name: str + private: bool + description: Optional[str] + securitymd: Optional[bool] = False