From: Tiago Melo Date: Mon, 11 Nov 2019 14:34:44 +0000 (-0100) Subject: backport-create-issue: read redmine key from file X-Git-Tag: v15.1.0~918^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=1b5f37bbcd4ad0deff39b160a156b726065d20c3;p=ceph-ci.git backport-create-issue: read redmine key from file Now you don't need to provide redmine key or user/password as a flag, as the script will read it from "~/.redmine_key". This makes it more consistent with other scripts. Signed-off-by: Tiago Melo --- diff --git a/src/script/backport-create-issue b/src/script/backport-create-issue index 8afe21db438..6e419142637 100755 --- a/src/script/backport-create-issue +++ b/src/script/backport-create-issue @@ -14,7 +14,7 @@ # # Author: Loic Dachary # Author: Nathan Cutler -# +# # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the @@ -30,6 +30,7 @@ # import argparse import logging +import os import re import time from redminelib import Redmine # https://pypi.org/project/python-redmine/ @@ -38,6 +39,7 @@ redmine_endpoint = "https://tracker.ceph.com" project_name = "Ceph" release_id = 16 delay_seconds = 5 +redmine_key_file="~/.redmine_key" # # NOTE: release_id is hard-coded because # http://www.redmine.org/projects/redmine/wiki/Rest_CustomFields @@ -56,17 +58,17 @@ version2version_id = {} resolve_parent = None def usage(): - logging.error("Command-line arguments must include either a Redmine key (--key) " + logging.error("Redmine credentials are required to perform this operation. " + "Please provide either a Redmine key (via %s) " "or a Redmine username and password (via --user and --password). " "Optionally, one or more issue numbers can be given via positional " "argument(s). In the absence of positional arguments, the script " - "will loop through all issues in Pending Backport status.") + "will loop through all issues in Pending Backport status." % redmine_key_file) exit(-1) def parse_arguments(): parser = argparse.ArgumentParser() parser.add_argument("issue_numbers", nargs='*', help="Issue number") - parser.add_argument("--key", help="Redmine user key") parser.add_argument("--user", help="Redmine user") parser.add_argument("--password", help="Redmine password") parser.add_argument("--resolve-parent", help="Resolve parent issue if all backports resolved/rejected", @@ -100,12 +102,20 @@ def process_resolve_parent_option(a): logging.warning("Parent issues with all backports resolved/rejected will be marked Resolved") def connect_to_redmine(a): - if a.key: - logging.info("Redmine key was provided; using it") - return Redmine(redmine_endpoint, key=a.key) - elif a.user and a.password: + full_path=os.path.expanduser(redmine_key_file) + redmine_key='' + try: + with open(full_path, "r") as f: + redmine_key = f.read().strip() + except FileNotFoundError: + pass + + if a.user and a.password: logging.info("Redmine username and password were provided; using them") return Redmine(redmine_endpoint, username=a.user, password=a.password) + elif redmine_key: + logging.info("Redmine key was read from '%s'; using it" % redmine_key_file) + return Redmine(redmine_endpoint, key=redmine_key) else: usage()