|
5 | 5 | # SPDX-License-Identifier: BSD-2-Clause |
6 | 6 |
|
7 | 7 | import argparse |
| 8 | +import json |
8 | 9 | import os |
9 | 10 | import pathlib |
10 | 11 | import shutil |
@@ -301,29 +302,42 @@ def core_sign(fs, args): |
301 | 302 |
|
302 | 303 | def core_publish(fs, args): |
303 | 304 | core = _get_core(fs, args.core) |
304 | | - logger.info("publish core file: " + core.core_file) |
305 | | - logger.info("to api at: " + args.url) |
306 | | - if args.sigfile: |
307 | | - logger.info("including sigfile: " + args.sigfile) |
| 305 | + uri = fs.config.publish_uri |
| 306 | + pem = fs.config.publish_uri_pem |
| 307 | + sigfile = core.core_file + ".sig" |
| 308 | + print("Publish core file: " + core.core_file) |
| 309 | + fob_core = open(core.core_file, "rb") |
| 310 | + body = {"core_file": fob_core} |
| 311 | + fob_sig = None |
| 312 | + if os.path.exists(sigfile): |
| 313 | + print("and signature file: " + sigfile) |
| 314 | + fob_sig = open(sigfile, "rb") |
| 315 | + body["signature_file"] = fob_sig |
308 | 316 | else: |
309 | | - logger.info("no sigfile") |
310 | | - |
311 | | - file = open(core.core_file) |
312 | | - cf_data = file.read() |
313 | | - file.close() |
314 | | - body = {"core_file": cf_data} |
315 | | - if args.sigfile: |
316 | | - file = open(args.sigfile) |
317 | | - sf_data = file.read() |
318 | | - file.close() |
319 | | - body["signature_file"] = sf_data |
320 | | - res = requests.post( |
321 | | - args.url + "/api/fusesoc-packages/publish/", json=body, allow_redirects=True |
322 | | - ) |
323 | | - logger.info("Got: " + str(res)) |
| 317 | + print("(without signature file)") |
| 318 | + sf_data = None |
| 319 | + if pem: |
| 320 | + print("with certificate from: " + pem) |
| 321 | + print("to api at: " + uri) |
| 322 | + if args.yes: |
| 323 | + print("without confirmation") |
| 324 | + else: |
| 325 | + c = input("Confirm by typing 'yes': ") |
| 326 | + if c != "yes": |
| 327 | + print("Aborted.") |
| 328 | + return False |
| 329 | + |
| 330 | + target = uri + "/v1/publish/" |
| 331 | + logger.debug("POST to " + target) |
| 332 | + res = requests.post(target, files=body, allow_redirects=True, verify=pem) |
324 | 333 | if not res.ok: |
325 | 334 | print("Request returned http result", res.status_code, res.reason) |
| 335 | + err = json.loads(res.content) |
| 336 | + print(str(err)) |
326 | 337 | res.close() |
| 338 | + fob_core.close() |
| 339 | + if fob_sig: |
| 340 | + fob_sig.close() |
327 | 341 |
|
328 | 342 |
|
329 | 343 | def gen_clean(fs, args): |
|
0 commit comments