# Path: internetarchive/exceptions.py
# class AuthenticationError(Exception):
#     """Authentication Failed"""


from requests.auth import AuthBase
from internetarchive.exceptions import AuthenticationError
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
internetarchive.auth
~~~~~~~~~~~~~~~~~~~~

This module contains the Archive.org authentication handlers for Requests.

:copyright: (C) 2012-2019 by Internet Archive.
:license: AGPL 3, see LICENSE for more details.
"""


class S3Auth(AuthBase):
    """Attaches S3 Basic Authentication to the given Request object."""
    def __init__(self, access_key=None, secret_key=None):
        self.access_key = access_key
        self.secret_key = secret_key

    def __call__(self, r):
        if not self.access_key:
            if self.secret_key:
                raise AuthenticationError('No access_key set!'
                                          ' Have you run `ia configure`?')
        if not self.secret_key:
            if self.access_key:
                raise AuthenticationError('No secret_key set!'
                                          ' Have you run `ia configure`?')
            else:

# Path: internetarchive/exceptions.py
# class AuthenticationError(Exception):
#     """Authentication Failed"""


# Path: internetarchive/auth.py
from requests.auth import AuthBase
from internetarchive.exceptions import AuthenticationError

# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
internetarchive.auth
~~~~~~~~~~~~~~~~~~~~

This module contains the Archive.org authentication handlers for Requests.

:copyright: (C) 2012-2019 by Internet Archive.
:license: AGPL 3, see LICENSE for more details.
"""


class S3Auth(AuthBase):
    """Attaches S3 Basic Authentication to the given Request object."""
    def __init__(self, access_key=None, secret_key=None):
        self.access_key = access_key
        self.secret_key = secret_key

    def __call__(self, r):
        if not self.access_key:
            if self.secret_key:
                raise AuthenticationError('No access_key set!'
                                          ' Have you run `ia configure`?')
        if not self.secret_key:
            if self.access_key:
                raise AuthenticationError('No secret_key set!'
                                          ' Have you run `ia configure`?')
            else:

                raise AuthenticationError('No access_key or secret_key set!'