예제 #1
0
def get_auth_items(hostname, ip=None, application=None,
                   serial=None, challenge=None, filter_param=None):
    """
    Return the authentication items for a given hostname and the application.
    The hostname is used to identify the machine object. Then all attached
    tokens to this machines and its applications are searched.

    :param hostname:
    :param ip:
    :param application:
    :param challenge: A challenge for the authitme
    :type challenge: basestring
    :param filter_param: Additional application specific parameter to filter
        the return value
    :type filter_param: dict
    :return: dictionary of lists of the application auth items

    **Example response**:

    .. sourcecode:: json

       { "luks": [ { "slot": "....",
                     "partition": "....",
                     "challenge": "....",
                     "response": "...." }
                 ],
         "ssh": [ { "username": "******",
                    "sshkey": "...."},
                  { "username": "******",
                    "sshkey": "...." }
                 ] }
    """
    #
    # TODO: We should check, if the IP Address matches the hostname
    #
    auth_items = {}
    machinetokens = list_machine_tokens(hostname=hostname,
                                        serial=serial,
                                        application=application)

    for mtoken in machinetokens:
        auth_item = get_auth_item(mtoken.get("application"),
                                  mtoken.get("type"),
                                  mtoken.get("serial"),
                                  challenge,
                                  options=mtoken.get("options"),
                                  filter_param=filter_param)
        if auth_item:
            if mtoken.get("application") not in auth_items:
                # we create a new empty list for the new application type
                auth_items[mtoken.get("application")] = []

            # Add the options the the auth_item
            for k, v in mtoken.get("options", {}).items():
                auth_item[k] = v

            # append the auth_item to the list
            auth_items[mtoken.get("application")].append(auth_item)

    return auth_items
예제 #2
0
def get_auth_items(hostname, ip=None, application=None,
                   serial=None, challenge=None, filter_param=None):
    """
    Return the authentication items for a given hostname and the application.
    The hostname is used to identify the machine object. Then all attached
    tokens to this machines and its applications are searched.

    :param hostname:
    :param ip:
    :param application:
    :param challenge: A challenge for the authitme
    :type challenge: basestring
    :param filter_param: Additional application specific parameter to filter
        the return value
    :type filter_param: dict
    :return: dictionary of lists of the application auth items

    **Example response**:

    .. sourcecode:: json

       { "luks": [ { "slot": "....",
                     "partition": "....",
                     "challenge": "....",
                     "response": "...." }
                 ],
         "ssh": [ { "username": "******",
                    "sshkey": "...."},
                  { "username": "******",
                    "sshkey": "...." }
                 ] }
    """
    #
    # TODO: We should check, if the IP Address matches the hostname
    #
    auth_items = {}
    machinetokens = list_machine_tokens(hostname=hostname,
                                        serial=serial,
                                        application=application)

    for mtoken in machinetokens:
        auth_item = get_auth_item(mtoken.get("application"),
                                  mtoken.get("type"),
                                  mtoken.get("serial"),
                                  challenge,
                                  options=mtoken.get("options"),
                                  filter_param=filter_param)
        if auth_item:
            if mtoken.get("application") not in auth_items:
                # we create a new empty list for the new application type
                auth_items[mtoken.get("application")] = []

            # Add the options the the auth_item
            for k, v in mtoken.get("options", {}).items():
                auth_item[k] = v

            # append the auth_item to the list
            auth_items[mtoken.get("application")].append(auth_item)

    return auth_items