def set_config(): """ Set the current configuration If the collector has not been previously initialized (due to no configuration at start up) a new configuration file is written to disk and then passed to a new instance of the collector :return: JSON dictionary with a Status of OK if successful """ global collector if not request.json: abort(400) if not collector: buffer = tempfile.NamedTemporaryFile(delete=False) buffer.write(json.dumps(request.json)) buffer.close() args.config = buffer.name collector = execute_tool(args, test_mode=True) else: resp = collector.save_config(request.json) if resp != 'OK': abort(400) collector.reload_config() return json.dumps({'Status': 'OK'}, indent=4, separators=(',', ':'))
DEFAULT_PORT = '5000' DEFAULT_IPADDRESS = '127.0.0.1' auth = HTTPBasicAuth() parser = get_arg_parser() parser.add_argument('--ip', default=DEFAULT_IPADDRESS, help='IP address to listen on.') parser.add_argument('--port', default=DEFAULT_PORT, help='Port number to listen on.') args = parser.parse_args() collector = execute_tool(args, test_mode=True) app = Flask(__name__) @auth.get_password def get_password(username): if username == 'admin': return 'acitoolkit' return None @auth.error_handler def unauthorized(): return make_response(jsonify({'error': 'Unauthorized access'}), 401)