Skip to content

Commit 92d9a4e

Browse files
committed
Merge branch 'feature/save-as-default' into 'develop'
Enhanced Configuration Management See merge request genaiic-reusable-assets/engagement-artifacts/genaiic-idp-accelerator!186
2 parents e6a72fd + c510911 commit 92d9a4e

File tree

4 files changed

+320
-85
lines changed

4 files changed

+320
-85
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ SPDX-License-Identifier: MIT-0
66
## [Unreleased]
77

88
### Added
9+
- **Enhanced Configuration Management**
10+
- **Save as Default**: New button to save current configuration as the new default baseline with confirmation modal and version upgrade warnings
11+
- **Export Configuration**: Export current configuration to local files in JSON or YAML format with customizable filename
12+
- **Import Configuration**: Import configuration from local JSON or YAML files with automatic format detection and validation
13+
- Enhanced Lambda resolver with deep merge functionality for proper default configuration updates
14+
- Automatic custom configuration reset when saving as default to maintain clean state
915
- **Nested Attribute Groups and Lists Support**
1016
- Enhanced document configuration schema to support complex nested attribute structures with three attribute types:
1117
- **Simple attributes**: Single-value extractions (existing behavior)

docs/configuration.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ The web interface allows real-time configuration updates without stack redeploym
1818
- **Evaluation Methods**: Set evaluation methods and thresholds for each attribute
1919
- **Summarization**: Configure model, prompts, and parameters for document summarization (when `IsSummarizationEnabled` is true)
2020

21+
### Configuration Management Features
22+
23+
- **Save as Default**: Save your current configuration as the new default baseline. This replaces the existing default configuration and automatically clears custom overrides. **Warning**: Default configurations may be overwritten during solution upgrades - export your configuration first for backup.
24+
- **Export Configuration**: Download your current configuration to local files in JSON or YAML format with customizable filenames. Use this to backup configurations before upgrades or share configurations between environments.
25+
- **Import Configuration**: Upload configuration files from your local machine in JSON or YAML format. The system automatically detects the file format and validates the configuration before applying changes.
26+
- **Restore Default**: Reset all configuration settings back to the original default values, removing all customizations.
27+
2128
Configuration changes are validated and applied immediately, with rollback capability if issues arise. See [web-ui.md](web-ui.md) for details on using the administration interface.
2229

2330
## Stack Parameters

src/lambda/configuration_resolver/index.py

Lines changed: 59 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,27 @@ def stringify_values(obj):
9494
# Convert everything to string, except None values
9595
return str(obj) if obj is not None else None
9696

97+
def deep_merge(target, source):
98+
"""
99+
Deep merge two dictionaries
100+
"""
101+
result = target.copy()
102+
103+
if not source:
104+
return result
105+
106+
for key, value in source.items():
107+
if key in result and isinstance(result[key], dict) and isinstance(value, dict):
108+
result[key] = deep_merge(result[key], value)
109+
else:
110+
result[key] = value
111+
112+
return result
113+
97114
def handle_update_configuration(custom_config):
98115
"""
99116
Handle the updateConfiguration GraphQL mutation
100-
Updates the Custom configuration item in DynamoDB
117+
Updates the Custom or Default configuration item in DynamoDB
101118
"""
102119
try:
103120
# Handle empty configuration case
@@ -117,18 +134,49 @@ def handle_update_configuration(custom_config):
117134
else:
118135
custom_config_obj = custom_config
119136

120-
# Convert all values to strings to ensure compatibility with DynamoDB
121-
stringified_config = stringify_values(custom_config_obj)
137+
# Check if this should be saved as default
138+
save_as_default = custom_config_obj.pop('saveAsDefault', False)
122139

123-
# Update the Custom configuration in DynamoDB
124-
response = table.put_item(
125-
Item={
126-
'Configuration': 'Custom',
127-
**stringified_config
128-
}
129-
)
140+
if save_as_default:
141+
# Get current default configuration
142+
default_item = get_configuration_item('Default')
143+
current_default = remove_configuration_key(default_item) if default_item else {}
144+
145+
# Merge custom changes with current default to create new complete default
146+
new_default_config = deep_merge(current_default, custom_config_obj)
147+
148+
# Convert to strings for DynamoDB
149+
stringified_default = stringify_values(new_default_config)
150+
151+
# Save new default configuration
152+
table.put_item(
153+
Item={
154+
'Configuration': 'Default',
155+
**stringified_default
156+
}
157+
)
158+
159+
# Clear custom configuration
160+
table.put_item(
161+
Item={
162+
'Configuration': 'Custom'
163+
}
164+
)
165+
166+
logger.info(f"Updated Default configuration and cleared Custom: {json.dumps(stringified_default)}")
167+
else:
168+
# Normal custom config update
169+
stringified_config = stringify_values(custom_config_obj)
170+
171+
table.put_item(
172+
Item={
173+
'Configuration': 'Custom',
174+
**stringified_config
175+
}
176+
)
177+
178+
logger.info(f"Updated Custom configuration: {json.dumps(stringified_config)}")
130179

131-
logger.info(f"Updated Custom configuration: {json.dumps(stringified_config)}")
132180
return True
133181

134182
except json.JSONDecodeError as e:

0 commit comments

Comments
 (0)