Skip to content

refactor: replace magic strings with Severity and LLMProvider enums (#47)#81

Merged
advaitpatel merged 1 commit into
OWASP:mainfrom
OddSteak:refactor/replace-magic-strings-with-enums-issue-47
May 18, 2026
Merged

refactor: replace magic strings with Severity and LLMProvider enums (#47)#81
advaitpatel merged 1 commit into
OWASP:mainfrom
OddSteak:refactor/replace-magic-strings-with-enums-issue-47

Conversation

@OddSteak
Copy link
Copy Markdown
Contributor

@OddSteak OddSteak commented May 16, 2026

Closes #47

Description

Severity levels (CRITICAL, HIGH, MEDIUM, LOW, UNKNOWN) and LLM
provider names (openai, anthropic, google, ollama) were repeated as
raw strings across 6+ files, making them typo-prone and hard to discover.

Files Changed

File Change
docksec/enums.py NewSeverity and LLMProvider enums
docksec/config_manager.py Provider/severity validation via enums
docksec/docker_scanner.py Severity enum in validation, scoring, and report generation
docksec/score_calculator.py SEVERITY_WEIGHTS dict keyed by enum
docksec/utils.py LLMProvider constants in get_llm branches
docksec/cli.py LLMProvider.values() for argparse choices
tests/test_docker_scanner.py Use Severity.values()

Type of Change

  • Code refactoring (no functional changes)

How Has This Been Tested?

  • All 17 existing tests pass

Test Configuration:

  • Python version: 3.14
  • Operating System: Arch Linux
  • DockSec version: main branch

Checklist

  • Code follows the style guidelines of this project
  • Self-review completed
  • Hard-to-understand areas are commented
  • Documentation updated where needed
  • No new warnings or errors introduced
  • Tests added that prove the fix or feature works
  • All existing tests pass
  • Dependent changes have been merged and published
  • Spelling checked

By submitting this pull request, I confirm that my contribution is made under the terms of the MIT license.

…WASP#47)

Adds docksec/enums.py with Severity and LLMProvider (both extend str for
backwards-compatible comparisons and JSON serialisation). All hardcoded
provider/severity string lists across config_manager.py, docker_scanner.py,
score_calculator.py, utils.py, and cli.py now source from the enums.
argparse provider choices are driven by LLMProvider.values().
Tests updated to use Severity.values().
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 53.06122% with 23 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@a248226). Learn more about missing BASE report.

Files with missing lines Patch % Lines
docksec/config_manager.py 14.28% 6 Missing ⚠️
docksec/docker_scanner.py 25.00% 6 Missing ⚠️
docksec/utils.py 33.33% 4 Missing ⚠️
docksec/score_calculator.py 0.00% 3 Missing ⚠️
docksec/cli.py 0.00% 2 Missing ⚠️
docksec/enums.py 90.47% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main      #81   +/-   ##
=======================================
  Coverage        ?   27.23%           
=======================================
  Files           ?       15           
  Lines           ?     1788           
  Branches        ?        0           
=======================================
  Hits            ?      487           
  Misses          ?     1301           
  Partials        ?        0           
Flag Coverage Δ
unittests 27.23% <53.06%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@advaitpatel advaitpatel left a comment

Choose a reason for hiding this comment

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

lgtm, thank you for your contributions.

@advaitpatel advaitpatel merged commit 7686cd0 into OWASP:main May 18, 2026
6 checks passed
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.

[ENHANCEMENT] Replace magic strings with Enums for severity levels and LLM providers

3 participants