From 545f3f1e7e5b3a3138e2ca0cde37f762ea4f0177 Mon Sep 17 00:00:00 2001 From: Alfredo Deza Date: Fri, 23 Jun 2017 14:38:14 -0400 Subject: [PATCH] ceph-volume: decorators: add a check for super user privileges Signed-off-by: Alfredo Deza --- src/ceph-volume/ceph_volume/decorators.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/ceph-volume/ceph_volume/decorators.py b/src/ceph-volume/ceph_volume/decorators.py index f41f89fb4d0f..d8bea58fe92b 100644 --- a/src/ceph-volume/ceph_volume/decorators.py +++ b/src/ceph-volume/ceph_volume/decorators.py @@ -1,9 +1,22 @@ import os import sys -from ceph_volume import terminal +from ceph_volume import terminal, exceptions from functools import wraps +def needs_root(func): + """ + Check for super user privileges on functions/methods. Raise + ``SuperUserError`` with a nice message. + """ + @wraps(func) + def is_root(*a, **kw): + if not os.getuid() == 0: + raise exceptions.SuperUserError() + return func + return is_root + + def catches(catch=None, handler=None, exit=True): """ Very simple decorator that tries any of the exception(s) passed in as -- 2.47.3