Module tim_client.credentials

Expand source code
from typing import Dict, List, Tuple
from base64 import b64encode
import logging
from logging import Logger


class Credentials:
    """TIM License data necessary to use TIM Engine."""

    __logger: Logger = None
    __tim_url: str = None
    __api_key: str = None
    __license_key: str = None
    __user_email: str = None
    __user_password: str = None

    def __init__(self, license_key: str, user_email: str, user_password: str, tim_url: str = 'https://timws.tangent.works/v4/api', api_key: str = 'a37b7c81-5a85-4eda-847d-d2d5ba33d2c8', logger: Logger = None):
        """Set TIM License credentials."""
        self.__tim_url = tim_url
        self.__api_key = api_key
        self.__license_key = license_key
        self.__user_email = user_email
        self.__user_password = user_password
        
        if self.__logger is None:
            self.__logger = logging.getLogger(__name__)

    def __str__(self) -> str:
        return f'{self.__license_key} - {self.__user_email}'

    def __calculate_basic_auth_value(self) -> str:
        """Return value of Basic Authorization HTTP header."""
        return 'Basic %s' % b64encode(f'{self.__user_email}:{self.__user_password}'.encode()).decode("ascii")

    def get_auth_headers(self) -> Dict:
        """Return dict with authoriaztion headers required by TIM Engine."""
        return {
            'Authorization': self.__calculate_basic_auth_value(),
            'License-Key': self.__license_key,
            'Api-Key': self.__api_key
        }

    def get_tim_url(self) -> str:
        """Return URL of TIM Engine."""
        return self.__tim_url

    def set_tim_url(self, tim_url: str) -> str:
        """Set new URL of TIM Engine."""
        self.__tim_url = tim_url
        self.__logger.debug('TIM URL has been changed to %s', tim_url)

Classes

class Credentials (license_key: str, user_email: str, user_password: str, tim_url: str = 'https://timws.tangent.works/v4/api', api_key: str = 'a37b7c81-5a85-4eda-847d-d2d5ba33d2c8', logger: logging.Logger = None)

TIM License data necessary to use TIM Engine.

Set TIM License credentials.

Expand source code
class Credentials:
    """TIM License data necessary to use TIM Engine."""

    __logger: Logger = None
    __tim_url: str = None
    __api_key: str = None
    __license_key: str = None
    __user_email: str = None
    __user_password: str = None

    def __init__(self, license_key: str, user_email: str, user_password: str, tim_url: str = 'https://timws.tangent.works/v4/api', api_key: str = 'a37b7c81-5a85-4eda-847d-d2d5ba33d2c8', logger: Logger = None):
        """Set TIM License credentials."""
        self.__tim_url = tim_url
        self.__api_key = api_key
        self.__license_key = license_key
        self.__user_email = user_email
        self.__user_password = user_password
        
        if self.__logger is None:
            self.__logger = logging.getLogger(__name__)

    def __str__(self) -> str:
        return f'{self.__license_key} - {self.__user_email}'

    def __calculate_basic_auth_value(self) -> str:
        """Return value of Basic Authorization HTTP header."""
        return 'Basic %s' % b64encode(f'{self.__user_email}:{self.__user_password}'.encode()).decode("ascii")

    def get_auth_headers(self) -> Dict:
        """Return dict with authoriaztion headers required by TIM Engine."""
        return {
            'Authorization': self.__calculate_basic_auth_value(),
            'License-Key': self.__license_key,
            'Api-Key': self.__api_key
        }

    def get_tim_url(self) -> str:
        """Return URL of TIM Engine."""
        return self.__tim_url

    def set_tim_url(self, tim_url: str) -> str:
        """Set new URL of TIM Engine."""
        self.__tim_url = tim_url
        self.__logger.debug('TIM URL has been changed to %s', tim_url)

Methods

def get_auth_headers(self) -> Dict

Return dict with authoriaztion headers required by TIM Engine.

Expand source code
def get_auth_headers(self) -> Dict:
    """Return dict with authoriaztion headers required by TIM Engine."""
    return {
        'Authorization': self.__calculate_basic_auth_value(),
        'License-Key': self.__license_key,
        'Api-Key': self.__api_key
    }
def get_tim_url(self) -> str

Return URL of TIM Engine.

Expand source code
def get_tim_url(self) -> str:
    """Return URL of TIM Engine."""
    return self.__tim_url
def set_tim_url(self, tim_url: str) -> str

Set new URL of TIM Engine.

Expand source code
def set_tim_url(self, tim_url: str) -> str:
    """Set new URL of TIM Engine."""
    self.__tim_url = tim_url
    self.__logger.debug('TIM URL has been changed to %s', tim_url)