예제 #1
0
def delete_option(machinetoken_id=None,
                  machine_id=None,
                  resolver_name=None,
                  hostname=None,
                  serial=None,
                  application=None,
                  key=None):
    """
    delete option from a machine token definition

    You can either specify machinetoken_id or
     * machine_id, resolvername, serial, application or
     * hostname, serial, application
    :param machinetoken_id: The database id of the machinetoken
    :param machine_id: the resolver dependent machine id
    :param resolver_name: the name of the machine resolver
    :param hostname: the machine name
    :param serial: the serial number of the token
    :param application: the application
    """
    if not machinetoken_id:
        machine_id, resolver_name = _get_host_identifier(
            hostname, machine_id, resolver_name)
        machinetoken_id = get_machinetoken_id(machine_id, resolver_name,
                                              serial, application)

    r = MachineTokenOptions.query.filter(
        and_(MachineTokenOptions.machinetoken_id == machinetoken_id,
             MachineTokenOptions.mt_key == key)).delete()
    db.session.commit()
    return r
예제 #2
0
def add_option(machinetoken_id=None,
               machine_id=None,
               resolver_name=None,
               hostname=None,
               serial=None,
               application=None,
               options=None):
    """
    Add options to the machine token definition.
    You can either specify machinetoken_id or
     * machine_id, resolvername, serial, application or
     * hostname, serial, application
    :param machinetoken_id: The database id of the machinetoken
    :param machine_id: the resolver dependent machine id
    :param resolver_name: the name of the machine resolver
    :param hostname: the machine name
    :param serial: the serial number of the token
    :param application: the application
    """
    if options is None:
        options = {}
    if not machinetoken_id:
        machine_id, resolver_name = _get_host_identifier(
            hostname, machine_id, resolver_name)

        machinetoken_id = get_machinetoken_id(machine_id, resolver_name,
                                              serial, application)

    for option_name, option_value in options.items():
        MachineTokenOptions(machinetoken_id, option_name, option_value)
    return len(options)
예제 #3
0
def delete_option(machinetoken_id=None, machine_id=None, resolver_name=None,
                  hostname=None, serial=None, application=None, key=None):
    """
    delete option from a machine token definition

    You can either specify machinetoken_id or
     * machine_id, resolvername, serial, application or
     * hostname, serial, application
    :param machinetoken_id: The database id of the machinetoken
    :param machine_id: the resolver dependent machine id
    :param resolver_name: the name of the machine resolver
    :param hostname: the machine name
    :param serial: the serial number of the token
    :param application: the application
    """
    if not machinetoken_id:
        machine_id, resolver_name = _get_host_identifier(hostname, machine_id,
                                                         resolver_name)
        machinetoken_id = get_machinetoken_id(machine_id,
                                              resolver_name,
                                              serial,
                                              application)

    r = MachineTokenOptions.query.filter(and_(
        MachineTokenOptions.machinetoken_id == machinetoken_id,
        MachineTokenOptions.mt_key == key)).delete()
    db.session.commit()
    return r
예제 #4
0
def add_option(machinetoken_id=None, machine_id=None, resolver_name=None,
               hostname=None, serial=None, application=None, options=None):
    """
    Add options to the machine token definition.
    You can either specify machinetoken_id or
     * machine_id, resolvername, serial, application or
     * hostname, serial, application
    :param machinetoken_id: The database id of the machinetoken
    :param machine_id: the resolver dependent machine id
    :param resolver_name: the name of the machine resolver
    :param hostname: the machine name
    :param serial: the serial number of the token
    :param application: the application
    """
    if options is None:
        options = {}
    if not machinetoken_id:
        machine_id, resolver_name = _get_host_identifier(hostname, machine_id,
                                                         resolver_name)

        machinetoken_id = get_machinetoken_id(machine_id,
                                              resolver_name,
                                              serial,
                                              application)

    for option_name, option_value in options.items():
            MachineTokenOptions(machinetoken_id, option_name, option_value)
    return len(options)
예제 #5
0
def detach_token(serial,
                 application,
                 hostname=None,
                 machine_id=None,
                 resolver_name=None):
    """
    Delete a machine token.
    Also deletes the corresponding MachineTokenOptions
    You need to provide either the hostname or the (machine_id,
    resolver_name) of the machine, from which you want to detach the
    token.

    :param serial: The serial number of the token
    :type serial: string
    :param application: The name of the application - something like ssh or luks
    :type application: basestring
    :param hostname: The hostname of the machine
    If the hostname is not unique, an exception is raised.
    :type hostname: basestring
    :param machine_id: The machine ID of the machine
    :type machine_id: basestring
    :param resolver_name: The resolver_name of the machine
    :type resolver_name: basestring
    :param options: addtional options
    :return: the new MachineToken Object
    """
    machine_id, resolver_name = _get_host_identifier(hostname, machine_id,
                                                     resolver_name)

    mtid = get_machinetoken_id(machine_id, resolver_name, serial, application)
    token_id = get_token_id(serial)
    machineresolver_id = get_machineresolver_id(resolver_name)
    # Delete MachineTokenOptions
    # Delete MachineToken
    MachineTokenOptions.query.filter(
        MachineTokenOptions.machinetoken_id == mtid).delete()
    r = MachineToken.query.filter(
        and_(MachineToken.token_id == token_id,
             MachineToken.machine_id == machine_id,
             MachineToken.machineresolver_id == machineresolver_id,
             MachineToken.application == application)).delete()
    db.session.commit()
    return r
예제 #6
0
def detach_token(serial, application, hostname=None, machine_id=None,
                 resolver_name=None):
    """
    Delete a machine token.
    Also deletes the corresponding MachineTokenOptions
    You need to provide either the hostname or the (machine_id,
    resolver_name) of the machine, from which you want to detach the
    token.

    :param serial: The serial number of the token
    :type serial: string
    :param application: The name of the application - something like ssh or luks
    :type application: basestring
    :param hostname: The hostname of the machine
    If the hostname is not unique, an exception is raised.
    :type hostname: basestring
    :param machine_id: The machine ID of the machine
    :type machine_id: basestring
    :param resolver_name: The resolver_name of the machine
    :type resolver_name: basestring
    :param options: addtional options
    :return: the new MachineToken Object
    """
    machine_id, resolver_name = _get_host_identifier(hostname, machine_id,
                                                     resolver_name)

    mtid = get_machinetoken_id(machine_id, resolver_name, serial,
                               application)
    token_id = get_token_id(serial)
    machineresolver_id = get_machineresolver_id(resolver_name)
    # Delete MachineTokenOptions
    # Delete MachineToken
    MachineTokenOptions.query.filter(MachineTokenOptions.machinetoken_id == mtid).delete()
    r = MachineToken.query.filter(and_(MachineToken.token_id == token_id,
                    MachineToken.machine_id == machine_id,
                    MachineToken.machineresolver_id == machineresolver_id,
                    MachineToken.application == application)).delete()
    db.session.commit()
    return r