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

Add Variable Replacement Support in Tirith Policies #171

Merged
merged 6 commits into from
Sep 30, 2024

Conversation

samriddhi99
Copy link
Contributor

Solves #130
This PR introduces functionality to replace variables in Tirith policies with values from a provided dictionary. The replacement is currently applied only within the evaluators. The new replace_vars function uses regex to identify and substitute variables in provider_args and condition fields.

src/tirith/core/policy_parameterization.py Outdated Show resolved Hide resolved
src/tirith/core/policy_parameterization.py Outdated Show resolved Hide resolved
Copy link
Member

@refeed refeed left a comment

Choose a reason for hiding this comment

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

Hi Samriddhi, so I just had a discussion with @Akshat0694 and @arunim2405 . So here are a few things that we decided:

  1. we'll also include the meta and the final_evaluator part of the policy to be parametrized. Reason: evaluators is already the hugest part of the policy, adding meta, and final_evaluator key won't hurt the performance so much
  2. pydash.get() already supports syntax like foo.bar[2], could you test this locally? or even better, you could create unittests for these functions

@refeed refeed force-pushed the parameterize-policies branch 4 times, most recently from 9898bb1 to c7bc6dd Compare September 4, 2024 07:26
@refeed refeed force-pushed the parameterize-policies branch from c7bc6dd to 485740b Compare September 4, 2024 09:32
Copy link

sonarcloud bot commented Sep 4, 2024

@refeed
Copy link
Member

refeed commented Sep 4, 2024

I'll squash the commits once it's been reviewed and marked as good to go

@AkashS0510
Copy link
Collaborator

@refeed Can you add me as a reviewer?

@AkashS0510
Copy link
Collaborator

@refeed @samriddhi99 LGTM.

@refeed
Copy link
Member

refeed commented Sep 17, 2024

Thanks for the review @AkashS0510!

@AkashS0510 AkashS0510 self-requested a review September 25, 2024 13:02
Copy link
Collaborator

@AkashS0510 AkashS0510 left a comment

Choose a reason for hiding this comment

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

LGTM!

@AkashS0510 AkashS0510 merged commit b9e7586 into main Sep 30, 2024
15 checks passed
@AkashS0510 AkashS0510 deleted the parameterize-policies branch September 30, 2024 15:28
tejasvi541 added a commit to tejasvi541/tirith-local that referenced this pull request Oct 4, 2024
Fix: corrected the file name __init__.py

Signed-off-by: pravo23 <[email protected]>

