Skip to content

Conversation

VakarisZ
Copy link
Contributor

@VakarisZ VakarisZ commented Nov 26, 2021

What does this PR do?

Fixes #1576

Add any further explanations here.

PR Checklist

  • Have you added an explanation of what your changes do and why you'd like to include them?
  • Is the TravisCI build passing?
  • Was the CHANGELOG.md updated to reflect the changes?
  • Was the documentation framework updated to reflect the changes?

Testing Checklist

  • Added relevant unit tests?

  • Have you successfully tested your changes locally? Elaborate:

    Tested by unit tests
    image
    Tested by building and running Docker with and without custom server_config.json
    Tested by building and running AppImage with and without custom server_config.json
    Tested by building monkey_island.exe(not MSI installer) and running it with server_config.json placed in CWD

  • If applicable, add screenshots or log transcripts of the feature working

Explain Changes

Are the commit messages enough? If not, elaborate.

Options removed match the defaults so there's no reason to keep them
…t tests for it

Since server_config.json no longer needs to be writable, we can load defaults, then override package specific options and lastly override user specified options to form the final config for island
On windows it's not easy to pass server_config as a commandline parameter. It's easier to just create a file in install directory.
@VakarisZ VakarisZ requested review from mssalvatore, shreyamalviya and ilija-lazoroski and removed request for mssalvatore and shreyamalviya November 26, 2021 14:59
…configuration.md page, which explains how to setup and use server_configuration.json

This change extracts server_config.json usage into a single page, which can then be referred to from any page that requires island configuration
@VakarisZ VakarisZ force-pushed the 1576-simplify-server-config-json branch from d411983 to 3e32dbb Compare November 26, 2021 15:08
@codecov
Copy link

codecov bot commented Nov 29, 2021

Codecov Report

Merging #1633 (1d7c80b) into develop (a3563b9) will increase coverage by 0.35%.
The diff coverage is 71.64%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1633      +/-   ##
===========================================
+ Coverage    44.75%   45.10%   +0.35%     
===========================================
  Files          460      459       -1     
  Lines        13398    13400       +2     
===========================================
+ Hits          5996     6044      +48     
+ Misses        7402     7356      -46     
Impacted Files Coverage Δ
monkey/monkey_island/cc/server_setup.py 0.00% <0.00%> (ø)
monkey/monkey_island/cc/server_utils/consts.py 92.85% <ø> (-0.25%) ⬇️
monkey/monkey_island/main.py 0.00% <0.00%> (ø)
monkey/monkey_island/cc/setup/config_setup.py 100.00% <100.00%> (+100.00%) ⬆️
monkey/monkey_island/cc/setup/data_dir.py 100.00% <100.00%> (ø)
...ey/monkey_island/cc/setup/island_config_options.py 100.00% <100.00%> (ø)
monkey/monkey_island/cc/arg_parser.py 45.45% <0.00%> (+45.45%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a3563b9...1d7c80b. Read the comment docs.

Comment on lines 59 to 60
except KeyError:
pass
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When would there ever be a KeyError? Shouldn't the .get() calls avoid this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Key error will happen when some config value is NOT provided in the server_config.json. We can't create IslandConfigOptions from the contents of the file, because unspecified options will get defaults. Then, how will we know if user provided a value that overrides package config OR was it just a default and we shouldn't override the package config with it?

Copy link
Collaborator

@mssalvatore mssalvatore Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I see. "." is the separator, not the default value.

Why don't we change the order of the calls in update(). Call self.__dict__.update(), then call self._expand_config_paths(). This way, we'll be guaranteed that all paths exist.


import monkey_island.cc.setup.config_setup # noqa: F401
from monkey_island.cc.arg_parser import IslandCmdArgs
from monkey_island.cc.server_setup import _extract_config
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing private/internal methods/functions is generally bad practice. Unit tests are for testing public interfaces.

Since _extract_config() is mostly just a wrapper around get_server_config(), let's just call that function instead. Then we can get rid of test_malformed_json() and simplify the call to create_server_config().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important to test what happens if the user provides a malformed JSON and it mostly uses the same fixtures to do so. I've tried splitting this up, but I don't think it's making this any more readable or maintainable, it just makes it more granular. I'm leaving it as it is.

@mssalvatore mssalvatore merged commit 47cdd7e into develop Dec 1, 2021
@mssalvatore mssalvatore deleted the 1576-simplify-server-config-json branch December 1, 2021 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Simplify handling of server_config.json
2 participants