-
Notifications
You must be signed in to change notification settings - Fork 26
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: Escaping Jinja logical statements from assets #205
Merged
Merged
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
145b8fc
fix: Escaping Jinja logical statements from assets
Vitor-Avila 78d003f
Improving Jinja test query
Vitor-Avila 43d5602
Merge pull request #1 from Vitor-Avila/jinja-flags
Vitor-Avila 88c8d1e
Update README.rst
Vitor-Avila a39b162
Merge pull request #2 from Vitor-Avila/Vitor-Avila-patch-1
Vitor-Avila 6d672b7
Fixing pylint issues
Vitor-Avila e3df8cf
Merge pull request #3 from Vitor-Avila/pylint-fix
Vitor-Avila f558638
small nit
Vitor-Avila 0e85232
Merge pull request #4 from Vitor-Avila/small-nit
Vitor-Avila 5ce7402
Merge branch 'main' into main
Vitor-Avila 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
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
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 |
---|---|---|
|
@@ -80,6 +80,16 @@ def is_yaml_config(path: Path) -> bool: | |
) | ||
|
||
|
||
def load_yaml(path: Path) -> Dict[str, Any]: | ||
""" | ||
Load a YAML file and returns it as a dictionary. | ||
""" | ||
with open(path, encoding="utf-8") as input_: | ||
content = input_.read() | ||
|
||
return yaml.load(content, Loader=yaml.SafeLoader) | ||
|
||
|
||
def render_yaml(path: Path, env: Dict[str, Any]) -> Dict[str, Any]: | ||
""" | ||
Load a YAML file as a template, render it, and deserialize it. | ||
|
@@ -108,6 +118,12 @@ def render_yaml(path: Path, env: Dict[str, Any]) -> Dict[str, Any]: | |
multiple=True, | ||
help="Custom values for templates (eg, country=BR)", | ||
) | ||
@click.option( | ||
"--disable-jinja-templating", | ||
is_flag=True, | ||
default=False, | ||
help="By default, the CLI supports Jinja templating. This flag disables it", | ||
) | ||
@click.option( | ||
"--disallow-edits", | ||
is_flag=True, | ||
|
@@ -130,11 +146,12 @@ def render_yaml(path: Path, env: Dict[str, Any]) -> Dict[str, Any]: | |
help="Split imports into individual assets", | ||
) | ||
@click.pass_context | ||
def native( # pylint: disable=too-many-locals, too-many-arguments | ||
def native( # pylint: disable=too-many-locals, too-many-arguments, too-many-branches | ||
ctx: click.core.Context, | ||
directory: str, | ||
option: Tuple[str, ...], | ||
overwrite: bool = False, | ||
disable_jinja_templating: bool = False, | ||
disallow_edits: bool = True, # pylint: disable=unused-argument | ||
external_url_prefix: str = "", | ||
load_env: bool = False, | ||
|
@@ -171,11 +188,17 @@ def native( # pylint: disable=too-many-locals, too-many-arguments | |
if path_name.is_dir() and not path_name.stem.startswith("."): | ||
queue.extend(path_name.glob("*")) | ||
elif is_yaml_config(relative_path): | ||
config = render_yaml(path_name, env) | ||
if disable_jinja_templating: | ||
config = load_yaml(path_name) | ||
else: | ||
config = render_yaml(path_name, env) | ||
|
||
overrides_path = path_name.with_suffix(".overrides" + path_name.suffix) | ||
if overrides_path.exists(): | ||
overrides = render_yaml(overrides_path, env) | ||
if disable_jinja_templating: | ||
overrides = load_yaml(overrides_path) | ||
else: | ||
overrides = render_yaml(overrides_path, env) | ||
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. Same here. 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. changed this one as well. |
||
dict_merge(config, overrides) | ||
|
||
config["is_managed_externally"] = disallow_edits | ||
|
Oops, something went wrong.
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.
Small nit:
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.
thanks! changed as suggested