diff options
author | Tiago Gomes <tiago.avv@gmail.com> | 2018-08-02 12:10:29 +0000 |
---|---|---|
committer | Tiago Gomes <tiago.avv@gmail.com> | 2018-08-02 12:10:29 +0000 |
commit | 8656a65d21bd002b1fd490481e736f1748e8db86 (patch) | |
tree | a54839da778fc48c22fac07c4d64fa8dc7e3ed93 /buildstream/plugin.py | |
parent | 039d43e43431957a42193f12f06acb7b95c2eae4 (diff) | |
parent | 9f0c8fcfe348533987ec128b85356655edae77f4 (diff) | |
download | buildstream-Qinusty/490-artifact-cache-interactivity.tar.gz |
Merge branch 'tiagogomes/issue-195' into 'master'Qinusty/490-artifact-cache-interactivity
Add validation for project paths
See merge request BuildStream/buildstream!593
Diffstat (limited to 'buildstream/plugin.py')
-rw-r--r-- | buildstream/plugin.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/buildstream/plugin.py b/buildstream/plugin.py index 155a9500e..836b60834 100644 --- a/buildstream/plugin.py +++ b/buildstream/plugin.py @@ -1,5 +1,5 @@ # -# Copyright (C) 2017 Codethink Limited +# Copyright (C) 2018 Codethink Limited # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -335,6 +335,51 @@ class Plugin(): """ return _yaml.node_get(node, expected_type, member_name, default_value=default) + def node_get_project_path(self, node, key, *, + check_is_file=False, check_is_dir=False): + """Fetches a project path from a dictionary node and validates it + + Paths are asserted to never lead to a directory outside of the + project directory. In addition, paths can not point to symbolic + links, fifos, sockets and block/character devices. + + The `check_is_file` and `check_is_dir` parameters can be used to + perform additional validations on the path. Note that an + exception will always be raised if both parameters are set to + ``True``. + + Args: + node (dict): A dictionary loaded from YAML + key (str): The key whose value contains a path to validate + check_is_file (bool): If ``True`` an error will also be raised + if path does not point to a regular file. + Defaults to ``False`` + check_is_dir (bool): If ``True`` an error will also be raised + if path does not point to a directory. + Defaults to ``False`` + + Returns: + (str): The project path + + Raises: + :class:`.LoadError`: In the case that the project path is not + valid or does not exist + + *Since: 1.2* + + **Example:** + + .. code:: python + + path = self.node_get_project_path(node, 'path') + + """ + + return _yaml.node_get_project_path(node, key, + self.__project.directory, + check_is_file=check_is_file, + check_is_dir=check_is_dir) + def node_validate(self, node, valid_keys): """This should be used in :func:`~buildstream.plugin.Plugin.configure` implementations to assert that users have only entered |