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

Azure's vm_agent() function has poorly written if-else blocks resulting in KeyError #64

Open
oguzhan-prplbx opened this issue Dec 24, 2020 · 0 comments

Comments

@oguzhan-prplbx
Copy link

When I run the cs-suite for Azure I get this following error:

File "/home/ubuntu/cs-suite/modules/azureaudit.py", line 1181, in vm_agent
    log_data["data"] = log_data.pop("value")
KeyError: 'value'

I checked the code, and I found this:

azure_audit.py:1170
        if check == '':
            j_res['type'] = 'WARNING'
            j_res['value'] = 'The VM %s does not have virtual agent enabled' %(name)
        else:
            list = check.split()
            if list[1] == "Succeeded" and list[0] != "":
                j_res['type'] = 'PASS'
                j_res['value'] = 'The VM %s does have virtual agent enabled' % (name)
        data.append(j_res)
        log_data = dict()
        log_data = j_res
        log_data["data"] = log_data.pop("value")

This is problematic because if condition inside else has no else condition to default to.

I had to add the following else block to bypass this problem.

azure_audit.py:1170
        if check == '':
            j_res['type'] = 'WARNING'
            j_res['value'] = 'The VM %s does not have virtual agent enabled' %(name)
        else:
            list = check.split()
            if list[1] == "Succeeded" and list[0] != "":
                j_res['type'] = 'PASS'
                j_res['value'] = 'The VM %s does have virtual agent enabled' % (name)
            # change made starts here:
            else:
                j_res['type'] = 'WARNING'
                j_res['value'] = 'The VM %s does not have virtual agent enabled' %(name)
            # change made ends here
        data.append(j_res)
        log_data = dict()
        log_data = j_res
        log_data["data"] = log_data.pop("value")
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

No branches or pull requests

1 participant