forked from p15670423/monkey
Added script which changes the server_config to testing in travis so the default will be standard (for running)
This commit is contained in:
parent
59a779822b
commit
827c4942d9
|
@ -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.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"server_config": "testing",
|
||||
"deployment": "develop"
|
||||
"server_config": "standard",
|
||||
"deployment": "develop"
|
||||
}
|
||||
|
|
|
@ -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()
|
Loading…
Reference in New Issue