<filename>core/Context.py
# Copyright 2021 by <NAME>. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Atik LAH
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# Atik LAH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# Atik LAH BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


"""
Context class that contains different clients instances to communicate with BigQuery, cloud storage, and GitHub API
"""

from github import Github
from google.auth.credentials import Credentials
from google.cloud import bigquery, storage


class Context:
    _instance = None
    _credentials = None

    def __init__(
            self,
            project_id,
            credentials,
            git_hub_token=None,
            dataset_id=None
    ) -> None:
        """
                Args:
                    projectId: gcp current project_id,
                    credentials: instance of Credentials,
                    big_query_client: big query client,
                    githubClient: github api client,
                    storageClient: cloud storage client,
                    datasetId: dataset_id
        """

        if self._credentials is None:
            self._big_query_client = bigquery.Client(project=project_id, credentials=credentials)
            self._project_id = project_id
            self._github_client = Github(git_hub_token)
            self._dataset_id = dataset_id
            self._storage_client = storage.Client(credentials=credentials)
            self._credentials = credentials
        else:
            pass

    def __new__(cls, *args, **kwargs):
        if not isinstance(cls._instance, cls):
            cls._instance = object.__new__(cls)

        return cls._instance

    @property
    def project_id(self):
        """Project ID associated with this credential."""
        return self._project_id

    @property
    def big_query_client(self) -> bigquery.Client:
        """big_query_client associated with this credential."""
        return self._big_query_client

    @property
    def github_client(self) -> Github:
        """git_hub client associated with the token provided."""
        return self._github_client

    @property
    def storage_client(self) -> storage.Client:
        """storage_client associated with this credential."""
        return self._storage_client

    @property
    def credentials(self) -> Credentials:
        """credentials associated with current session."""
        return self._credentials

    @github_client.setter
    def github_client(self, new_github_client):
        self._github_client = new_github_client



<filename>core/Context.py
# Copyright 2021 by <NAME>. All Rights Reserved.
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any purpose and without fee is hereby granted,
# provided that the above copyright notice appear in all copies and that
# both that copyright notice and this permission notice appear in
# supporting documentation, and that the name of Atik LAH
# not be used in advertising or publicity pertaining to distribution
# of the software without specific, written prior permission.
# Atik LAH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# Atik LAH BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.


"""
Context class that contains different clients instances to communicate with BigQuery, cloud storage, and GitHub API
"""

from github import Github
from google.auth.credentials import Credentials
from google.cloud import bigquery, storage


class Context:
    _instance = None
    _credentials = None

    def __init__(
            self,
            project_id,
            credentials,
            git_hub_token=None,
            dataset_id=None
    ) -> None:
        """
                Args:
                    projectId: gcp current project_id,
                    credentials: instance of Credentials,
                    big_query_client: big query client,
                    githubClient: github api client,
                    storageClient: cloud storage client,
                    datasetId: dataset_id
        """

        if self._credentials is None:
            self._big_query_client = bigquery.Client(project=project_id, credentials=credentials)
            self._project_id = project_id
            self._github_client = Github(git_hub_token)
            self._dataset_id = dataset_id
            self._storage_client = storage.Client(credentials=credentials)
            self._credentials = credentials
        else:
            pass

    def __new__(cls, *args, **kwargs):
        if not isinstance(cls._instance, cls):
            cls._instance = object.__new__(cls)

        return cls._instance

    @property
    def project_id(self):
        """Project ID associated with this credential."""
        return self._project_id

    @property
    def big_query_client(self) -> bigquery.Client:
        """big_query_client associated with this credential."""
        return self._big_query_client

    @property
    def github_client(self) -> Github:
        """git_hub client associated with the token provided."""
        return self._github_client

    @property
    def storage_client(self) -> storage.Client:
        """storage_client associated with this credential."""
        return self._storage_client

    @property
    def credentials(self) -> Credentials:
        """credentials associated with current session."""
        return self._credentials

    @github_client.setter
    def github_client(self, new_github_client):
        self._github_client = new_github_client



# Copyright 2021 by <NAME>. All Rights Reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appear in all copies and that # both that copyright notice and this permission notice appear in # supporting documentation, and that the name of Atik LAH # not be used in advertising or publicity pertaining to distribution # of the software without specific, written prior permission. # Atik LAH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL # Atik LAH BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER # IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Context class that contains different clients instances to communicate with BigQuery, cloud storage, and GitHub API Args:                     projectId: gcp current project_id,                     credentials: instance of Credentials,                     big_query_client: big query client,                     githubClient: github api client,                     storageClient: cloud storage client,                     datasetId: dataset_id Project ID associated with this credential. big_query_client associated with this credential. git_hub client associated with the token provided. storage_client associated with this credential. credentials associated with current session.