-
Notifications
You must be signed in to change notification settings - Fork 786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create data directory on Island initialisation #1170
Merged
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
76d82ce
Create `data_dir` if no `--server-config` is passed during Monkey Isl…
shreyamalviya 8246341
Create data dir if `--server-config` is passed, "data_dir" field exis…
shreyamalviya 808e86d
Create data_dir before logger is set up
shreyamalviya 9eedac4
Move `create_data_dir()` from monkey_island.py to monkey_island/cc/se…
shreyamalviya 805e5e6
Restructure code for creating default data directory and server config
shreyamalviya d8927a5
Create constant SERVER_CONFIG_FILENAME
shreyamalviya af42c01
Replace missed out function name
shreyamalviya ff1e6bd
Remove logic for creating default server config in appimage script
shreyamalviya a1beee9
Change data_dir permissions on Windows
shreyamalviya 3201672
Move `is_windows_os` to data_dir_generator.py and add user write
shreyamalviya e7a26aa
Rename `set_data_dir_security_to_read_by_owner()` to
shreyamalviya 8c575b9
Import Windows specific modules only on Windows
shreyamalviya 8ce506a
Refactored windows permission handling into a separate file
VakarisZ 409a3c5
Refactored code duplication by adding a parameter for create_data_dir
VakarisZ 2fb77fc
Get default directory depending on OS
shreyamalviya 37b7815
Move `is_windows_os()` to separate file
shreyamalviya dc129c0
Fix unit test in test_consts.py
shreyamalviya 4640a76
Update CHANGELOG (create data dir on island init)
shreyamalviya b4708fc
Import Windows specific modules only on Windows systems
shreyamalviya 9705c73
Remove code in environment_config.py which was calling `write_default…
shreyamalviya 23b0492
Remove unit test related to code removed in the previous commit
shreyamalviya 43d919a
Create default server_config.json when running unit tests
shreyamalviya 70b9a9f
Refactored config_loader.py and server_config_handler.py into a singl…
VakarisZ 8afe937
Improved monkey_island.py setup readability by extracting workflows o…
VakarisZ 5f88f6f
Moved a comment to a proper place
VakarisZ 3098ac1
Fixed a failing environment setup in unit tests
VakarisZ d33c5d6
Use `os.path.expandvars()` on server config argument
shreyamalviya f500ca8
Merge pull request #1184 from guardicore/data-dir-on-island-refactor
shreyamalviya 7d1c5dd
Merged develop into data-dir-on-island-init
VakarisZ 0a7cf1d
Improved readability in the arg_parser.py by extracting defaults to t…
VakarisZ 2b257f0
Fixed bugs merge bugs where structures are being accessed in an outda…
VakarisZ d273e85
Fixed bugs in argument parser passing default server config path even…
VakarisZ 3a800d9
Fixed a bug where models were getting imported without mongodb connec…
VakarisZ 9337c68
Removed the infrastructure from starting main.py - it can no longer b…
VakarisZ 057a579
Rolled back the changes that made default server config on model pack…
VakarisZ 5b7329b
Fixed stack-overflow that has been happening due to gevent unpatched …
VakarisZ 17e994c
Fixed UT's for models by mocking an environment singleton with needed…
VakarisZ a89a62c
Remove unneeded "noqa" statements
shreyamalviya baee74b
Add exception messages during data directory creation
shreyamalviya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,8 @@ | |
"environment": { | ||
"server_config": "password", | ||
"deployment": "standard" | ||
}, | ||
"mongodb": { | ||
"start_mongodb": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,8 @@ | |
"environment": { | ||
"server_config": "password", | ||
"deployment": "develop" | ||
}, | ||
"mongodb": { | ||
"start_mongodb": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import json | ||
from os.path import isfile | ||
|
||
from monkey_island.cc.server_utils.consts import DEFAULT_SERVER_CONFIG_PATH | ||
from monkey_island.setup.island_config_options import IslandConfigOptions | ||
|
||
|
||
def load_island_config_from_file(server_config_path: str) -> IslandConfigOptions: | ||
config_contents = read_config_file(server_config_path) | ||
return IslandConfigOptions(config_contents) | ||
|
||
|
||
def read_config_file(server_config_path: str) -> dict: | ||
if not server_config_path or not isfile(server_config_path): | ||
server_config_path = DEFAULT_SERVER_CONFIG_PATH | ||
with open(server_config_path, "r") as f: | ||
config_content = f.read() | ||
config = json.loads(config_content) | ||
return config |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from __future__ import annotations | ||
|
||
from monkey_island.cc.server_utils.consts import ( | ||
DEFAULT_DATA_DIR, | ||
DEFAULT_LOG_LEVEL, | ||
DEFAULT_START_MONGO_DB, | ||
) | ||
|
||
|
||
class IslandConfigOptions: | ||
def __init__(self, config_contents: dict): | ||
self.data_dir = config_contents.get("data_dir", DEFAULT_DATA_DIR) | ||
|
||
self.log_level = config_contents.get("log_level", DEFAULT_LOG_LEVEL) | ||
|
||
self.start_mongodb = config_contents.get( | ||
"mongodb", {"start_mongodb": DEFAULT_START_MONGO_DB} | ||
).get("start_mongodb", DEFAULT_START_MONGO_DB) |
2 changes: 2 additions & 0 deletions
2
monkey/tests/data_for_tests/server_configs/server_config_empty.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{ | ||
} |
File renamed without changes.
27 changes: 0 additions & 27 deletions
27
monkey/tests/unit_tests/monkey_island/cc/environment/test_server_config_handler.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +0,0 @@ | ||
import os | ||
|
||
from monkey_island.cc.environment import server_config_handler | ||
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR | ||
|
||
|
||
def test_load_server_config_from_file(test_server_config, mock_home_env): | ||
config = server_config_handler.load_server_config_from_file(test_server_config) | ||
|
||
assert config["data_dir"] == os.path.join(mock_home_env, ".monkey_island") | ||
assert config["log_level"] == "NOTICE" | ||
|
||
|
||
def test_default_log_level(): | ||
test_config = {} | ||
config = server_config_handler.add_default_values_to_config(test_config) | ||
|
||
assert "log_level" in config | ||
assert config["log_level"] == "INFO" | ||
|
||
|
||
def test_default_data_dir(mock_home_env): | ||
test_config = {} | ||
config = server_config_handler.add_default_values_to_config(test_config) | ||
|
||
assert "data_dir" in config | ||
assert config["data_dir"] == DEFAULT_DATA_DIR | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
You are viewing a condensed version of this merge commit. You can view the full changes here.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we deliberately removing this or is this part of the rebase mess?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This commit also removes
monkey/tests/unit_tests/monkey_island/cc/environment/test_server_config_handler.py
as part of the rebase. Depending on this comment, we need to re-add/modify this file too.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deliberately. Config is now built in
island_config_options.py
.