-
Notifications
You must be signed in to change notification settings - Fork 793
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
Fix error when removing uploaded post breach file on config reset #1054
Merged
mssalvatore
merged 3 commits into
guardicore:develop
from
shreyamalviya:bugfix_pba_file_delete
Apr 26, 2021
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4854c9c
Attempt to remove custom PBA file when resetting config only if filen…
shreyamalviya 4f94e9d
Break PBA file deletion into functions: attempt to delete PBA file in…
shreyamalviya 9b38303
Rearrange functions' order in `monkey_island/cc/resources/pba_file_up…
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
__author__ = "VakarisZ" | ||
|
||
LOG = logging.getLogger(__name__) | ||
# Front end uses these strings to identify which files to work with (linux of windows) | ||
# Front end uses these strings to identify which files to work with (linux or windows) | ||
LINUX_PBA_TYPE = "PBAlinux" | ||
WINDOWS_PBA_TYPE = "PBAwindows" | ||
|
||
|
@@ -69,13 +69,10 @@ def delete(self, file_type): | |
PBA_LINUX_FILENAME_PATH if file_type == "PBAlinux" else PBA_WINDOWS_FILENAME_PATH | ||
) | ||
filename = ConfigService.get_config_value(filename_path) | ||
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename) | ||
try: | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
if filename: | ||
file_path = Path(env_singleton.env.get_config().data_dir_abs_path).joinpath(filename) | ||
FileUpload._delete_file(file_path) | ||
ConfigService.set_config_value(filename_path, "") | ||
except OSError as e: | ||
LOG.error("Can't remove previously uploaded post breach files: %s" % e) | ||
|
||
return {} | ||
|
||
|
@@ -96,3 +93,11 @@ def upload_pba_file(request_, is_linux=True): | |
(PBA_LINUX_FILENAME_PATH if is_linux else PBA_WINDOWS_FILENAME_PATH), filename | ||
) | ||
return filename | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend putting this method immediately after the one that calls it so as to follow the Stepdown rule |
||
@staticmethod | ||
def _delete_file(file_path): | ||
try: | ||
if os.path.exists(file_path): | ||
os.remove(file_path) | ||
except OSError as e: | ||
LOG.error("Couldn't remove previously uploaded post breach files: %s" % e) |
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.
Regarding the value of adding tests, does this function behave in a sane way if I pass an invalid value for
file_type
?