From 887df2714adb57ee95575930a0856dd7cc2f7262 Mon Sep 17 00:00:00 2001 From: Mikolaj Izdebski Date: Jan 22 2019 18:18:08 +0000 Subject: Import Koschei Koji plugin Import an existing, simple simple Koji Hub plugin to base the new work on instead of starting from scratch. This is cherry-pick of Koschei commit bcbd476efecba2d23fcf9b773e11dacdcaabf29c. --- diff --git a/koji/plugin/README.md b/koji/plugin/README.md new file mode 100644 index 0000000..d81a4e8 --- /dev/null +++ b/koji/plugin/README.md @@ -0,0 +1,41 @@ +Koschei Koji plugin +=================== + +Installation +------------ + +First install plugin file in Koji hub file system: + + mkdir -p /usr/lib/koji-hub-plugins/ + cp koji/plugin.py /usr/lib/koji-hub-plugins/koschei.py + +And then enable it in hub config. `/etc/koji-hub/hub.conf` should +contain: + + PluginPath = /usr/lib/koji-hub-plugins + Plugins = koschei + +Since repos created by Koschei plugin don't physically exist on hub, +appropriate redirect must be added. Create +`/etc/httpd/conf.d/koschei-repos.conf` with the following content: + + RewriteEngine on + RewriteRule "^/kojifiles/repos/(.*)" "http://master-koji.example.com/kojifiles/repos/$1" [R,L] + +Koji hub needs to be restarted for the changes to take effect: + + systemctl restart httpd + +Now Koschei Koji plugin should be installed. To verify that, run +`koji list-api` command -- it should now display `koscheiCreateRepo` +as one of available API calls. + +Usage +----- + +Example plugin usage from Python: + + import koji + ks = koji.ClientSession('http://koji.example.com/kojihub') + ks.login() + ks.koscheiCreateRepo(582920, 'f24-build') diff --git a/koji/plugin/koschei.py b/koji/plugin/koschei.py new file mode 100644 index 0000000..814bc50 --- /dev/null +++ b/koji/plugin/koschei.py @@ -0,0 +1,45 @@ +# Copyright (C) 2016 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Author: Mikolaj Izdebski + +from koji.context import context +from koji.plugin import export +import koji +import sys + +sys.path.insert(0, '/usr/share/koji-hub/') +from kojihub import _singleValue, get_tag, InsertProcessor + +__all__ = ('koscheiCreateRepo') + +@export +def koscheiCreateRepo(repo_id, tag): + """ + Add repo with specified repo_id for given tag and mark it as ready. + Calling user must have repo or admin permission. Specified + repo_id must not exist yet. Specified tag must be a valid tag + name. + """ + context.session.assertPerm('repo') + + event_id = _singleValue("SELECT get_event()") + tag_id = get_tag(tag, strict=True)['id'] + state = koji.REPO_READY + + insert = InsertProcessor('repo') + insert.set(id=repo_id, create_event=event_id, tag_id=tag_id, state=state) + insert.execute()