Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOLR-17438 Resolve committer GPG key from other source #3145

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions dev-tools/scripts/releaseWizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import scriptutil
from consolemenu import ConsoleMenu
from 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 mapping
java_versions = {6: 8, 7: 8, 8: 8, 9: 11, 10: 21}
Expand Down Expand Up @@ -307,6 +307,7 @@ def __init__(self, config_path, release_version, script_version):
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
Expand Down Expand Up @@ -406,6 +407,7 @@ def get_main_version(self):
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))
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion dev-tools/scripts/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ holidays~=0.16
ics~=0.7.2
console-menu~=0.7.1
PyGithub~=2.1.1
jira~=3.4.1
jira~=3.4.1
json
47 changes: 47 additions & 0 deletions dev-tools/scripts/scriptutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import urllib.error
import urllib.parse
import urllib.request
import json
from enum import Enum


Expand Down Expand Up @@ -82,6 +83,52 @@ def is_back_compat_with(self, other):
raise Exception('Back compat check disallowed for newer version: %s < %s' % (self, other))
return other.major + 1 >= self.major


"""
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.
"""
class CommitterPgp():
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}')


""" Resolve the PGP key fingerprint for the committer's ASF id """
def resolve(self):
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)
Expand Down
Loading