mflbackend/src/helpers.py
def authenticate(lexicon, action='read'):
    """
    Authentication check. Used when but data is sent to the user, but Karp is
    not involved (Karp takes care of this otherwise).
    Args:
        lexicon (str): the lexicon name
        action (str, optional): defines which permission to verify.
            Possible values: read, write.
    Raises:
        MflException: if the user is not granted the action in the lexicon
    """
    if action == 'checkopen':
        auth = None
    else:
        auth = request.authorization
    postdata = {"include_open_resources": "true"}
    if auth is not None:
        user, pw = auth.username, auth.password
        server = C.config['AUTH_SERVER']
        mdcode = user + pw + C.config['SECRET_KEY']
        postdata["checksum"] = md5(mdcode.encode('utf8')).hexdigest()
        postdata["username"] = user
        postdata["password"] = pw
    else:
        server = C.config['AUTH_RESOURCES']

    data = urllib.parse.urlencode(postdata).encode()
    response = urllib.request.urlopen(server, data).read().decode('utf8')
    auth_response = json.loads(response)
    lexitems = auth_response.get("permitted_resources", {})
    if action == 'checkopen':
        return [lex for lex, per in lexitems.get("lexica", {}).items()
                if per['read']]
    else:
        permissions = lexitems.get("lexica", {}).get(lexconfig.get_wsauth_name(lexicon), {})
        if not permissions.get(action, False):
            raise errs.MflException("Action %s not allowed in lexicon %s" %
                                    (action, lexconfig.get_lexiconname(lexicon)),
                                    code="authentication", status_code=401)
        return permissions

    Authentication check. Used when but data is sent to the user, but Karp is
    not involved (Karp takes care of this otherwise).
    Args:
        lexicon (str): the lexicon name
        action (str, optional): defines which permission to verify.
            Possible values: read, write.
    Raises:
        MflException: if the user is not granted the action in the lexicon
    
Authentication check. Used when but data is sent to the user, but Karp is
not involved (Karp takes care of this otherwise).
Authentication check . Used when but data is sent to the user but Karp is not involved ( Karp takes care of this otherwise ) .
def authenticate(lexicon, action='read'):
    if action == 'checkopen':
        auth = None
    else:
        auth = request.authorization
    postdata = {"include_open_resources": "true"}
    if auth is not None:
        user, pw = auth.username, auth.password
        server = C.config['AUTH_SERVER']
        mdcode = user + pw + C.config['SECRET_KEY']
        postdata["checksum"] = md5(mdcode.encode('utf8')).hexdigest()
        postdata["username"] = user
        postdata["password"] = pw
    else:
        server = C.config['AUTH_RESOURCES']
    data = urllib.parse.urlencode(postdata).encode()
    response = urllib.request.urlopen(server, data).read().decode('utf8')
    auth_response = json.loads(response)
    lexitems = auth_response.get("permitted_resources", {})
    if action == 'checkopen':
        return [lex for lex, per in lexitems.get("lexica", {}).items()
                if per['read']]
    else:
        permissions = lexitems.get("lexica", {}).get(lexconfig.get_wsauth_name(lexicon), {})
        if not permissions.get(action, False):
            raise errs.MflException("Action %s not allowed in lexicon %s" %
                                    (action, lexconfig.get_lexiconname(lexicon)),
                                    code="authentication", status_code=401)
        return permissions
def authenticate ( lexicon , action = 'read' ) : if action == 'checkopen' : auth = None else : auth = request . authorization postdata = { "include_open_resources" : "true" } if auth is not None : user , pw = auth . username , auth . password server = C . config [ 'AUTH_SERVER' ] mdcode = user + pw + C . config [ 'SECRET_KEY' ] postdata [ "checksum" ] = md5 ( mdcode . encode ( 'utf8' ) ) . hexdigest ( ) postdata [ "username" ] = user postdata [ "password" ] = pw else : server = C . config [ 'AUTH_RESOURCES' ] data = urllib . parse . urlencode ( postdata ) . encode ( ) response = urllib . request . urlopen ( server , data ) . read ( ) . decode ( 'utf8' ) auth_response = json . loads ( response ) lexitems = auth_response . get ( "permitted_resources" , { } ) if action == 'checkopen' : return [ lex for lex , per in lexitems . get ( "lexica" , { } ) . items ( ) if per [ 'read' ] ] else : permissions = lexitems . get ( "lexica" , { } ) . get ( lexconfig . get_wsauth_name ( lexicon ) , { } ) if not permissions . get ( action , False ) : raise errs . MflException ( "Action %s not allowed in lexicon %s" % ( action , lexconfig . get_lexiconname ( lexicon ) ) , code = "authentication" , status_code = 401 ) return permissions
Authentication check.
Authentication check .
"""
    Authentication check. Used when but data is sent to the user, but Karp is
    not involved (Karp takes care of this otherwise).
    Args:
        lexicon (str): the lexicon name
        action (str, optional): defines which permission to verify.
            Possible values: read, write.
    Raises:
        MflException: if the user is not granted the action in the lexicon
    """
if the user is not granted the action in the lexicon
if the user is not granted the action in the lexicon
MflException
lexicon
the lexicon name
the lexicon name
action
defines which permission to verify.
Possible values: read, write.
defines which permission to verify . Possible values : read write .