@plugin.route('/execution/', methods=['POST'])
def execution():
    execution_instance = {}
    if ('config_uuid' in request.form):
        config_uuid = request.form['config_uuid']
        config_entry = persistence['configuration'][config_uuid]
        execution_instance['config'] = config_entry
        use_https = (bool(config_entry['use_https']) if ('use_https' in config_entry) else None)
        method = (str(config_entry['method']).upper() if ('method' in config_entry) else None)
        hostname = (str(config_entry['hostname']) if ('hostname' in config_entry) else None)
        port = (int(config_entry['port']) if ('port' in config_entry) else None)
        path = (str(config_entry['path']) if ('path' in config_entry) else None)
        test_body = (config_entry['test_body'] if ('test_body' in config_entry) else None)
        test_header = (config_entry['test_header'] if ('test_header' in config_entry) else None)
        if ((use_https is not None) and method and hostname and port and path):
            protocol = 'http'
            if use_https:
                protocol += 's'
            target_url = f'{protocol}://{hostname}:{port}{path}'
            response = requests.request(method, target_url, headers=test_header, json=test_body)
            response_status = response.status_code
            execution_uuid = str(uuid.uuid4())
            execution_instance['uuid'] = execution_uuid
            execution_instance['target_url'] = target_url
            execution_instance['status'] = str(response_status)
            persistence['execution'][execution_uuid] = execution_instance
            execution_results_dir = os.path.join(storage_path, execution_uuid)
            os.makedirs(execution_results_dir)
            execution_json = os.path.join(execution_results_dir, 'execution.json')
            received_response = os.path.join(execution_results_dir, 'response.bin')
            with open(execution_json, 'w') as exec_json:
                exec_json.write(json.dumps(execution_instance))
            with open(received_response, 'wb') as response_bin:
                response_bin.write(pickle.dumps(response))
            with tempfile.NamedTemporaryFile() as tf:
                tmp_zip_file = shutil.make_archive(tf.name, 'zip', execution_results_dir)
                shutil.copy2(tmp_zip_file, os.path.join(execution_results_dir, result_zip_file_name))
            return (jsonify(execution_instance), 200)
        else:
            return ('Required configuration parameters are missing.', jsonify(config_entry), 400)
    else:
        return ('No configuration with that ID found.', jsonify(persistence), 404)
@plugin.route('/execution/', methods=['POST'])
def execution():
    execution_instance = {}
    if ('config_uuid' in request.form):
        config_uuid = request.form['config_uuid']
        config_entry = persistence['configuration'][config_uuid]
        execution_instance['config'] = config_entry
        use_https = (bool(config_entry['use_https']) if ('use_https' in config_entry) else None)
        method = (str(config_entry['method']).upper() if ('method' in config_entry) else None)
        hostname = (str(config_entry['hostname']) if ('hostname' in config_entry) else None)
        port = (int(config_entry['port']) if ('port' in config_entry) else None)
        path = (str(config_entry['path']) if ('path' in config_entry) else None)
        test_body = (config_entry['test_body'] if ('test_body' in config_entry) else None)
        test_header = (config_entry['test_header'] if ('test_header' in config_entry) else None)
        if ((use_https is not None) and method and hostname and port and path):
            protocol = 'http'
            if use_https:
                protocol += 's'
            target_url = f'{protocol}://{hostname}:{port}{path}'
            response = requests.request(method, target_url, headers=test_header, json=test_body)
            response_status = response.status_code
            execution_uuid = str(uuid.uuid4())
            execution_instance['uuid'] = execution_uuid
            execution_instance['target_url'] = target_url
            execution_instance['status'] = str(response_status)
            persistence['execution'][execution_uuid] = execution_instance
            execution_results_dir = os.path.join(storage_path, execution_uuid)
            os.makedirs(execution_results_dir)
            execution_json = os.path.join(execution_results_dir, 'execution.json')
            received_response = os.path.join(execution_results_dir, 'response.bin')
            with open(execution_json, 'w') as exec_json:
                exec_json.write(json.dumps(execution_instance))
            with open(received_response, 'wb') as response_bin:
                response_bin.write(pickle.dumps(response))
            with tempfile.NamedTemporaryFile() as tf:
                tmp_zip_file = shutil.make_archive(tf.name, 'zip', execution_results_dir)
                shutil.copy2(tmp_zip_file, os.path.join(execution_results_dir, result_zip_file_name))
            return (jsonify(execution_instance), 200)
        else:
            return ('Required configuration parameters are missing.', jsonify(config_entry), 400)
    else:
        return ('No configuration with that ID found.', jsonify(persistence), 404)