Skip to content

Commit

Permalink
[Documentation][validation] Add docstrings to module_utils/validation…
Browse files Browse the repository at this point in the history
….py (#1336)

* Add docstrings to module_utils/validation.py

* Create changelog fragment

* Modify google style to numpy

* Standarize numpy style
  • Loading branch information
IsaacVRey authored Apr 19, 2024
1 parent 46a21d2 commit e2a574f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelogs/fragments/1336-update-docstring-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trivial:
- validation - Updated docstrings to numpy style for visual aid to developers.
(https://github.com/ansible-collections/ibm_zos_core/pull/1336).
30 changes: 28 additions & 2 deletions plugins/module_utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,25 @@


def validate_safe_path(path):
"""
This function is implemented to validate against path traversal attack
"""This function is implemented to validate against path traversal attack
when using os.path.join function.
In this action plugin, path is on the controller.
Parameters
----------
path : str
A file's path.
Returns
-------
str
The introduced path.
Raises
------
DirectoryTraversalError
User does not have access to a directory.
"""
if not os.path.isabs(path):
real_path = os.path.realpath(path)
Expand All @@ -39,6 +53,18 @@ def validate_safe_path(path):


class DirectoryTraversalError(Exception):
"""User does not have access to a directory.
Parameters
----------
path : str
Directory path.
Attributes
----------
msg : str
Human readable string describing the exception.
"""
def __init__(self, path):
self.msg = "Detected directory traversal, user does not have access to {0}".format(path)
super().__init__(self.msg)

0 comments on commit e2a574f

Please sign in to comment.