1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-12 08:56:13 +01:00

Migrate 'signkey' command to obs_api.Keyinfo

This commit is contained in:
Daniel Mach 2024-03-14 10:30:56 +01:00
parent e170b0d54c
commit b8ab16945e

View File

@ -9710,31 +9710,38 @@ Please submit there instead, or use --nodevelproject to force direct submission.
url = makeurl(apiurl, ['source', prj, "_pubkey"]) url = makeurl(apiurl, ['source', prj, "_pubkey"])
f = http_DELETE(url) f = http_DELETE(url)
else: else:
from . import obs_api
try: try:
# use current api, supporting fallback to higher project and server side scripts # use current api, supporting fallback to higher project and server side scripts
query = {} keyinfo = obs_api.Keyinfo.from_api(apiurl, prj)
if opts.sslcert: if opts.sslcert:
query['withsslcert'] = 1 for sslcert in keyinfo.sslcert_list or []:
url = makeurl(apiurl, ['source', prj, '_keyinfo'], query) print(sslcert.to_human_readable_string())
f = http_GET(url) print()
except HTTPError as e:
# old way to do it
while True:
try:
url = makeurl(apiurl, ['source', prj, '_pubkey'])
if opts.sslcert:
url = makeurl(apiurl, ['source', prj, '_project', '_sslcert'], 'meta=1')
f = http_GET(url)
break
except HTTPError as e:
l = prj.rsplit(':', 1)
# try key from parent project
if not opts.notraverse and len(l) > 1 and l[0] and l[1] and e.code == 404:
print(f'{prj} has no key, trying {l[0]}')
prj = l[0]
else: else:
for pubkey in keyinfo.pubkey_list or []:
print(pubkey.to_human_readable_string())
print()
return
except HTTPError as e:
if e.code != 404:
raise raise
# the _keyinfo endpoint doesn't exist, use the old _pubkey/_sslcert instead
if opts.sslcert:
result = obs_api.Keyinfo.get_sslcert_deprecated(apiurl, prj, traverse=not(opts.notraverse))
else:
result = obs_api.Keyinfo.get_pubkey_deprecated(apiurl, prj, traverse=not(opts.notraverse))
if result:
_, key = result
print(key)
return
while True: while True:
data = f.read(16384) data = f.read(16384)
if not data: if not data: