Bug 1062889 - [RFE] [api] add class attribute to dnf.cli.Command which will say it is root-only plugin
[RFE] [api] add class attribute to dnf.cli.Command which will say it is root-...
Status: CLOSED ERRATA
Product: Fedora
Classification: Fedora
Component: dnf (Show other bugs)
rawhide
Unspecified Unspecified
unspecified Severity low
: ---
: ---
Assigned To: Ales Kozumplik
Fedora Extras Quality Assurance
:
Depends On:
Blocks: 1080331
  Show dependency treegraph
 
Reported: 2014-02-08 06:08 EST by Miroslav Suchý
Modified: 2014-09-30 19:42 EDT (History)
5 users (show)

See Also:
Fixed In Version: dnf-plugins-core-0.0.8-2.fc20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2014-05-31 19:58:25 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Miroslav Suchý 2014-02-08 06:08:16 EST
Description of problem:
Currently if write plugin, which is intended only for root, I have to put somewhere logic of:

if uid != 0:
   print "you are not root user, go away"
   sys.exit

It would be nice to have class boolean attribute root_only, which would indicate if you must be root to call it. And this check would be done by DNF itself and DNF would print unified error message and unified exit code.
Comment 1 Ales Kozumplik 2014-02-10 03:08:34 EST
We discussed this at the DevConf. Waiting for the moment to do the proper signup mechanism support, where root-user will be one of the elements commands can signup for.
Comment 2 Miroslav Suchý 2014-02-10 04:38:51 EST
As I continued with coding of plugin I do not longer think it should be attribute of class.
Because I want to create plugin which use command alias "copr" and it will have subcommands "enable" which will be for root only. And subcommand "search", which will be available for everybody.
So I would rather see dnf.cli.Command.check_for_root(), which I would call in moments when some action require to be run by root.
Comment 3 Igor Gnatenko 2014-02-17 03:53:43 EST
Just sent  patch.

https://github.com/akozumpl/dnf/pull/89
Comment 4 Igor Gnatenko 2014-02-17 04:32:40 EST
for copr I've implemented in test mode (in separate branch)

https://git.fedorahosted.org/cgit/copr.git/commit/?h=check-root

It works with patched dnf.
Comment 5 Radek Holy 2014-02-17 04:41:58 EST
However such a method does not allow DNF (e.g. noroot plugin) to check whether a command requires root privileges. The simplest solution would be to add a method which accepts CLI arguments and returns the information whether the command needs such privileges. I would prefer a new method 'configure' which accepts CLI arguments and configures all those "properties".

Currently, the sub-commands problem is worked around by defining the 'writes_rpmdb' as a property and setting its value during 'run'. See similar thing here: https://github.com/akozumpl/dnf/blob/master/dnf/cli/commands.py#L743
Comment 6 Ales Kozumplik 2014-02-17 05:18:15 EST
I really dislike adding a special method for this until we know figure out there's nothing better we can do. Let's leave this sitting for now.
Comment 7 Ales Kozumplik 2014-04-01 09:57:45 EDT
Provided by aee2170 on master. The commands can now do:

  cli.demands.root_user = True

This and other demands should can take place in their configure() method as Radek writes comment 5.
Comment 8 Fedora Update System 2014-05-02 04:32:04 EDT
dnf-0.5.1-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/dnf-0.5.1-1.fc20
Comment 9 Fedora Update System 2014-05-02 17:04:36 EDT
Package dnf-0.5.1-1.fc20, hawkey-0.4.14-1.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing dnf-0.5.1-1.fc20 hawkey-0.4.14-1.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-5937/hawkey-0.4.14-1.fc20,dnf-0.5.1-1.fc20
then log in and leave karma (feedback).
Comment 10 Fedora Update System 2014-05-28 08:09:55 EDT
dnf-plugins-core-0.0.8-2.fc20, libsolv-0.6.1-1.git6d968f1.fc20, hawkey-0.4.16-1.fc20, dnf-0.5.2-1.fc20 has been submitted as an update for Fedora 20.
https://admin.fedoraproject.org/updates/libsolv-0.6.1-1.git6d968f1.fc20,hawkey-0.4.16-1.fc20,dnf-0.5.2-1.fc20,dnf-plugins-core-0.0.8-2.fc20
Comment 11 Fedora Update System 2014-05-28 19:49:52 EDT
Package dnf-plugins-core-0.0.8-2.fc20, libsolv-0.6.1-1.git6d968f1.fc20, hawkey-0.4.16-1.fc20, dnf-0.5.2-1.fc20:
* should fix your issue,
* was pushed to the Fedora 20 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing dnf-plugins-core-0.0.8-2.fc20 libsolv-0.6.1-1.git6d968f1.fc20 hawkey-0.4.16-1.fc20 dnf-0.5.2-1.fc20'
as soon as you are able to.
Please go to the following url:
https://admin.fedoraproject.org/updates/FEDORA-2014-6789/libsolv-0.6.1-1.git6d968f1.fc20,hawkey-0.4.16-1.fc20,dnf-0.5.2-1.fc20,dnf-plugins-core-0.0.8-2.fc20
then log in and leave karma (feedback).
Comment 12 Fedora Update System 2014-05-31 19:58:25 EDT
dnf-plugins-core-0.0.8-2.fc20, libsolv-0.6.1-1.git6d968f1.fc20, hawkey-0.4.16-1.fc20, dnf-0.5.2-1.fc20 has been pushed to the Fedora 20 stable repository.  If problems still persist, please make note of it in this bug report.

Note You need to log in before you can comment on or make changes to this bug.