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

handle non-boolean values in handlermanifest #3208

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

nagworld9
Copy link
Contributor

Description

We learned recently that some extensions are sending string value "true" or "false" for boolean flags in handlermanifest. This led to wrong matching in the agent. For ex: string "false" matched as true since we assume they are boolean value and condition not flag became as flag has value or not instead flag has true or false

Addressing this pr with reporting warning plus default to false if they send non-boolean value except "true". For backward compatibility, 'true' (case insensitive) is accepted.

Issue #


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made

Quality of Code and Contribution Guidelines

maddieford
maddieford previously approved these changes Sep 10, 2024
Copy link

codecov bot commented Sep 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 72.32%. Comparing base (3aebcdd) to head (a77bde9).
Report is 303 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3208      +/-   ##
===========================================
+ Coverage    71.97%   72.32%   +0.34%     
===========================================
  Files          103      114      +11     
  Lines        15692    16978    +1286     
  Branches      2486     2452      -34     
===========================================
+ Hits         11295    12280     +985     
- Misses        3881     4132     +251     
- Partials       516      566      +50     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

maddieford
maddieford previously approved these changes Sep 10, 2024
"""
for key in ['reportHeartbeat', 'continueOnUpdateFailure', 'supportsMultipleExtensions']:
value = self.data['handlerManifest'].get(key, False)
if not isinstance(value, bool):
Copy link
Member

Choose a reason for hiding this comment

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

I think this expresses the intention of the check a little better:

            value = self.data['handlerManifest'].get(key)
            if value is not None and not isinstance(value, bool):

value = self.data['handlerManifest'].get(key, False)
if not isinstance(value, bool):
msg =("In the handler manifest: '{0}' has a non-boolean value [{1}] for boolean type. Please change it to a boolean value. "
"For backward compatibility, 'true' (case insensitive) is accepted, and other values default to False.").format(key, value)
Copy link
Member

Choose a reason for hiding this comment

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

I would not advertise this, since we do not want to encourage its use

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean this part "For backward compatibility, 'true' (case insensitive) is accepted, and other values default to False.

Copy link
Member

Choose a reason for hiding this comment

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

Yup, we don't want to encourage the use of strings as booleans. We need to supported for extensions that already do it, but we should not let other extensions know that we do.

add_event(name=ext_name, is_success=False, message=msg, op=WALAEventOperation.ExtensionHandlerManifest, log_event=False)

@staticmethod
def _parse_boolean_value(value, default_val=False):
Copy link
Member

Choose a reason for hiding this comment

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

let's not have a default for default_val; in this case, forcing the caller to explicitly specify the default value makes the code more readable

@nagworld9 nagworld9 merged commit 4d47b5e into Azure:develop Sep 11, 2024
11 checks passed
@nagworld9 nagworld9 deleted the nonbool-value branch September 11, 2024 23:36
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