Skip to content

Fix error when there's an empty 'mask' in bitops config#350

Merged
PhillypHenning merged 1 commit intomainfrom
mask_check
Nov 9, 2022
Merged

Fix error when there's an empty 'mask' in bitops config#350
PhillypHenning merged 1 commit intomainfrom
mask_check

Conversation

@PhillypHenning
Copy link
Copy Markdown
Contributor

Description

Adding mask value check. If value is set, masking will occur, if not, message it returned unmasked. This avoid null value issues.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation

@arm4b arm4b added this to the v2.2.0 milestone Nov 8, 2022
@arm4b
Copy link
Copy Markdown
Contributor

arm4b commented Nov 8, 2022

For the record, this is a follow-up to #345 implementation where we get the following error:

#8 0.955   File "/opt/bitops/scripts/plugins/logging.py", line 84, in format
#8 0.955     record.msg = mask_message(record.msg)
#8 0.955   File "/opt/bitops/scripts/plugins/logging.py", line 44, in mask_message
#8 0.955     for config_item in BITOPS_logging_masks:
#8 0.955 TypeError: 'NoneType' object is not iterable

@PhillypHenning Is it happening when the mask: wasn't provided in the bitops config, right?

@PhillypHenning
Copy link
Copy Markdown
Contributor Author

Yep!

Comment on lines +42 to +43
if BITOPS_logging_masks is None:
return message
Copy link
Copy Markdown
Contributor

@arm4b arm4b Nov 8, 2022

Choose a reason for hiding this comment

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

How about specifying the right default for the empty mask? I believe it's a list by default.

Maybe adding else [] instead of else None here would save us from future issues?

BITOPS_logging_masks = (
bitops_build_configuration.bitops.logging.masks
if bitops_build_configuration.bitops.logging.masks is not None
else None
)

WDYT?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Additionally, looks like we've missed adding new mask to bitops schema here:
https://github.com/bitovi/bitops/blob/main/bitops.schema.yaml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I disagree - personally if the value is "" then it should be a none type. None type checking is fast and accurate. Variables being half set isn't a great pattern.

Copy link
Copy Markdown
Contributor

@arm4b arm4b Nov 8, 2022

Choose a reason for hiding this comment

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

Yeah, I understand what you mean.
I just see similar errors in so many places as we're fixing those.

For instance, if schema says bitops: is an object, - yeah after parsing yaml technically empty value is None, but it's much better for us to consider it as an empty object/dict {}.

If schema says mask: is a list, technically empty value is None, but it's much better to consider it as an empty list [].

And because we have a schema with default types it makes more sense to justify it:

source:
type: object
properties:
sourced_from:
type: string
description: "Where the plugin will be sourced from"

So we're casting to the default type according to the schema that we defined previously.

Technically relying on None gives us nothing, but relying on the default schema type is much more beneficial saving us from all the type & empty check issues in the long run.

@arm4b arm4b added the bug 🪲 Something isn't working label Nov 8, 2022
@arm4b arm4b changed the title Adding mask check Fix error when there's an empty 'mask' in bitops config Nov 8, 2022
@PhillypHenning
Copy link
Copy Markdown
Contributor Author

Alright based on https://github.com/bitovi/bitops/pull/345/files#diff-3ee44309834f418383ee2f058cfc22a2dd857c38b7c85ba42c835ae4d23e2163 which details the original masking work, am I right to assume what we're really needing here is a dict schema converter?

bitops.config.yaml

masks:
      - # regex to search
        # looks for `BITOPS_KUBECONFIG_BASE64={string}`
        search:  (.*BITOPS_KUBECONFIG_BASE64.*\=)(.*\n)
        # replace the value part
        replace: '\1*******\n'
      - # regex to search
        # looks for `The namespace kube-system exists`
        search:  (.*The namespace )(kube-system)( exists.*)
        #replace kube-system
        replace: '\1*******\3'

From my perspective this is either a list object or a dict.
Regardless, a converter will need to be written.

@armab @mickmcgrath13

@arm4b
Copy link
Copy Markdown
Contributor

arm4b commented Nov 8, 2022

Looks like the masks is a list of dicts at this moment: masks: [{}, {}, {}].
What do you mean by converting?

I would care about the highest-level masks: [] default casting to the list for now for this specific case, as that's happening when the user is omitting the masks in the bitops config.

Copy link
Copy Markdown
Contributor

@arm4b arm4b left a comment

Choose a reason for hiding this comment

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

Alright, let's merge it as is as it fixes an issue, - was still good to have a conversation here.
Thanks for creating a dedicated PR for the fix! 👍

@PhillypHenning PhillypHenning merged commit 0bf00f7 into main Nov 9, 2022
@PhillypHenning PhillypHenning deleted the mask_check branch November 9, 2022 19:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants