Apache Solr open-source search software
SOLR-17438 ReleaseWizard to resolve committer GPG key from whimsy (#3145)
Jan Høydahl4acc1dfc5364
diff --git a/dev-tools/scripts/releaseWizard.py b/dev-tools/scripts/releaseWizard.pyindex e5dd6b835e7..d8d34d3409c 100755--- a/dev-tools/scripts/releaseWizard.py+++ b/dev-tools/scripts/releaseWizard.py@@ -65,7 +65,7 @@ except:import scriptutilfrom consolemenu import ConsoleMenufrom consolemenu.items import FunctionItem, SubmenuItem, ExitItem-from scriptutil import BranchType, Version, download, run+from scriptutil import BranchType, Version, download, run, CommitterPgp# Solr-to-Java version mappingjava_versions = {6: 8, 7: 8, 8: 8, 9: 11, 10: 21}@@ -307,6 +307,7 @@ class ReleaseState:self.set_latest_version()self.set_latest_lts_version()+def set_release_version(self, version):self.validate_release_version(self.script_branch_type, self.script_branch, version)self.release_version = version@@ -406,6 +407,7 @@ class ReleaseState:v = Version.parse(self.latest_version)return "%s.%s.%s" % (v.major + 1, 0, 0)+def validate_release_version(self, branch_type, branch, release_version):ver = Version.parse(release_version)# print("release_version=%s, ver=%s" % (release_version, ver))@@ -1167,20 +1169,12 @@ def configure_pgp(gpg_todo):id = str(input("Please enter your Apache id: (ENTER=skip) "))if id.strip() == '':return False- key_url = "https://home.apache.org/keys/committer/%s.asc" % id.strip()- committer_key = load(key_url)- lines = committer_key.splitlines()- keyid_linenum = None- for idx, line in enumerate(lines):- if line == 'ASF ID: %s' % id:- keyid_linenum = idx+1- break- if keyid_linenum:- keyid_line = lines[keyid_linenum]- assert keyid_line.startswith('LDAP PGP key: ')- gpg_fingerprint = keyid_line[14:].replace(" ", "")- gpg_id = gpg_fingerprint[-8:]- print("Found gpg key id %s on file at Apache (%s)" % (gpg_id, key_url))++ committer_pgp = CommitterPgp(id.strip())+ gpg_id = committer_pgp.get_short_fingerprint()+ gpg_fingerprint = committer_pgp.get_fingerprint()+ if gpg_id is not None:+ print("Found gpg key id %s on file at Apache" % gpg_id)else:print(textwrap.dedent("""\Could not find your GPG key from Apache servers.diff --git a/dev-tools/scripts/requirements.txt b/dev-tools/scripts/requirements.txtindex 1ef4fd25b45..efde9acc402 100644--- a/dev-tools/scripts/requirements.txt+++ b/dev-tools/scripts/requirements.txt@@ -5,4 +5,5 @@ holidays~=0.16ics~=0.7.2console-menu~=0.7.1PyGithub~=2.1.1-jira~=3.4.1\ No newline at end of file+jira~=3.4.1+json\ No newline at end of filediff --git a/dev-tools/scripts/scriptutil.py b/dev-tools/scripts/scriptutil.pyindex d272e4a20fd..6d1fb9bc851 100644--- a/dev-tools/scripts/scriptutil.py+++ b/dev-tools/scripts/scriptutil.py@@ -22,6 +22,7 @@ import timeimport urllib.errorimport urllib.parseimport urllib.request+import jsonfrom enum import Enum@@ -82,6 +83,52 @@ class Version(object):raise Exception('Back compat check disallowed for newer version: %s < %s' % (self, other))return other.major + 1 >= self.major++class CommitterPgp():+ """+ A class to resolve a commiter's committer's PGP key from ASF records.+ The class looks up the committer's ASF id in a json file downloaded from+ https://whimsy.apache.org/public/public_ldap_people.json+ and if the committer has a PGP key, it's fingerprint is made available.+ """+ def __init__(self, asf_id, json_content = None):+ self.asf_id = asf_id+ self.fingerprint = None+ self.ldap_url = 'https://whimsy.apache.org/public/public_ldap_people.json'+ self.fingerprint = None+ self.fingerprint_short = None+ if json_content:+ self.ldap_json = json_content+ else:+ self.ldap_json = self.load_ldap()+ self.resolve()+++ def load_ldap(self):+ try:+ with urllib.request.urlopen(self.ldap_url) as f:+ return json.load(f)+ except urllib.error.HTTPError as e:+ raise Exception(f'Failed to load {self.ldap_url}: {e}')+++ def resolve(self):+ """ Resolve the PGP key fingerprint for the committer's ASF id """+ try:+ self.fingerprint = self.ldap_json['people'][self.asf_id]['key_fingerprints'][0].replace(" ", "").upper()+ self.fingerprint_short = self.fingerprint[-8:]+ except KeyError:+ raise Exception(f'No PGP key found for {self.asf_id}')+++ def get_fingerprint(self):+ return self.fingerprint+++ def get_short_fingerprint(self):+ return self.fingerprint_short++def run(cmd, cwd=None):try:output = subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, cwd=cwd)