# Path: ethronsoft/gcspypi/exceptions/repository_errors.py
# class RepositoryError(Exception):
#     pass
# 
# Path: ethronsoft/gcspypi/exceptions/boundary_errors.py
# class NotFound(Exception):
#     pass
# 
# Path: ethronsoft/gcspypi/repository/object_metadata.py
# class ObjectMetadata(object):
#     """ObjectMetadata represents the metadata associated with a repository Object
#     """
# 
#     def __init__(self, mime, md5_hash, time_created):
#         """ObjectMetadata constructor
#         
#         Arguments:
#             mime {str} -- MIME type of object
#             md5_hash {str} -- Hash representing the object. Can be used to determine content equality
#             time_created {datetime} -- Timestamp for the object creation
#         """
# 
#         self.mime = mime
#         self.md5 = md5_hash
#         self.time_created = time_created


from google.cloud import storage
from ethronsoft.gcspypi.exceptions import RepositoryError, NotFound
from .object_metadata import ObjectMetadata
import six
import sys
import warnings


class GCloudRepository(object):

    def __init__(self, bucket):
        """GCloudRepository constructor

        Arguments:
            bucket {str} -- The Google Cloud Storage Bucket to act as our repository

        Raises:
            cpm.exceptions.RepositoryError -- If the was an error connecting to the repository
            or to the bucket. Most often due to invalid credentials    
        """
        try:
            #NOTE: It is convenient to authenticate with application-default credentials.
            #Moving away from it is as simple as setting an environment variable and getting access
            #to server credentials but this is cumbersome for the front-end use of cpm.
            #Keeping this for as long as google doesn't deprecate feature
            warnings.filterwarnings("ignore", "Your application has authenticated using end user credentials")
            self.bucket = storage.Client().bucket(bucket)
            if not self.bucket.exists():

# Path: ethronsoft/gcspypi/exceptions/repository_errors.py
# class RepositoryError(Exception):
#     pass
# 
# Path: ethronsoft/gcspypi/exceptions/boundary_errors.py
# class NotFound(Exception):
#     pass
# 
# Path: ethronsoft/gcspypi/repository/object_metadata.py
# class ObjectMetadata(object):
#     """ObjectMetadata represents the metadata associated with a repository Object
#     """
# 
#     def __init__(self, mime, md5_hash, time_created):
#         """ObjectMetadata constructor
#         
#         Arguments:
#             mime {str} -- MIME type of object
#             md5_hash {str} -- Hash representing the object. Can be used to determine content equality
#             time_created {datetime} -- Timestamp for the object creation
#         """
# 
#         self.mime = mime
#         self.md5 = md5_hash
#         self.time_created = time_created


# Path: ethronsoft/gcspypi/repository/gcloud_remote.py
from google.cloud import storage
from ethronsoft.gcspypi.exceptions import RepositoryError, NotFound
from .object_metadata import ObjectMetadata
import six
import sys
import warnings



class GCloudRepository(object):

    def __init__(self, bucket):
        """GCloudRepository constructor

        Arguments:
            bucket {str} -- The Google Cloud Storage Bucket to act as our repository

        Raises:
            cpm.exceptions.RepositoryError -- If the was an error connecting to the repository
            or to the bucket. Most often due to invalid credentials    
        """
        try:
            #NOTE: It is convenient to authenticate with application-default credentials.
            #Moving away from it is as simple as setting an environment variable and getting access
            #to server credentials but this is cumbersome for the front-end use of cpm.
            #Keeping this for as long as google doesn't deprecate feature
            warnings.filterwarnings("ignore", "Your application has authenticated using end user credentials")
            self.bucket = storage.Client().bucket(bucket)
            if not self.bucket.exists():

                raise RepositoryError("{} does not exist".format(bucket))