Skip to content

feat: Add enabled field to plugin configuration to control plugin load #680

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crivetimihai
Copy link
Member

feat: Add enabled field to plugin configuration to control plugin loading

Implements plugin enable/disable functionality as requested in issue #679. Individual plugins can now be enabled or disabled via the 'enabled' field in plugins/config.yaml.

Changes Made

Schema Updates

  • Add enabled: bool = True field to PluginConfig model in framework/models.py
  • Defaults to True for backward compatibility with existing configurations
  • Field is properly validated by Pydantic schema

Plugin Loading Logic

  • Update PluginManager.initialize() in framework/manager.py to check enabled field
  • Plugins are only loaded if both enabled=True AND mode \!= DISABLED
  • Added descriptive logging to distinguish between disabled methods:
    • "enabled=false" for plugins disabled via enabled field
    • "mode=disabled" for plugins disabled via mode field

Configuration Examples

  • Update plugins/config.yaml to demonstrate usage:
    • PIIFilterPlugin and ReplaceBadWordsPlugin: enabled=true
    • DenyListPlugin: enabled=false (example of disabled plugin)
  • Add inline comments explaining the field usage

Key Features

Backward Compatible: Existing configs without 'enabled' default to true
Dual Control: Plugins can be disabled via enabled=false OR mode=disabled
Clear Logging: Descriptive messages distinguish disabling methods
Schema Validation: New field properly validated by Pydantic
Comprehensive Testing: All doctests and unit tests passing (1190 passed)

Testing

  • Schema validation confirmed working with new enabled field
  • Plugin loading logic tested with both enabled=true/false scenarios
  • Configuration loading successfully validates YAML with new field
  • All existing tests pass, confirming backward compatibility maintained
  • Code coverage maintained at 80%

Closes #679

…ding

Implements plugin enable/disable functionality as requested in issue #679.
Individual plugins can now be enabled or disabled via the 'enabled' field
in plugins/config.yaml.

## Changes Made

### Schema Updates
- Add `enabled: bool = True` field to PluginConfig model in framework/models.py
- Defaults to True for backward compatibility with existing configurations
- Field is properly validated by Pydantic schema

### Plugin Loading Logic
- Update PluginManager.initialize() in framework/manager.py to check enabled field
- Plugins are only loaded if both `enabled=True` AND `mode \!= DISABLED`
- Added descriptive logging to distinguish between disabled methods:
  - "enabled=false" for plugins disabled via enabled field
  - "mode=disabled" for plugins disabled via mode field

### Configuration Examples
- Update plugins/config.yaml to demonstrate usage:
  - PIIFilterPlugin and ReplaceBadWordsPlugin: enabled=true
  - DenyListPlugin: enabled=false (example of disabled plugin)
- Add inline comments explaining the field usage

## Key Features

✅ **Backward Compatible**: Existing configs without 'enabled' default to true
✅ **Dual Control**: Plugins can be disabled via enabled=false OR mode=disabled
✅ **Clear Logging**: Descriptive messages distinguish disabling methods
✅ **Schema Validation**: New field properly validated by Pydantic
✅ **Comprehensive Testing**: All doctests and unit tests passing (1190 passed)

## Testing

- Schema validation confirmed working with new enabled field
- Plugin loading logic tested with both enabled=true/false scenarios
- Configuration loading successfully validates YAML with new field
- All existing tests pass, confirming backward compatibility maintained
- Code coverage maintained at 80%

Closes #679
if not plugin_config.enabled:
logger.debug(f"Skipping disabled plugin: {plugin_config.name} (enabled=false)")
else:
logger.debug(f"Skipping disabled plugin: {plugin_config.name} (mode=disabled)")
Copy link
Collaborator

@imolloy imolloy Aug 7, 2025

Choose a reason for hiding this comment

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

Maybe swap these? I think the mode is the coarser level of granularity and might take precedence for the debug statement.

Copy link
Collaborator

@terylt terylt left a comment

Choose a reason for hiding this comment

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

Hi @crivetimihai

Nice updates. My one comment is just about the difference between mode=disabled and enabled=True. Is there a case where we'd use on over the other? My thought would be if we want to break enabled out separately, we could have mode just be enforce/permissive.

Is there a use case where we would need both?

@araujof
Copy link
Member

araujof commented Aug 7, 2025

Nice updates. My one comment is just about the difference between mode=disabled and enabled=True. Is there a case where we'd use on over the other? My thought would be if we want to break enabled out separately, we could have mode just be enforce/permissive.

Is there a use case where we would need both?

My thoughts, exactly. We define the enabled/disabled state in the mode.

class PluginMode(str, Enum):
"""Plugin modes of operation.
Attributes:
enforce: enforces the plugin result.
permissive: audits the result.
disabled: plugin disabled.
"""
ENFORCE = "enforce"
PERMISSIVE = "permissive"
DISABLED = "disabled"

Do you prefer to have it as a new field instead? If so, we could remove the DISABLED mode from the enum, simplifying a bit the usage and implementation.

Maybe, the question is whether CF allows the PluginConfig options to be changed without reloading the server. If not, how do we differentiate the semantics between the config's enabled flag and the plugin model DISABLED state?

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.

[Feature] Add enabled field to plugins/config.yaml
4 participants