diff options
author | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2016-01-12 21:00:30 +0200 |
---|---|---|
committer | Paul Sokolovsky <paul.sokolovsky@linaro.org> | 2016-01-12 21:00:30 +0200 |
commit | 8097341492c03b41634e9fe97330c66efedc58f8 (patch) | |
tree | 01cb62cfc38d95e7ae271d3a4b33634fcc600163 | |
parent | b26a13b3e6344a7faf59664893241a3ca007f711 (diff) |
linaro_gerrit.py: Allow to take some args (like password) from config file.
Passwords are not safe to be passed from command line: tehy can be shown in
process list (ps ax, etc), in cron mails, etc.
Config file is linaro_gerrit.conf in the same directory as linaro_gerrit.py.
Clients of linaro_gerrit.py must call apply_gerrit_conf() to pull data from
config.
Change-Id: If21503769d27d5ca865a3d890598d67a0e1ff18f
-rwxr-xr-x | linaro_gerrit.py | 18 | ||||
-rwxr-xr-x | update-gerrit-groups.py | 1 | ||||
-rwxr-xr-x | update-gerrit-keys.py | 1 |
3 files changed, 20 insertions, 0 deletions
diff --git a/linaro_gerrit.py b/linaro_gerrit.py index f2f7d7a..c5fef05 100755 --- a/linaro_gerrit.py +++ b/linaro_gerrit.py @@ -173,3 +173,21 @@ def add_gerrit_args(parser): help="Do not perform any actions, just report") parser.add_argument('--loglevel', default="WARNING", help="Setting logging level, default: %(default)s") + + +def apply_gerrit_conf(args): + """Try to load linaro_gerrit.conf file of simple arg=val format and + use options there for None-valued arguments in args. The usecase is: + Let specify password in a config file, so it didn't show in the process + list, cron emails, etc. If password is specified on command line however, + it should be used instead of one in config file. Different/mroe advanced + usecases may not be handled by this function.""" + conf_path = __file__.rsplit(".", 1)[0] + ".conf" + with open(conf_path) as f: + for l in f: + l = l.strip() + if not l or l[0] == "#": + continue + k, v = [x.strip() for x in l.split("=", 1)] + if hasattr(args, k): + setattr(args, k, v) diff --git a/update-gerrit-groups.py b/update-gerrit-groups.py index 180b89c..a5ecaf3 100755 --- a/update-gerrit-groups.py +++ b/update-gerrit-groups.py @@ -9,6 +9,7 @@ parser = argparse.ArgumentParser( description='Update Gerrit Groups from LDAP') linaro_gerrit.add_gerrit_args(parser) args = parser.parse_args() +linaro_gerrit.apply_gerrit_conf(args) logging.basicConfig() log = logging.getLogger("update-gerrit-groups") log.setLevel(getattr(logging, args.loglevel.upper())) diff --git a/update-gerrit-keys.py b/update-gerrit-keys.py index bb9ddc2..ce7bab0 100755 --- a/update-gerrit-keys.py +++ b/update-gerrit-keys.py @@ -9,6 +9,7 @@ parser = argparse.ArgumentParser( description='Update Gerrit users SSH keys from LDAP') linaro_gerrit.add_gerrit_args(parser) args = parser.parse_args() +linaro_gerrit.apply_gerrit_conf(args) logging.basicConfig() log = logging.getLogger("update-gerrit-keys") log.setLevel(getattr(logging, args.loglevel.upper())) |