# Path: shelf/cloud/cloud_exceptions.py
# class ArtifactNotFoundError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact {0} not found".format(artifact_name)
#         super(ArtifactNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class BucketNotFoundError(CloudStorageException):
#     def __init__(self, bucket_name):
#         message = "Bucket {0} not found".format(bucket_name)
#         super(BucketNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class DuplicateArtifactError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact by name {0} already exists in current directory".format(artifact_name)
#         super(DuplicateArtifactError, self).__init__(message, ErrorCode.DUPLICATE_ARTIFACT)


from boto.s3.connection import S3Connection
from boto.s3.key import Key
from shelf.cloud.stream_iterator import StreamIterator
from shelf.cloud.cloud_exceptions import ArtifactNotFoundError, BucketNotFoundError, DuplicateArtifactError
            Makes sure that the bucket we are trying to access is accessible. This covers three things.

            1. The bucket we attempted to get was configured, but it doesn't actually exist.
            2. The credentials configured for the bucket are invalid.
            3. We could not connect to S3 for some reason.

            Returns:
                boolean True if bucket is fully accessible.
        """
        accessible = True

        try:
            self._get_bucket(self.bucket_name)
        except BucketNotFoundError:
            accessible = False

        return accessible

    def _get_bucket(self, bucket_name):
        bucket = self.conn.lookup(self.bucket_name)
        if bucket is None:
            # This scenario could be one of three things.
            #
            # 1. The bucket we attempted to get was configured, but it doesn't actually exist.
            # 2. The credentials configured for the bucket are invalid.
            # 3. We could not connect to S3 for some reason.
            self.logger.error(
                "Bucket {0} does not exist or we failed to authenticate with the provided credentials or we were "
                "simply unable to connect to S3.".format(bucket_name)
            )

# Path: shelf/cloud/cloud_exceptions.py
# class ArtifactNotFoundError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact {0} not found".format(artifact_name)
#         super(ArtifactNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class BucketNotFoundError(CloudStorageException):
#     def __init__(self, bucket_name):
#         message = "Bucket {0} not found".format(bucket_name)
#         super(BucketNotFoundError, self).__init__(message, ErrorCode.RESOURCE_NOT_FOUND)
# 
# class DuplicateArtifactError(CloudStorageException):
#     def __init__(self, artifact_name):
#         message = "Artifact by name {0} already exists in current directory".format(artifact_name)
#         super(DuplicateArtifactError, self).__init__(message, ErrorCode.DUPLICATE_ARTIFACT)


# Path: shelf/cloud/storage.py
from boto.s3.connection import S3Connection
from boto.s3.key import Key
from shelf.cloud.stream_iterator import StreamIterator
from shelf.cloud.cloud_exceptions import ArtifactNotFoundError, BucketNotFoundError, DuplicateArtifactError

            Makes sure that the bucket we are trying to access is accessible. This covers three things.

            1. The bucket we attempted to get was configured, but it doesn't actually exist.
            2. The credentials configured for the bucket are invalid.
            3. We could not connect to S3 for some reason.

            Returns:
                boolean True if bucket is fully accessible.
        """
        accessible = True

        try:
            self._get_bucket(self.bucket_name)
        except BucketNotFoundError:
            accessible = False

        return accessible

    def _get_bucket(self, bucket_name):
        bucket = self.conn.lookup(self.bucket_name)
        if bucket is None:
            # This scenario could be one of three things.
            #
            # 1. The bucket we attempted to get was configured, but it doesn't actually exist.
            # 2. The credentials configured for the bucket are invalid.
            # 3. We could not connect to S3 for some reason.
            self.logger.error(
                "Bucket {0} does not exist or we failed to authenticate with the provided credentials or we were "
                "simply unable to connect to S3.".format(bucket_name)
            )

            raise BucketNotFoundError(bucket_name)