Enhance GitHub Actions Workflow with PR Triggers (StackGuardian#148)

* Add PR triggers to github actions workflow

* Update lint.yml
Centralized version definition to simplify version management (StackGuardian#142)

Co-authored-by: Rafid Aslam <[email protected]>
Update build_test.yml (StackGuardian#149)

* Update build_test.yml

* Update lint.yml
Update logger initialization to use module-specific loggers StackGuardian#140

Changed "logger = logging.getLogger()" line of code to "logger = logging.getLogger(__name__)" in all files

Removed the TODO Comments - "# TODO: At least add __name__ as the name for the logger" in all files
StackGuardian#140

Removed RESULTS text from error

Resolved - Generalize the function get_path_value_from_dict

Refactor get_path_value_from_dict

Moved get_path_value_from_dict to common.py.
Refactored Kubernetes and JSON handler files to import from common.py.

Updated Common.py

Fix linting (StackGuardian#167)

Add a getting started guide in README.md (StackGuardian#139)

* Add a getting started guide in README.md

* Add description of getting started activity, and some minor fixes
Add maintainers in README and CODEOWNERS file

Add additional rules and guidelines to contributing.md

Add examples for commit messages and guidelines for solving issues

Update CONTRIBUTING.md with guidelines about solving issues

Add separate heading about solving issues, and add examples for writing descriptions in commit changes
setup the docs base (StackGuardian#177)

* created the template for the official documentation

* setting up the environment

* cleaned up the documentation setup

* adjusted the color scheme

* setup the basic pages for the tirith documentation

* updated the intro page
Add dev container

Add dev container

Closes StackGuardian#175

Update Readme.MD

Simplify type checking in sort_collections()

Closes StackGuardian#185

Add Variable Replacement Support in Tirith Policies (StackGuardian#171)

* Add support for parameterizing Tirith policies

* Use pydash.get() and check for match only if the value is of type str

* Add variable replacement for meta and eval_expression in a policy

* Add unit tests for policy parameterization, change return type for cases where the path was not found, and change syntax of entering the variable names

* Fix linting

* tirith parametrization

---------

Co-authored-by: Rafid Aslam <[email protected]>
Removed RESULTS text from error

Resolved - Generalize the function get_path_value_from_dict

Refactor get_path_value_from_dict

Moved get_path_value_from_dict to common.py.
Refactored Kubernetes and JSON handler files to import from common.py.

Updated Common.py

Fix linting (StackGuardian#167)

Add a getting started guide in README.md (StackGuardian#139)

* Add a getting started guide in README.md

* Add description of getting started activity, and some minor fixes
Add maintainers in README and CODEOWNERS file

Add additional rules and guidelines to contributing.md

Add examples for commit messages and guidelines for solving issues

Update CONTRIBUTING.md with guidelines about solving issues

Add separate heading about solving issues, and add examples for writing descriptions in commit changes

Merge branch 'main' of https://github.com/StackGuardian/tirith
refeed pushed a commit that referenced this pull request Oct 15, 2024
* Requested Changes

- Changed some variable names to snake case

- Removed unused imports from cli.py

- Added Some dev dependencies like autopep8 and pylint for effective searches will remove before final commit

- Added a custom py file to filter pylint logs, will remove before final commit

* removed filter script and logs, and changed names where's its needed

* Add installation instruction to README.md

Fix: corrected the file name __init__.py

Signed-off-by: pravo23 <[email protected]>

Enhance GitHub Actions Workflow with PR Triggers (#148)

* Add PR triggers to github actions workflow

* Update lint.yml
Centralized version definition to simplify version management (#142)

Co-authored-by: Rafid Aslam <[email protected]>
Update build_test.yml (#149)

* Update build_test.yml

* Update lint.yml
Update logger initialization to use module-specific loggers #140

Changed "logger = logging.getLogger()" line of code to "logger = logging.getLogger(__name__)" in all files

Removed the TODO Comments - "# TODO: At least add __name__ as the name for the logger" in all files
#140

Removed RESULTS text from error

Resolved - Generalize the function get_path_value_from_dict

Refactor get_path_value_from_dict

Moved get_path_value_from_dict to common.py.
Refactored Kubernetes and JSON handler files to import from common.py.

Updated Common.py

Fix linting (#167)

Add a getting started guide in README.md (#139)

* Add a getting started guide in README.md

* Add description of getting started activity, and some minor fixes
Add maintainers in README and CODEOWNERS file

Add additional rules and guidelines to contributing.md

Add examples for commit messages and guidelines for solving issues

Update CONTRIBUTING.md with guidelines about solving issues

Add separate heading about solving issues, and add examples for writing descriptions in commit changes
setup the docs base (#177)

* created the template for the official documentation

* setting up the environment

* cleaned up the documentation setup

* adjusted the color scheme

* setup the basic pages for the tirith documentation

* updated the intro page
Add dev container

Add dev container

Closes #175

Update Readme.MD

Simplify type checking in sort_collections()

Closes #185

Add Variable Replacement Support in Tirith Policies (#171)

* Add support for parameterizing Tirith policies

* Use pydash.get() and check for match only if the value is of type str

* Add variable replacement for meta and eval_expression in a policy

* Add unit tests for policy parameterization, change return type for cases where the path was not found, and change syntax of entering the variable names

* Fix linting

* tirith parametrization

---------

Co-authored-by: Rafid Aslam <[email protected]>
Removed RESULTS text from error

Resolved - Generalize the function get_path_value_from_dict

Refactor get_path_value_from_dict

Moved get_path_value_from_dict to common.py.
Refactored Kubernetes and JSON handler files to import from common.py.

Updated Common.py

Fix linting (#167)

Add a getting started guide in README.md (#139)

* Add a getting started guide in README.md

* Add description of getting started activity, and some minor fixes
Add maintainers in README and CODEOWNERS file

Add additional rules and guidelines to contributing.md

Add examples for commit messages and guidelines for solving issues

Update CONTRIBUTING.md with guidelines about solving issues

Add separate heading about solving issues, and add examples for writing descriptions in commit changes

Merge branch 'main' of https://github.com/StackGuardian/tirith
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.

3 participants