Exemple #1
0
    def test_create_user_keys(self, mc_request):
        for code in [400, 401, 404, 500, 599]:
            mc_request.return_value.status_code = code
            mc_request.return_value.content = "error: {}".format(code)

            with pytest.raises(CoprKeygenRequestError) as err:
                create_user_keys(self.username, self.projectname, self.opts)
            assert "Failed to create key-pair for user: foo, project:bar" in str(err)
Exemple #2
0
    def test_create_user_keys(self, mc_request):
        for code in [400, 401, 404, 500, 599]:
            mc_request.return_value.status_code = code
            mc_request.return_value.content = "error: {}".format(code)

            with pytest.raises(CoprKeygenRequestError) as err:
                create_user_keys(self.username, self.projectname, self.opts)
            assert "Failed to create key-pair for user: foo, project:bar" in str(err)
Exemple #3
0
def main():
    # shutil.rmtree("/tmp/users_failed.txt", ignore_errors=True)
    # shutil.rmtree("/tmp/users_done.txt", ignore_errors=True)
    users_done_old = set()
    try:
        with open("/tmp/users_done.txt") as handle:
            for line in handle:
                users_done_old.add(line.strip())
    except Exception as err:
        log.exception(err)
        log.debug("error during read old users done")

    opts = BackendConfigReader().read()
    log.info("Starting pubkey fill, destdir: {}".format(opts.destdir))

    log.debug("list dir: {}".format(os.listdir(opts.destdir)))
    for user_name in os.listdir(opts.destdir):
        if user_name in users_done_old:
            log.info("skipping user: {}".format(user_name))
            continue

        failed = False
        log.info("Started processing user dir: {}".format(user_name))
        user_dir = os.path.join(opts.destdir, user_name)

        for project_name in os.listdir(user_dir):
            log.info("Checking project dir: {}".format(project_name))

            try:
                get_pubkey(user_name, project_name)
                log.info("Key-pair exists for {}/{}".format(
                    user_name, project_name))
            except CoprSignNoKeyError:
                create_user_keys(user_name, project_name, opts)
                log.info("Created new key-pair for {}/{}".format(
                    user_name, project_name))
            except Exception as err:
                log.error(
                    "Failed to get pubkey for {}/{}, mark as failed, skipping")
                log.exception(err)
                failed = True
                continue

            project_dir = os.path.join(user_dir, project_name)
            pubkey_path = os.path.join(project_dir, "pubkey.gpg")
            if not check_signed_rpms(project_dir, user_name, project_name,
                                     opts):
                failed = False

            if not check_pubkey(pubkey_path, user_name, project_name, opts):
                failed = False

        if failed:
            with open("/tmp/users_failed.txt", "a") as handle:
                handle.write("{}\n".format(user_name))
        else:
            with open("/tmp/users_done.txt", "a") as handle:
                handle.write("{}\n".format(user_name))
Exemple #4
0
    def test_create_user_keys(self, mc_request):
        mc_request.return_value.status_code = 200
        create_user_keys(self.username, self.projectname, self.opts)

        assert mc_request.called
        expected_call = mock.call(
            url="http://example.com/gen_key",
            data='{"name_real": "foo_bar", "name_email": "*****@*****.**"}',
            method="post"
        )
        assert mc_request.call_args == expected_call
Exemple #5
0
    def test_create_user_keys(self, mc_request):
        mc_request.return_value.status_code = 200
        create_user_keys(self.username, self.projectname, self.opts)

        assert mc_request.called
        expected_call = mock.call(
            url="http://example.com/gen_key",
            data=
            '{"name_real": "foo_bar", "name_email": "*****@*****.**"}',
            method="post")
        assert mc_request.call_args == expected_call
Exemple #6
0
def main():
    # shutil.rmtree("/tmp/users_failed.txt", ignore_errors=True)
    # shutil.rmtree("/tmp/users_done.txt", ignore_errors=True)
    users_done_old = set()
    try:
        with open("/tmp/users_done.txt") as handle:
            for line in handle:
                users_done_old.add(line.strip())
    except Exception as err:
        log.exception(err)
        log.debug("error during read old users done")

    opts = BackendConfigReader().read()
    log.info("Starting pubkey fill, destdir: {}".format(opts.destdir))

    log.debug("list dir: {}".format(os.listdir(opts.destdir)))
    for user_name in os.listdir(opts.destdir):
        if user_name in users_done_old:
            log.info("skipping user: {}".format(user_name))
            continue

        failed = False
        log.info("Started processing user dir: {}".format(user_name))
        user_dir = os.path.join(opts.destdir, user_name)

        for project_name in os.listdir(user_dir):
            log.info("Checking project dir: {}".format(project_name))

            try:
                get_pubkey(user_name, project_name)
                log.info("Key-pair exists for {}/{}".format(user_name, project_name))
            except CoprSignNoKeyError:
                create_user_keys(user_name, project_name, opts)
                log.info("Created new key-pair for {}/{}".format(user_name, project_name))
            except Exception as err:
                log.error("Failed to get pubkey for {}/{}, mark as failed, skipping")
                log.exception(err)
                failed = True
                continue

            project_dir = os.path.join(user_dir, project_name)
            pubkey_path = os.path.join(project_dir, "pubkey.gpg")
            if not check_signed_rpms(project_dir, user_name, project_name, opts):
                failed = False

            if not check_pubkey(pubkey_path, user_name, project_name, opts):
                failed = False

        if failed:
            with open("/tmp/users_failed.txt", "a") as handle:
                handle.write("{}\n".format(user_name))
        else:
            with open("/tmp/users_done.txt", "a") as handle:
                handle.write("{}\n".format(user_name))
