-
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
Conversation
DeepCode's analysis on #baee74 found:
Top issues
👉 View analysis in DeepCode’s Dashboard | Configure the bot |
Codecov Report
@@ Coverage Diff @@
## develop #1170 +/- ##
===========================================
- Coverage 28.94% 28.80% -0.15%
===========================================
Files 419 424 +5
Lines 12797 12863 +66
===========================================
+ Hits 3704 3705 +1
- Misses 9093 9158 +65
Continue to review full report at Codecov.
|
8137313
to
81f6af7
Compare
9cc4d23
to
b925113
Compare
…and initialisation
…ts, but the dir doesn't exist
permissions to newly created data directory
`set_data_dir_security_to_read_and_write_by_owner`
…_server_config_to_file()` This was causing an error in the unit tests, and is handled in monkey_island.py (commit 3de620e).
378f8ed
to
23b0492
Compare
def create_default_config_file(path): | ||
def create_default_server_config_file() -> str: | ||
if not os.path.isfile(DEFAULT_SERVER_CONFIG_PATH): | ||
create_data_dir(DEFAULT_DATA_DIR, False) |
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.
I'm sorry, but I still don't understand what's wrong with using os.makedirs
here. The explanation of $HOME
might not be resolved doesn't make sense. It's the responsibility of DEFAULT_DATA_DIR
to point to a resolvable path. And if DEFAULT_DATA_DIR
can't be resolved, how will not making parent directories help us?
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.
For example, on Linux, if the $HOME env variable doesn't exist, the value of DEFAULT_DATA_DIR
will remain "$HOME/.monkey_island" (we're using os.path.expandvars()
to resolve the path but in case nothing is resolved, it will simply return the same string, it won't throw any kind of error). Using os.makedirs
will create a directory named "$HOME" and the ".monkey_island" directory under that. Creating a directory named "$HOME" is not the expected behaviour. If the $HOME variable can't be resolved, we expect the user to specify the path for the data directory.
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.
If the $HOME variable can't be resolved, we expect the user to specify the path for the data directory.
How is this expressed in the code and where? Users and developers are expected to get os.mkdir
error and know that os.mkdir
failed because it doesn't create parent folders, so it means that the parent folder of data_dir
is not present?
What prevents the user from making the same mistake via cmd arguments?
Wouldn't it be better to
if not os.path.isdir(data_dir_parent):
logger.error(f"Can't create a data directory because path {data_dir_parent} doesn't exist. Specify a reachable directory with {data_dir_flag}")
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.
See baee74b7
monkey/monkey_island.py
Outdated
|
||
config = config_loader.load_server_config_from_file(server_config_path) | ||
|
||
create_data_dir(config["data_dir"], True) |
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 line only makes sense if island_args.server_config
, because otherwise you create the dir in server_config_generator.create_default_server_config_file()
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.
Fixed in #1184
…e file, with server config write/read operations
…f server_config setup by cmd_arguments and setup of server_config using defaults
Data dir on island refactor
…he argparser flag section
… though server path is not specified. Island thinks that server config path was specified.
…e the entrypoint to the application
… mongodb parameters
add_default_values_to_config(config) | ||
|
||
return config | ||
|
||
|
||
def add_default_values_to_config(config): | ||
config["data_dir"] = os.path.abspath( | ||
os.path.expanduser(os.path.expandvars(config.get("data_dir", DEFAULT_DATA_DIR))) | ||
) | ||
|
||
config.setdefault("log_level", DEFAULT_LOG_LEVEL) | ||
|
||
return config |
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
.
Fixes #1147
(Still need to figure out Windows permissions!)PR Checklist
Was the documentation framework updated to reflect the changes?Testing Checklist
If applicable, add screenshots or log transcripts of the feature working