OutSystems / outsystems-pipeline

Python package and pipeline examples to accelerate the integration of OutSystems with third-party CI/CD tools
Apache License 2.0
38 stars 54 forks source link

Validate technical debt script crashes if an application has no technical debt #68

Closed basdejong95 closed 1 year ago

basdejong95 commented 1 year ago

When doing the tech debt analysis on an application that has no findings, the script crashed:

2023-11-01T12:01:57.2487319Z ##[section]Starting: Check technical debt data thresholds
2023-11-01T12:01:57.2692958Z ==============================================================================
2023-11-01T12:01:57.2693425Z Task         : Python script
2023-11-01T12:01:57.2693625Z Description  : Run a Python file or inline script
2023-11-01T12:01:57.2693951Z Version      : 0.229.3
2023-11-01T12:01:57.2694112Z Author       : Microsoft Corporation
2023-11-01T12:01:57.2694366Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/python-script
2023-11-01T12:01:57.2694966Z ==============================================================================
2023-11-01T12:01:57.7114623Z [command]"C:\Program Files\Python310\python.exe" D:\a\2\s\Pipelines\scripts\tech_debt_validation.py --manifest_file D:\a\2/trigger_manifest/trigger_manifest.json --techdebt_data D:\a\2/techdebt_data --max_techdebt_level Medium --max_security_findings 1
2023-11-01T12:01:57.7116782Z Checking thresholds (per application) for technical debt data:
2023-11-01T12:01:57.7119855Z     >>> Tech Debt Level = Medium
2023-11-01T12:01:57.7120309Z     >>> Security Findings (Count) = 1
2023-11-01T12:01:57.7120840Z Traceback (most recent call last):
2023-11-01T12:01:57.7121507Z   File "D:\a\2\s\Pipelines\scripts\tech_debt_validation.py", line 61, in <module>
2023-11-01T12:01:57.7122238Z     for finding in sec_findings_only:
2023-11-01T12:01:57.7122901Z   File "D:\a\2\s\Pipelines\scripts\tech_debt_validation.py", line 60, in <lambda>
2023-11-01T12:01:57.7123978Z     sec_findings_only = filter(lambda x: x["CategoryGUID"] == cat_security_guid, module["Findings"])
2023-11-01T12:01:57.7124828Z KeyError: 'CategoryGUID'
2023-11-01T12:01:57.7160571Z ##[error]The process 'C:\Program Files\Python310\python.exe' failed with exit code 1
2023-11-01T12:01:57.7186815Z ##[section]Finishing: Check technical debt data thresholds

When doing this on an application that has 1 or more security findings it runs just fine

basdejong95 commented 1 year ago

JSON of working application:

{
    "InfrastructureInfo": {
        "ActivationCode": "xxx",
        "LastAnalyzedOn": "2023-11-01T11:47:20Z"
    },
    "Applications": [
        {
            "GUID": "c8df437c-ab8b-4d24-8214-17567cb2c957",
            "Name": "xxx",
            "LevelGUID": "dc01c0b8-ae5b-49b3-91f9-793fc04c5215",
            "Findings": [
                {
                    "CategoryGUID": "57e63fe8-a299-4f32-b7b6-e8c5f863da06",
                    "PatternGUID": "5bf0ba1b-4543-4790-87d3-a8e5386371ba",
                    "Count": 1
                }
            ],
            "Modules": [
                {
                    "GUID": "d16f2054-2e9b-4d53-bf11-d36f3524434f",
                    "Name": "xxx",
                    "LevelGUID": "dc01c0b8-ae5b-49b3-91f9-793fc04c5215",
                    "Findings": [
                        {
                            "CategoryGUID": "57e63fe8-a299-4f32-b7b6-e8c5f863da06",
                            "PatternGUID": "5bf0ba1b-4543-4790-87d3-a8e5386371ba",
                            "Count": 10
                        },
                        {
                            "CategoryGUID": "57e63fe8-a299-4f32-b7b6-e8c5f863da06",
                            "PatternGUID": "c8e11573-0579-4b00-8c4b-d92ed74cca01",
                            "Count": 1
                        },
                        {
                            "CategoryGUID": "6c87e98f-2ece-4df2-b791-d0c7eae15914",
                            "PatternGUID": "062205e2-983c-4717-b8a1-43d9c3f54834",
                            "Count": 1
                        },
                        {
                            "CategoryGUID": "f7fdbb75-f2f3-4199-9761-ae0fd08f0998",
                            "PatternGUID": "b2660dcc-8d22-4d5c-a6e5-1942519df07a"
                        }
                    ]
                }
            ]
        }
    ],
    "Page": {
        "Limit": 20,
        "TotalResults": 1,
        "TotalPages": 1
    }
}

JSON of application where it crashes:

{
    "InfrastructureInfo": {
        "ActivationCode": "xxx",
        "LastAnalyzedOn": "2023-11-01T11:47:20Z"
    },
    "Applications": [
        {
            "GUID": "81064293-f866-4e36-beab-2462348e3588",
            "Name": "xxx",
            "LevelGUID": "dc01c0b8-ae5b-49b3-91f9-793fc04c5215",
            "Findings": [
                {}
            ],
            "Modules": [
                {
                    "GUID": "388dbde6-54bb-4dba-80ca-dd922d450f6b",
                    "Name": "xxx",
                    "LevelGUID": "dc01c0b8-ae5b-49b3-91f9-793fc04c5215",
                    "Findings": [
                        {}
                    ]
                }
            ]
        }
    ],
    "Page": {
        "Limit": 20,
        "TotalResults": 1,
        "TotalPages": 1
    }
}
giulianoragusa commented 1 year ago

facing the same issue. Any updated?

duarte-castano commented 1 year ago

Hi @basdejong95 and @giulianoragusa

The script has been updated, and it no longer fails when the application has no tech debt findings. The updated script can be found here.

Cheers, Duarte Castaño

giulianoragusa commented 1 year ago

Thanks for the quick turnover @duarte-castano . It does seem like a different bug is still present: image

duarte-castano commented 1 year ago

Hey @giulianoragusa,

I am not able to reproduce the error, can you provide the JSON file so I can troubleshoot? Which python version are you using?

A possible solution might be updating line 72 with finding.get("Count", 0) instead of finding["Count"] to fall back to 0 if it doesn't find the "Count" entry. Can you try it?

giulianoragusa commented 1 year ago

That did the trick! Muito obrigado!