Context class for DevOps operations. Encapsulates user identity, AWS region, GitHub organization, and other contextual information needed for DevOps operations.
| 11 | |
| 12 | |
| 13 | class DevOpsContext(BaseModel): |
| 14 | """ |
| 15 | Context class for DevOps operations. |
| 16 | |
| 17 | Encapsulates user identity, AWS region, GitHub organization, and other |
| 18 | contextual information needed for DevOps operations. |
| 19 | """ |
| 20 | |
| 21 | user_id: str = Field( |
| 22 | description="Unique identifier for the user" |
| 23 | ) |
| 24 | |
| 25 | aws_region: Optional[str] = Field( |
| 26 | default=None, |
| 27 | description="Default AWS region for operations" |
| 28 | ) |
| 29 | |
| 30 | github_org: Optional[str] = Field( |
| 31 | default=None, |
| 32 | description="Default GitHub organization" |
| 33 | ) |
| 34 | |
| 35 | environment: str = Field( |
| 36 | default="dev", |
| 37 | description="Environment (dev, staging, prod)" |
| 38 | ) |
| 39 | |
| 40 | metadata: Dict[str, Any] = Field( |
| 41 | default_factory=dict, |
| 42 | description="Additional metadata for the context" |
| 43 | ) |
| 44 | |
| 45 | def get_metadata(self, key: str, default: Any = None) -> Any: |
| 46 | """ |
| 47 | Get a metadata value by key. |
| 48 | |
| 49 | Args: |
| 50 | key: The metadata key |
| 51 | default: Default value if key doesn't exist |
| 52 | |
| 53 | Returns: |
| 54 | The metadata value or default |
| 55 | """ |
| 56 | return self.metadata.get(key, default) |
| 57 | |
| 58 | def set_metadata(self, key: str, value: Any) -> None: |
| 59 | """ |
| 60 | Set a metadata value. |
| 61 | |
| 62 | Args: |
| 63 | key: The metadata key |
| 64 | value: The value to set |
| 65 | """ |
| 66 | self.metadata[key] = value |
| 67 | |
| 68 | def with_aws_region(self, region: str) -> 'DevOpsContext': |
| 69 | """ |
| 70 | Create a new context with the specified AWS region. |