1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-12 00:46:14 +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,30 +9710,37 @@ 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()
else:
for pubkey in keyinfo.pubkey_list or []:
print(pubkey.to_human_readable_string())
print()
return
except HTTPError as e: except HTTPError as e:
# old way to do it if e.code != 404:
while True: raise
try:
url = makeurl(apiurl, ['source', prj, '_pubkey']) # the _keyinfo endpoint doesn't exist, use the old _pubkey/_sslcert instead
if opts.sslcert:
url = makeurl(apiurl, ['source', prj, '_project', '_sslcert'], 'meta=1') if opts.sslcert:
f = http_GET(url) result = obs_api.Keyinfo.get_sslcert_deprecated(apiurl, prj, traverse=not(opts.notraverse))
break else:
except HTTPError as e: result = obs_api.Keyinfo.get_pubkey_deprecated(apiurl, prj, traverse=not(opts.notraverse))
l = prj.rsplit(':', 1) if result:
# try key from parent project _, key = result
if not opts.notraverse and len(l) > 1 and l[0] and l[1] and e.code == 404: print(key)
print(f'{prj} has no key, trying {l[0]}')
prj = l[0] return
else:
raise
while True: while True:
data = f.read(16384) data = f.read(16384)