Skip to content
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

Allow usage of environment variables in rules path #608

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nicogodet
Copy link
Contributor

After discussion with @Guts on IRC, this PR intends to allow usage of environment variables in rules path.

profile.json

{
    [...],
        "rules": [
        {
            "name": "MY_ENV_VAR exists",
            "description": "Deploy only if $env:MY_ENV_VAR exists",
            "conditions": {
                "all": [
                    {
                        "path": "$.env.MY_ENV_VAR",
                        "operator": "not_equal",
                        "value": ""
                    }
                ]
            }
        }
    ]
}

QdtRulesContext is modified :

  • Add property _context_env to return environment variables as dict
  • only_prefixed_variables boolean to control behavior of _context_env if it should return all variables or only filtered based on prefixes (default to True)
  • variables_prefix a list with allowed prefixes

TODO:

  • Control only_prefixed_variables and variables_prefix with 2 environment variables QDT_RULES_ONLY_PREFIXED_VARIABLES and QDT_RULES_VARIABLES_PREFIXES --> Easy and can be implemented in generic job class

  • Control only_prefixed_variables and variables_prefix in scenario.yml --> not trivial to me as other jobs need QdtRulesContext and default QdtRulesContext initialized in generic job will not contains altered only_prefixed_variables and variables_prefix

  • Tests

  • Documentation

Copy link

Copy link

codecov bot commented Jan 15, 2025

Codecov Report

Attention: Patch coverage is 80.00000% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
qgis_deployment_toolbelt/profiles/rules_context.py 80.00% 1 Missing and 1 partial ⚠️

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #608      +/-   ##
==========================================
- Coverage   70.63%   70.47%   -0.16%     
==========================================
  Files          47       47              
  Lines        3204     3214      +10     
  Branches      566      567       +1     
==========================================
+ Hits         2263     2265       +2     
- Misses        740      746       +6     
- Partials      201      203       +2     
Flag Coverage Δ
unittests 69.91% <80.00%> (-0.16%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
qgis_deployment_toolbelt/utils/str2bool.py 100.00% <ø> (ø)
qgis_deployment_toolbelt/profiles/rules_context.py 90.74% <80.00%> (-2.45%) ⬇️

... and 3 files with indirect coverage changes

@@ -14,6 +14,7 @@
# Standard library
import json
import logging
import os
Copy link
Collaborator

Choose a reason for hiding this comment

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

Prefer complete function import rather than package. See other projects modules where we work with env vars to make it consistent with.

only_prefixed_variables: bool = True,
variables_prefix: list[str] = ["QDT_", "QGIS_"],
) -> None:
self.only_prefixed_variables = only_prefixed_variables
Copy link
Collaborator

Choose a reason for hiding this comment

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

Docstring is missing

Returns:
dict: dict with environment variables to use in rules.
"""
env_vars = dict(os.environ)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's already a mapping object no?

https://docs.python.org/3/library/os.html#os.environ

@Guts
Copy link
Collaborator

Guts commented Jan 24, 2025

Hi @nicogodet,

We're pretty interested in your feature. @jmkerloch do you want to have a look?

@nicogodet
Copy link
Contributor Author

I would really like to have control over this settings in scenario.yml.

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.

2 participants