|
| 1 | +""" |
| 2 | +ITL ControlPlane SDK - Modular Architecture |
| 3 | + |
| 4 | +The SDK is now organized into two main modules: |
| 5 | +1. Core Module - Base infrastructure, models, exceptions |
| 6 | +2. Identity Module - Pluggable identity provider framework |
| 7 | +""" |
| 8 | + |
| 9 | +SDK Structure: |
| 10 | +============== |
| 11 | + |
| 12 | +itl_controlplane_sdk/ |
| 13 | +│ |
| 14 | +├── core/ # Core module - Base functionality |
| 15 | +│ ├── __init__.py # Exports all core components |
| 16 | +│ ├── models.py # HTTP models, infrastructure models, constants |
| 17 | +│ └── exceptions.py # Standard exception hierarchy |
| 18 | +│ |
| 19 | +├── identity/ # Identity module - Provider framework |
| 20 | +│ ├── __init__.py # Factory and provider exports |
| 21 | +│ ├── identity_provider_base.py # IdentityProvider ABC |
| 22 | +│ ├── identity_provider_factory.py # Factory pattern |
| 23 | +│ └── exceptions.py # Identity-specific exceptions |
| 24 | +│ |
| 25 | +├── fastapi/ # HTTP routing support |
| 26 | +│ ├── __init__.py |
| 27 | +│ ├── app_factory.py |
| 28 | +│ ├── config.py |
| 29 | +│ ├── middleware/ |
| 30 | +│ │ ├── error_handling.py |
| 31 | +│ │ └── logging.py |
| 32 | +│ └── routes/ |
| 33 | +│ └── metadata.py |
| 34 | +│ |
| 35 | +├── __init__.py # Main SDK entry point (unified exports) |
| 36 | +├── resource_provider.py # ResourceProvider ABC |
| 37 | +├── registry.py # ResourceProviderRegistry |
| 38 | +└── resource_ids.py # Resource ID utilities |
| 39 | + |
| 40 | + |
| 41 | +Core Module Exports: |
| 42 | +==================== |
| 43 | + |
| 44 | +HTTP Models: |
| 45 | + - ProvisioningState |
| 46 | + - ResourceMetadata |
| 47 | + - ResourceRequest |
| 48 | + - ResourceResponse |
| 49 | + - ResourceListResponse |
| 50 | + - ErrorResponse |
| 51 | + |
| 52 | +Infrastructure Models (8): |
| 53 | + - Tag |
| 54 | + - ResourceGroup |
| 55 | + - ManagementGroup |
| 56 | + - Deployment |
| 57 | + - Subscription |
| 58 | + - Location |
| 59 | + - ExtendedLocation |
| 60 | + - Policy |
| 61 | + - ProviderConfiguration (config model) |
| 62 | + |
| 63 | +Enums (2): |
| 64 | + - ResourceState (Active, Inactive, Deleted, Pending) |
| 65 | + - DeploymentState (Running, Succeeded, Failed, Canceled) |
| 66 | + |
| 67 | +Exceptions (4): |
| 68 | + - ResourceProviderError (base) |
| 69 | + - ResourceNotFoundError |
| 70 | + - ResourceConflictError |
| 71 | + - ValidationError |
| 72 | + |
| 73 | +Constants: |
| 74 | + - PROVIDER_NAMESPACE |
| 75 | + - 8 RESOURCE_TYPE_* constants |
| 76 | + - ITL_RESOURCE_TYPES (list of all types) |
| 77 | + - DEFAULT_LOCATIONS (8 default locations) |
| 78 | + |
| 79 | + |
| 80 | +Identity Module Exports: |
| 81 | +========================= |
| 82 | + |
| 83 | +Interfaces: |
| 84 | + - IdentityProvider (ABC) |
| 85 | + |
| 86 | +Factory: |
| 87 | + - IdentityProviderFactory |
| 88 | + - get_factory() |
| 89 | + - register_provider() |
| 90 | + - create_provider() |
| 91 | + - get_or_create_provider() |
| 92 | + |
| 93 | +Exceptions: |
| 94 | + - IdentityProviderError (base) |
| 95 | + - IdentityProviderNotFoundError |
| 96 | + - InvalidCredentialsError |
| 97 | + - RealmAlreadyExistsError |
| 98 | + - ClientAlreadyExistsError |
| 99 | + |
| 100 | + |
| 101 | +Main SDK Exports: |
| 102 | +================= |
| 103 | + |
| 104 | +From core: |
| 105 | + - All HTTP models, infrastructure models, constants, exceptions |
| 106 | + |
| 107 | +From identity: |
| 108 | + - IdentityProvider, IdentityProviderFactory, factory functions |
| 109 | + |
| 110 | +Base classes: |
| 111 | + - ResourceProvider |
| 112 | + - ResourceProviderRegistry |
| 113 | + |
| 114 | +Utilities: |
| 115 | + - ResourceIdentity |
| 116 | + - generate_resource_id() |
| 117 | + - parse_resource_id() |
| 118 | + |
| 119 | + |
| 120 | +Usage Examples: |
| 121 | +=============== |
| 122 | + |
| 123 | +# Import from core |
| 124 | +from itl_controlplane_sdk.core import ( |
| 125 | + ResourceRequest, |
| 126 | + ResourceResponse, |
| 127 | + ResourceGroup, |
| 128 | + ResourceProviderError, |
| 129 | +) |
| 130 | + |
| 131 | +# Or import from main SDK |
| 132 | +from itl_controlplane_sdk import ( |
| 133 | + ResourceRequest, |
| 134 | + ResourceResponse, |
| 135 | + ResourceGroup, |
| 136 | +) |
| 137 | + |
| 138 | +# Identity provider framework |
| 139 | +from itl_controlplane_sdk.identity import ( |
| 140 | + get_factory as get_identity_factory, |
| 141 | + register_provider, |
| 142 | +) |
| 143 | +from keycloak_identity_provider import KeycloakIdentityProvider |
| 144 | + |
| 145 | +# Register and use |
| 146 | +register_provider("keycloak", KeycloakIdentityProvider) |
| 147 | +factory = get_identity_factory() |
| 148 | +provider = factory.create("keycloak", config) |
| 149 | + |
| 150 | +# Resource provider framework |
| 151 | +from itl_controlplane_sdk import ResourceProvider, ResourceProviderRegistry |
| 152 | + |
| 153 | +class MyProvider(ResourceProvider): |
| 154 | + async def create_or_update_resource(self, request): |
| 155 | + ... |
| 156 | + |
| 157 | +registry = ResourceProviderRegistry() |
| 158 | +registry.register_provider("my-provider", MyProvider("namespace")) |
| 159 | + |
| 160 | + |
| 161 | +Benefits of Modular Architecture: |
| 162 | +================================== |
| 163 | + |
| 164 | +✓ Separation of Concerns |
| 165 | + - Core: Base models and exceptions |
| 166 | + - Identity: Pluggable identity providers |
| 167 | + |
| 168 | +✓ Clear Dependencies |
| 169 | + - Core has no external dependencies (except pydantic) |
| 170 | + - Identity imports from core |
| 171 | + - Main SDK imports from both |
| 172 | + |
| 173 | +✓ Easier Testing |
| 174 | + - Test core without identity |
| 175 | + - Test identity with mock providers |
| 176 | + - Test main SDK with all components |
| 177 | + |
| 178 | +✓ Maintainability |
| 179 | + - Each module has single responsibility |
| 180 | + - Changes localized to relevant module |
| 181 | + - Easier to understand and extend |
| 182 | + |
| 183 | +✓ Scalability |
| 184 | + - Easy to add new identity providers |
| 185 | + - Can add new modules (e.g., storage, compute) without affecting existing |
| 186 | + - Clear import patterns for all providers |
0 commit comments