|
| 1 | +# ADR-005: Unified Backend Approach for Value Storage |
| 2 | + |
| 3 | +## Status |
| 4 | +Proposed |
| 5 | + |
| 6 | +## Context |
| 7 | +Currently, the Value class handles two distinct storage types: local and remote. This creates a split in logic within the Value class, requiring different code paths and validation rules based on the storage type. This complexity makes the code harder to maintain and test. |
| 8 | + |
| 9 | +## Decision |
| 10 | +We will remove the storage_type distinction from the Value class and implement a SimpleValueBackend for non-sensitive data (previously handled as "local" storage). This means: |
| 11 | + |
| 12 | +1. Value class will: |
| 13 | + - Only interact with backends through a unified interface |
| 14 | + - Not need to know about storage types |
| 15 | + - Have simpler logic and better separation of concerns |
| 16 | + |
| 17 | +2. Storage backends will: |
| 18 | + - Include a new SimpleValueBackend for non-sensitive data |
| 19 | + - All implement the same ValueBackend interface |
| 20 | + - Be responsible for their specific storage mechanisms |
| 21 | + |
| 22 | +3. Configuration will: |
| 23 | + - Use SimpleValueBackend internally for non-sensitive values |
| 24 | + - Use secure backends (AWS/Azure) for sensitive values |
| 25 | + - Backend selection handled by the system based on value sensitivity |
| 26 | + |
| 27 | +## Consequences |
| 28 | + |
| 29 | +### Positive |
| 30 | +1. **Cleaner Value Class** |
| 31 | + - Removes storage type logic |
| 32 | + - Single consistent interface for all operations |
| 33 | + - Better separation of concerns |
| 34 | + |
| 35 | +2. **Unified Testing** |
| 36 | + - All storage types tested through the same interface |
| 37 | + - No need for separate local/remote test cases |
| 38 | + - Easier to mock and verify behavior |
| 39 | + |
| 40 | +3. **More Flexible** |
| 41 | + - Easy to add new backend types |
| 42 | + - Consistent interface for all storage types |
| 43 | + - Clear extension points |
| 44 | + |
| 45 | +4. **Better Security Model** |
| 46 | + - Storage backend choice driven by data sensitivity |
| 47 | + - Clear separation between sensitive and non-sensitive data |
| 48 | + - Explicit in configuration |
| 49 | + |
| 50 | +### Negative |
| 51 | +1. **Slight Performance Impact** |
| 52 | + - Additional method calls for simple value operations |
| 53 | + - Extra object creation for SimpleValueBackend |
| 54 | + |
| 55 | +### Neutral |
| 56 | +1. **Configuration Changes** |
| 57 | + - Backend selection based on value sensitivity |
| 58 | + - Transparent to end users |
| 59 | + |
| 60 | +## Implementation Plan |
| 61 | + |
| 62 | +1. **Backend Development** |
| 63 | + ```python |
| 64 | + class SimpleValueBackend(ValueBackend): |
| 65 | + def __init__(self): |
| 66 | + self._values = {} |
| 67 | + |
| 68 | + def get_value(self, path: str, environment: str) -> str: |
| 69 | + key = self._make_key(path, environment) |
| 70 | + return self._values[key] |
| 71 | + |
| 72 | + def set_value(self, path: str, environment: str, value: str) -> None: |
| 73 | + key = self._make_key(path, environment) |
| 74 | + self._values[key] = value |
| 75 | + ``` |
| 76 | + |
| 77 | +2. **Value Class Simplification** |
| 78 | + ```python |
| 79 | + @dataclass |
| 80 | + class Value: |
| 81 | + path: str |
| 82 | + environment: str |
| 83 | + _backend: ValueBackend |
| 84 | + |
| 85 | + def get(self) -> str: |
| 86 | + return self._backend.get_value(self.path, self.environment) |
| 87 | + |
| 88 | + def set(self, value: str) -> None: |
| 89 | + if not isinstance(value, str): |
| 90 | + raise ValueError("Value must be a string") |
| 91 | + self._backend.set_value(self.path, self.environment, value) |
| 92 | + ``` |
| 93 | + |
| 94 | +3. **Configuration Example** |
| 95 | + ```json |
| 96 | + { |
| 97 | + "version": "1.0", |
| 98 | + "release": "my-app", |
| 99 | + "deployments": { |
| 100 | + "prod": { |
| 101 | + "backend": "aws", |
| 102 | + "auth": { |
| 103 | + "type": "managed_identity" |
| 104 | + }, |
| 105 | + "backend_config": { |
| 106 | + "region": "us-west-2" |
| 107 | + } |
| 108 | + } |
| 109 | + }, |
| 110 | + "config": [ |
| 111 | + { |
| 112 | + "path": "app.replicas", |
| 113 | + "description": "Number of application replicas", |
| 114 | + "required": true, |
| 115 | + "sensitive": false, |
| 116 | + "values": { |
| 117 | + "dev": "3", |
| 118 | + "prod": "5" |
| 119 | + } |
| 120 | + }, |
| 121 | + { |
| 122 | + "path": "app.secretKey", |
| 123 | + "description": "Application secret key", |
| 124 | + "required": true, |
| 125 | + "sensitive": true, |
| 126 | + "values": { |
| 127 | + "dev": "dev-key-123", |
| 128 | + "prod": "prod-key-456" |
| 129 | + } |
| 130 | + } |
| 131 | + ] |
| 132 | + } |
| 133 | + ``` |
| 134 | + |
| 135 | + The system will automatically: |
| 136 | + - Use SimpleValueBackend for non-sensitive values (app.replicas) |
| 137 | + - Use configured secure backend for sensitive values (app.secretKey) |
0 commit comments