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 ability to escape variable expansion in policy #5035

Merged
merged 4 commits into from
Jul 2, 2024

Conversation

blakerouse
Copy link
Contributor

@blakerouse blakerouse commented Jul 2, 2024

What does this PR do?

Adds the ability to a variable not be expanded and replaced in inputs.

A variable that is defined as $${...} will be replaced with ${...} in the policy.

$${...} is not allowed in any condition statement, because a condition statement requires that strings always be wrapped in '...' and so it doesn't make sense to allow it to be escaped and converted into a real string. That is already supported by just doing '${...}'.

Why is it important?

Allows users to provide values that should not be replaced in the policy.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in ./changelog/fragments using the changelog tool
  • [ ] I have added an integration test or an E2E test(unit test coverage is really good)

Disruptive User Impact

Adds the ability of users to escape variables.

Related issues

@blakerouse blakerouse added Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team backport-skip labels Jul 2, 2024
@blakerouse blakerouse self-assigned this Jul 2, 2024
@blakerouse blakerouse requested a review from a team as a code owner July 2, 2024 15:46
@elasticmachine
Copy link
Contributor

Pinging @elastic/elastic-agent-control-plane (Team:Elastic-Agent-Control-Plane)

Copy link

Quality Gate failed Quality Gate failed

Failed conditions
1.9% Coverage on New Code (required ≥ 40%)

See analysis details on SonarQube

@pierrehilbert pierrehilbert requested review from pchila and removed request for AndersonQ July 2, 2024 16:23
@blakerouse
Copy link
Contributor Author

Seems SonarQube is mad about the generated code from antlr, not from the code added.

@pierrehilbert
Copy link
Contributor

I'm okay with force merging this if we are getting the approval from code reviewer, @ycombinator is probably sharing my thoughts here

Copy link
Contributor

@michel-laterman michel-laterman left a comment

Choose a reason for hiding this comment

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

lgtm

func (v *expVisitor) VisitExpEVariable(ctx *parser.ExpEVariableContext) interface{} {
// escaped variables are not allowed in Eql conditions
// they should be wrapped in a constant to be allowed as a valid string in the expression
v.err = errors.New("escaped variable $${ is not allowed")
Copy link
Contributor

Choose a reason for hiding this comment

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

(nitpick) Would this error message be clear in the logs that this is not allowed in a condition?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes the condition checker adds that context.

@ycombinator
Copy link
Contributor

Force merging as this PR contains a lot of generated code and SonarQube is not able to exclude it.

@ycombinator ycombinator merged commit 3b7e584 into elastic:main Jul 2, 2024
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-skip Team:Elastic-Agent-Control-Plane Label for the Agent Control Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No way to escape variables in transpiler parsing
5 participants