Beispiel #1
0
 def __init__(self, given_api_key: str, given_api_secret: str) -> None:
     self.api_key = given_api_key
     try:
         self.api_secret = b64decode(given_api_secret)
     except BinasciiError as e:
         raise IncorrectApiKeyFormat(
             'Rotkehlchen api secret is not in the correct format', ) from e
Beispiel #2
0
def premium_create_and_verify(api_key: ApiKey, api_secret: ApiSecret):
    """Create a Premium object with the key pairs and verify them.

    Returns the created premium object

    raises IncorrectApiKeyFormat if the given key is in the wrong format
    raises AuthenticationError if the given key is rejected by the server
    """
    try:
        premium = Premium(api_key, api_secret)
    except BinasciiError:
        raise IncorrectApiKeyFormat('Rotkehlchen api key is not in the correct format')
    if premium.is_active():
        return premium

    raise AuthenticationError('Rotkehlchen API key was rejected by server')
Beispiel #3
0
    def set_credentials(self, credentials: PremiumCredentials) -> None:
        """Try to set the credentials for a premium rotkehlchen subscription

        Raises PremiumAuthenticationError if the given key is rejected by the Rotkehlchen server
        """
        old_credentials = self.credentials

        # Forget the last active value since we are trying new credentials
        self.status = SubscriptionStatus.UNKNOWN

        # If what's given is not even valid b64 encoding then stop here
        try:
            self.reset_credentials(credentials)
        except BinasciiError as e:
            raise IncorrectApiKeyFormat(f'Secret Key formatting error: {str(e)}')

        active = self.is_active()
        if not active:
            self.reset_credentials(old_credentials)
            raise PremiumAuthenticationError('Rotkehlchen API key was rejected by server')
Beispiel #4
0
    def set_credentials(self, api_key: ApiKey, api_secret: ApiSecret) -> None:
        """Try to set the credentials for a premium rotkehlchen subscription

        Raises IncorrectApiKeyFormat if the given key is not in a proper format
        Raises AuthenticationError if the given key is rejected by the Rotkehlchen server
        """
        old_api_key = self.api_key
        old_secret = ApiSecret(base64.b64encode(self.secret))

        # Forget the last active value since we are trying new credentials
        self.status = SubscriptionStatus.UNKNOWN

        # If what's given is not even valid b64 encoding then stop here
        try:
            self.reset_credentials(api_key, api_secret)
        except BinasciiError as e:
            raise IncorrectApiKeyFormat(f'Secret Key formatting error: {str(e)}')

        active = self.is_active()
        if not active:
            self.reset_credentials(old_api_key, old_secret)
            raise AuthenticationError('Rotkehlchen API key was rejected by server')