diff --git a/.travis.yml b/.travis.yml index b05dfbe94..06511e74b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,11 +5,12 @@ python: - 3.7 install: - pip install -r monkey/monkey_island/requirements.txt -- pip install flake8 pytest dlint +- pip install flake8 pytest dlint pylint - pip install -r monkey/infection_monkey/requirements_linux.txt before_script: - flake8 . --count --select=E901,E999,F821,F822,F823 --show-source --statistics - flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics +- monkey/monkey_island/cc/set_server_config.py testing script: - cd monkey # This is our source dir - python -m pytest # Have to use `python -m pytest` instead of `pytest` to add "{$builddir}/monkey/monkey" to sys.path. diff --git a/monkey/monkey_island/cc/server_config.json b/monkey/monkey_island/cc/server_config.json index 7bf106194..0b28d0b74 100644 --- a/monkey/monkey_island/cc/server_config.json +++ b/monkey/monkey_island/cc/server_config.json @@ -1,4 +1,4 @@ { - "server_config": "testing", - "deployment": "develop" + "server_config": "standard", + "deployment": "develop" } diff --git a/monkey/monkey_island/cc/set_server_config.py b/monkey/monkey_island/cc/set_server_config.py new file mode 100644 index 000000000..fc20747c9 --- /dev/null +++ b/monkey/monkey_island/cc/set_server_config.py @@ -0,0 +1,46 @@ +import argparse +import json +import logging +from pathlib import Path + +SERVER_CONFIG = "server_config" + +logger = logging.getLogger(__name__) +logger.addHandler(logging.StreamHandler()) +logger.setLevel(logging.DEBUG) + + +def main(): + args = parse_args() + file_path = get_config_file_path(args) + + # Read config + with open(file_path) as config_file: + config_data = json.load(config_file) + + # Edit the config + config_data[SERVER_CONFIG] = args.server_config + + # Write new config + logger.info("Writing the following config: {}".format(json.dumps(config_data, indent=4))) + with open(file_path, "w") as config_file: + json.dump(config_data, config_file, indent=4) + config_file.write("\n") # Have to add newline at end of file, since json.dump does not. + + +def get_config_file_path(args): + file_path = Path(__file__).parent.joinpath(args.file_name) + logger.info("Config file path: {}".format(file_path)) + return file_path + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("server_config", choices=["standard", "testing", "password"]) + parser.add_argument("-f", "--file_name", required=False, default="server_config.json") + args = parser.parse_args() + return args + + +if __name__ == '__main__': + main()