Exemple #7
0
def fix_copr(opts, copr_full_name):
    log.info('Going to fix {}:'.format(copr_full_name))

    owner, coprname = tuple(copr_full_name.split('/'))
    copr_path = os.path.abspath(os.path.join(opts.destdir, owner, coprname))

    if not os.path.isdir(copr_path):
        log.info('Ignoring {}. Directory does not exist.'.format(copr_path))
        return

    log.info(
        '> Generate key-pair on copr-keygen (if not generated) for email {}.'.
        format(create_gpg_email(owner, coprname)))
    create_user_keys(owner, coprname, opts)

    log.info('> Regenerate pubkey.gpg in copr {}.'.format(copr_path))
    get_pubkey(owner, coprname, os.path.join(copr_path, 'pubkey.gpg'))

    log.info('> Re-sign rpms and call createrepo in copr\'s chroots:')
    for dir_name in os.listdir(copr_path):
        dir_path = os.path.join(copr_path, dir_name)
        if not os.path.isdir(dir_path):
            log.info('> > Ignoring {}'.format(dir_path))
            continue

        for builddir_name in os.listdir(dir_path):
            builddir_path = os.path.join(dir_path, builddir_name)
            if not os.path.isdir(builddir_path):
                continue
            log.info(
                '> > Processing rpms in builddir {}:'.format(builddir_path))
            try:
                unsign_rpms_in_dir(
                    builddir_path, opts, log
                )  # first we need to unsign by using rpm-sign before we sign with obs-sign
                sign_rpms_in_dir(owner, coprname, builddir_path, opts, log)
            except Exception as e:
                log.exception(str(e))
                continue

        log.info("> > Running createrepo_unsafe for {}".format(dir_path))
        createrepo_unsafe(dir_path)

        log.info("> > Running add_appdata for {}".format(dir_path))
        add_appdata(dir_path, owner, coprname)
Exemple #8
0
def fix_copr(opts, copr_full_name):
    log.info('Going to fix {}:'.format(copr_full_name))

    owner, coprname = tuple(copr_full_name.split('/'))
    copr_path = os.path.abspath(os.path.join(opts.destdir, owner, coprname))

    if not os.path.isdir(copr_path):
        log.info('Ignoring {}. Directory does not exist.'.format(copr_path))
        return

    log.info('> Generate key-pair on copr-keygen (if not generated) for email {}.'.format(create_gpg_email(owner, coprname)))
    create_user_keys(owner, coprname, opts)

    log.info('> Regenerate pubkey.gpg in copr {}.'.format(copr_path))
    get_pubkey(owner, coprname, os.path.join(copr_path, 'pubkey.gpg'))

    log.info('> Re-sign rpms and call createrepo in copr\'s chroots:')
    for dir_name in os.listdir(copr_path):
        dir_path = os.path.join(copr_path, dir_name)
        if not os.path.isdir(dir_path):
            log.info('> > Ignoring {}'.format(dir_path))
            continue

        for builddir_name in os.listdir(dir_path):
            builddir_path = os.path.join(dir_path, builddir_name)
            if not os.path.isdir(builddir_path):
                continue
            log.info('> > Processing rpms in builddir {}:'.format(builddir_path))
            try:
                unsign_rpms_in_dir(builddir_path, opts, log) # first we need to unsign by using rpm-sign before we sign with obs-sign
                sign_rpms_in_dir(owner, coprname, builddir_path, opts, log)
            except Exception as e:
                log.exception(str(e))
                continue

        log.info("> > Running createrepo_unsafe for {}".format(dir_path))
        createrepo_unsafe(dir_path)

        log.info("> > Running add_appdata for {}".format(dir_path))
        add_appdata(dir_path, owner, coprname)
Exemple #9
0
    def test_create_user_keys_error_1(self, mc_request):
        mc_request.side_effect = IOError()
        with pytest.raises(CoprKeygenRequestError) as err:
            create_user_keys(self.username, self.projectname, self.opts)

        assert "Failed to create key-pair" in str(err)
Exemple #10
0
    def test_create_user_keys_error_1(self, mc_request):
        mc_request.side_effect = IOError()
        with pytest.raises(CoprKeygenRequestError) as err:
            create_user_keys(self.username, self.projectname, self.opts)

        assert "Failed to create key-pair" in str(err)