Beispiel #1
0
def main():
    """ Create logger and log some messages."""
    logger = redacted_logging.get_logger(__name__)
    logger.debug("Harmless debug Message")
    logger.info("Just an information")
    logger.warning("It's a Warning")
    logger.error("Did you try to divide by zero")
    logger.critical("Internet is down")

    # External libraries don't have privacy-preserving logging. We need to
    # wrap it in a try-except(-else) block so we can catch traceback messages.
    try:
        # We know this is a bad idea and will fail, so no warnings needed:
        # pylint: disable=import-outside-toplevel,import-error
        import unexisting_module
        unexisting_module.this_will_fail()
    except ModuleNotFoundError as expected_error:
        # Logging to console log and file log.
        logger.error("An expected error occured: %s", expected_error)

        # An exception will be redacted in the console log, but appears with
        # full traceback in the file log. Ideally use both statements for
        # full information.
        logger.exception("e %s", expected_error)

        # Here we can handle the error or `raise` it to pass it on.
        # Never raise exceptions in top-level scripts! This will generate
        # a traceback message that we then cannot redact.

    # Always catch remaining Exceptions in top-level scripts!
    # This way we can mask the traceback messages. Also, don't `raise` them,
    # or they will not be redacted.
    #
    # Catching Exception is very broad, so pylint would complain.
    # Disable this warning:
    # pylint: disable=broad-except
    except Exception as exception:
        logger.error("An unexpected error occured: %s", exception)
        logger.exception(exception)
    else:
        # Code in the else block is executed if no exceptions were raised.
        # Further exceptions from here on will be raised as usual.
        logger.info("Script would continue here if no exceptions were raised.")
        logger.info("You will never read this, because we forced exceptions.")

    logger.info("Script continues afterwards, if no exception was `raise`d.")
import time
start_time = time.time()

import json, yaml, sys
import shutil
import requests
import pp_enc
import redacted_logging as rlog
logger = rlog.get_logger(__name__)

#read input file
try:
    with open(r'/inputVolume/security_input.yaml') as file:
        inputYAML = yaml.load(file, Loader=yaml.FullLoader)
        logger.debug("Reading request.yaml file...")

    parties = inputYAML['parties']
    modelNames = inputYAML["modelNames"]

    receiver_url = inputYAML['receiver_url']
    if receiver_url != False:
        ### Read encrypted data files ###
        for p in parties:
            url = receiver_url + '/file/%s' % inputYAML["%sfileUUID" % (p)]
            response = requests.get(url, stream=True)
            with open('/data/%sData.enc' % (p), 'wb') as out_file:
                shutil.copyfileobj(response.raw, out_file)
            del response

            ### Read signed model files ###
        for m in modelNames: