Example #1
0
def handled_list(ui_, params, stored_cfg):
    """ INTERNAL: HACKED"""
    if params['FMSREAD'] != 'listall' and params['FMSREAD'] != 'list':
        return False

    trust_map = None
    if params['FMSREAD'] == 'list':
        trust_map = stored_cfg.fmsread_trust_map.copy() # paranoid copy
        fms_ids = trust_map.keys()
        fms_ids.sort()
        ui_.status(("Only listing repo USKs from trusted "
                    + "FMS IDs:\n   %s\n\n") % '\n   '.join(fms_ids))

    parser = USKNotificationParser(trust_map)
    parser.add_default_repos(KNOWN_REPOS)
    recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'],
                             stored_cfg.defaults['FMS_PORT'],
                             None),
              parser,
              stored_cfg.fmsread_groups)
    show_table(parser, ui_.status)

    return True
Example #2
0
def get_uri_from_hash(ui_, dummy, params, stored_cfg):
    """ Use FMS to get the URI for a repo hash. """

    show_fms_info(ui_, params, stored_cfg)

    parser = USKNotificationParser(get_trust_map(ui_, params, stored_cfg))
    parser.add_default_repos(KNOWN_REPOS)

    ui_.status("Raking through fms messages. This may take a while...\n")
    recv_msgs(get_connection(stored_cfg.defaults['FMS_HOST'],
                             stored_cfg.defaults['FMS_PORT'],
                             None),
              parser,
              stored_cfg.fmsread_groups,
              None,
              True)

    target_usk = None
    fms_id_map, announce_map, update_map = parser.invert_table()

    # Find URI
    for usk in announce_map:
        if params['FMSREAD_HASH'] == get_usk_hash(usk):
            # We don't care who announced. The hash matches.
            target_usk = usk
            break

    if target_usk is None:
        raise util.Abort(("No announcement found for [%s]. "
                          +"Use --uri to set the URI.") %
                         params['FMSREAD_HASH'])

    if params['VERBOSITY'] >= 2:
        ui_.status("Found URI announcement:\n%s\n" % target_usk)

    trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH'])

    notifiers = {}
    for clean_id in update_map[params['FMSREAD_HASH']]:
        notifiers[fms_id_map[clean_id]] = (parser.table[clean_id][1]
                                           [params['FMSREAD_HASH']])

    fms_ids = notifiers.keys()
    fms_ids.sort()

    ui_.status("Found Updates:\n")
    for fms_id in fms_ids:
        if fms_id in trusted_notifiers:
            ui_.status("   [trusted]:%i:%s\n" % (notifiers[fms_id], fms_id))
        else:
            ui_.status("   [untrusted]:%i:%s\n" % (notifiers[fms_id], fms_id))

    check_trust_map(ui_, stored_cfg, params['FMSREAD_HASH'],
                    notifiers, trusted_notifiers)

    # Check for updates against the updated trust map.
    trusted_notifiers = stored_cfg.trusted_notifiers(params['FMSREAD_HASH'])
    for fms_id in fms_ids:
        if fms_id in trusted_notifiers:
            if (notifiers[fms_id] >
                stored_cfg.get_index(params['FMSREAD_HASH'])):
                stored_cfg.update_index(params['FMSREAD_HASH'],
                                        notifiers[fms_id])

    return target_usk