Esempio n. 1
0
 def parse_header(header):
     checksum_type = rhn_rpm.RPM_Header(header).checksum_type()
     return mpmSource.create_package(header,
                                     size=0,
                                     checksum_type=checksum_type,
                                     checksum=None,
                                     relpath=None,
                                     org_id=None,
                                     header_start=None,
                                     header_end=None,
                                     channels=[])
Esempio n. 2
0
def processPackageKeyAssociations(header, checksum_type, checksum):
    provider_sql = rhnSQL.prepare("""
        insert into rhnPackageKeyAssociation
            (package_id, key_id) values
            (:package_id, :key_id)
    """)

    insert_keyid_sql = rhnSQL.prepare("""
        insert into rhnPackagekey
            (id, key_id, key_type_id) values
            (sequence_nextval('rhn_pkey_id_seq'), :key_id, :key_type_id)
    """)

    lookup_keyid_sql = rhnSQL.prepare("""
       select pk.id
         from rhnPackagekey pk
        where pk.key_id = :key_id
    """)

    lookup_keytype_id = rhnSQL.prepare("""
       select id
         from rhnPackageKeyType
        where LABEL in ('gpg', 'pgp')
    """)

    lookup_pkgid_sql = rhnSQL.prepare("""
        select p.id
          from rhnPackage p,
               rhnChecksumView c
         where c.checksum = :csum
           and c.checksum_type = :ctype
           and p.checksum_id = c.id
    """)

    lookup_pkgkey_sql = rhnSQL.prepare("""
        select 1
          from rhnPackageKeyAssociation
         where package_id = :package_id
           and key_id = :key_id
    """)

    lookup_pkgid_sql.execute(ctype=checksum_type, csum=checksum)
    pkg_id = lookup_pkgid_sql.fetchall_dict()

    if not pkg_id:
        # No package to associate, continue with next
        return

    sigkeys = rhn_rpm.RPM_Header(header).signatures
    key_id = None  # _key_ids(sigkeys)[0]
    for sig in sigkeys:
        if sig['signature_type'] in ['gpg', 'pgp']:
            key_id = sig['key_id']

    if not key_id:
        # package is not signed, skip gpg key insertion
        return

    lookup_keyid_sql.execute(key_id=key_id)
    keyid = lookup_keyid_sql.fetchall_dict()

    if not keyid:
        lookup_keytype_id.execute()
        key_type_id = lookup_keytype_id.fetchone_dict()
        insert_keyid_sql.execute(key_id=key_id, key_type_id=key_type_id['id'])
        lookup_keyid_sql.execute(key_id=key_id)
        keyid = lookup_keyid_sql.fetchall_dict()

    lookup_pkgkey_sql.execute(key_id=keyid[0]['id'],
                              package_id=pkg_id[0]['id'])
    exists_check = lookup_pkgkey_sql.fetchall_dict()

    if not exists_check:
        provider_sql.execute(key_id=keyid[0]['id'], package_id=pkg_id[0]['id'])