Module licenseware.decorators.auth_decorators.authenticated_machine

Expand source code
from functools import wraps
from licenseware.utils.logger import log
from licenseware.auth import Authenticator
from licenseware.common.constants import envs


def authenticated_machine(f):
    """
        Refreshes the authentication token before making a request
    """
    @wraps(f)
    def decorated(*args, **kwargs):   

        if envs.DESKTOP_ENVIRONMENT: return f(*args, **kwargs)
        
        response, status_code = Authenticator.connect()
        if status_code not in {200, 201}:
            log.warning("Could not refresh token")
            return {'status': 'fail', 'message': 'Could not refresh token'}, 403
       
        return f(*args, **kwargs)
    
    return decorated

Functions

def authenticated_machine(f)

Refreshes the authentication token before making a request

Expand source code
def authenticated_machine(f):
    """
        Refreshes the authentication token before making a request
    """
    @wraps(f)
    def decorated(*args, **kwargs):   

        if envs.DESKTOP_ENVIRONMENT: return f(*args, **kwargs)
        
        response, status_code = Authenticator.connect()
        if status_code not in {200, 201}:
            log.warning("Could not refresh token")
            return {'status': 'fail', 'message': 'Could not refresh token'}, 403
       
        return f(*args, **kwargs)
    
    return decorated