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

[3006.x] Fix find_json to not rely on newline after valid JSON #67023

Open
wants to merge 2 commits into
base: 3006.x
Choose a base branch
from

Conversation

m-czernek
Copy link
Contributor

What does this PR do?

In this PR, we enhance the find_json function to work with valid JSONs that contain garbage right after the JSON end. This is a problem when the text contains JSON and, for example, deprecation messages, such as:

{
    "local": {
        "saltutil_|-sync_states_|-sync_states_|-sync_states": {
            "name": "sync_states",
            "changes": {},
            "result": true,
            "comment": "No updates to sync",
            "__sls__": "util.syncstates",
            "__run_num__": 0,
            "start_time": "14:35:37.150819",
            "duration": 1256.999,
            "__id__": "sync_states"
        },
...JSON continues...
}/usr/lib/python3.6/site-packages/salt/states/x509.py:214: DeprecationWarning: The x509 modules are deprecated. Please migrate to the replacement modules (x509_v2). They are the default from Salt 3008 (Argon) onwards.
  "The x509 modules are deprecated. Please migrate to the replacement "

Previous Behavior

Previously, if the JSON contains text right after the closing parenthesis, we either get a ValueError, or we get a wrong return (in the example above, the return value is "The x509 modules are deprecated. Please migrate to the replacement "

New Behavior

The find_json method is able to filter the text right after the closing parenthesis, and returns the valid JSON.

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

Yes/No

Please review Salt's Contributing Guide for best practices, including the
PR Guidelines.

See GitHub's page on GPG signing for more information about signing commits with GPG.

Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

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

Please add a changelog for this

@m-czernek
Copy link
Contributor Author

Thank you for taking a look @twangboy , chlog added.

@twangboy
Copy link
Contributor

Once the testing pipeline is fixed you'll need to rebase this so the tests can run. Until then there's a pre-commit error. Looksl like you need to add .md to the changelog.

salt/utils/json.py Outdated Show resolved Hide resolved
salt/utils/json.py Outdated Show resolved Hide resolved
salt/utils/json.py Show resolved Hide resolved
tests/unit/utils/test_json.py Outdated Show resolved Hide resolved
salt/utils/json.py Outdated Show resolved Hide resolved
salt/utils/json.py Outdated Show resolved Hide resolved
salt/utils/json.py Show resolved Hide resolved
salt/utils/json.py Outdated Show resolved Hide resolved
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