def add_gateway_txn(): """ Generates an add_gateway_txn if a destination name and wallets are defined and valid. Diagnostics report will be in the format below if successful. https://docs.helium.com/mine-hnt/full-hotspots/become-a-maker/hotspot-integration-testing/#generate-an-add-hotspot-transaction { errors: [], DESTINATION_ADD_GATEWAY_TXN_KEY: { "address": "11TL62V8NYvSTXmV5CZCjaucskvNR1Fdar1Pg4Hzmzk5tk2JBac", "fee": 65000, "owner": "14GWyFj9FjLHzoN3aX7Tq7PL6fEg4dfWPY8CrK8b9S5ZrcKDz6S", "payer": "138LbePH4r7hWPuTnK6HXVJ8ATM2QU71iVHzLTup1UbnPDvbxmr", "staking fee": 4000000, "txn": "CrkBCiEBrlImpYLbJ0z0hw5b4g9isRyPrgbXs9X+RrJ4pJJc9MkS..." } } """ shipping_destination_with_signature = request.get_data() if not shipping_destination_with_signature: err_msg = 'Can not find payload.' LOGGER.error(err_msg) diagnostics_report = compose_diagnostics_report_from_err_msg( DESTINATION_ADD_GATEWAY_TXN_KEY, err_msg) return diagnostics_report, 406 diagnostics = [ AddGatewayTxnDiagnostic(GnuPG(), shipping_destination_with_signature), ] diagnostics_report = DiagnosticsReport(diagnostics) diagnostics_report.perform_diagnostics() if diagnostics_report.has_errors({DESTINATION_ADD_GATEWAY_TXN_KEY}): http_code = 500 else: http_code = 200 LOGGER.debug("add_gateway_txn result: %s" % diagnostics_report) return diagnostics_report, http_code
def shutdown_gateway(): """ Shuts down the gateway using the Balena supervisor API. Requires a signed PGP payload to be supplied in the format: -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 { "shutdown_gateway": true } -----BEGIN PGP SIGNATURE----- [REDACTED] -----END PGP SIGNATURE----- """ shutdown_request_with_signature = request.get_data() if not shutdown_request_with_signature: err_msg = 'Can not find PGP payload.' LOGGER.error(err_msg) diagnostics_report = compose_diagnostics_report_from_err_msg( SHUTDOWN_GATEWAY_KEY, err_msg) return diagnostics_report, 406 diagnostics = [ ShutdownGatewayDiagnostic(GnuPG(), shutdown_request_with_signature), ] diagnostics_report = DiagnosticsReport(diagnostics) diagnostics_report.perform_diagnostics() if diagnostics_report.has_errors({SHUTDOWN_GATEWAY_KEY}): http_code = 500 else: http_code = 200 LOGGER.debug("shutdown_gateway result: %s" % diagnostics_report) return diagnostics_report, http_code