Skip to content

Commit ab506f5

Browse files
committed
feat: Add Metadata API endpoints and service patterns for resource management
- Implemented metadata API endpoints in `metadata.py` for querying resource metadata, dependencies, and hierarchical structures. - Created a base service class `BaseResourceService` in `base.py` to provide common functionality for resource providers, including idempotency, event publishing, tenant isolation, and error handling. - Added test suite for models, resource handlers, and resource provider functionality to ensure proper validation and behavior. - Introduced a test implementation of `ResourceProvider` to facilitate testing of resource creation, retrieval, and deletion.
1 parent 9a984d1 commit ab506f5

42 files changed

Lines changed: 8005 additions & 138 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 128 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@ The core SDK framework for ITL ControlPlane, providing resource management capab
66

77
- **Resource Provider Registry**: Core framework for registering and managing resource providers
88
- **Resource Provider Base Classes**: Abstract base classes for implementing custom resource providers
9-
- **Data Models**: Comprehensive data models for resources, requests, and responses
9+
- **Data Models**: Comprehensive data models for resources, requests, and responses using Pydantic
1010
- **Clean Architecture**: Independent component with minimal dependencies
11-
- **Provider Isolation**: Support for containerized provider deployments
11+
- **Provider Isolation**: Support for containerized and standalone provider deployments
12+
- **Async Support**: Built-in support for asynchronous resource operations
13+
- **Type Safety**: Full type hints and validation using Pydantic models
14+
- **Core Models**: Shared models for common resource types and configurations
15+
- **Hybrid Resource IDs**: Both human-readable path-based IDs and globally unique GUIDs for maximum flexibility
1216

1317
## Installation
1418

@@ -26,7 +30,14 @@ pip install -e .
2630
## Quick Start
2731

2832
```python
29-
from itl_controlplane_sdk import ResourceProviderRegistry, ResourceProvider
33+
from itl_controlplane_sdk import (
34+
ResourceProviderRegistry,
35+
ResourceProvider,
36+
ResourceRequest,
37+
ResourceResponse,
38+
ProvisioningState,
39+
generate_resource_id
40+
)
3041

3142
# Initialize the registry
3243
registry = ResourceProviderRegistry()
@@ -35,26 +46,44 @@ registry = ResourceProviderRegistry()
3546
class MyResourceProvider(ResourceProvider):
3647
def __init__(self):
3748
super().__init__("MyProvider")
49+
self.supported_resource_types = ["myresourcetype"]
3850

39-
async def create_or_update_resource(self, request):
40-
# Implementation here
41-
pass
51+
async def create_or_update_resource(self, request: ResourceRequest) -> ResourceResponse:
52+
# Generate a proper resource ID
53+
resource_id = generate_resource_id(
54+
subscription_id=request.subscription_id,
55+
resource_group=request.resource_group,
56+
provider_namespace=request.provider_namespace,
57+
resource_type=request.resource_type,
58+
resource_name=request.resource_name
59+
)
60+
61+
# Create response with both path-based ID and auto-generated GUID
62+
return ResourceResponse(
63+
id=resource_id,
64+
name=request.resource_name,
65+
type=f"{request.provider_namespace}/{request.resource_type}",
66+
location=request.location,
67+
properties=request.body.get("properties", {}),
68+
provisioning_state=ProvisioningState.SUCCEEDED
69+
# resource_guid is automatically generated for global uniqueness!
70+
)
4271

43-
async def get_resource(self, resource_id):
72+
async def get_resource(self, resource_type: str, resource_name: str) -> ResourceResponse:
4473
# Implementation here
4574
pass
4675

47-
async def delete_resource(self, resource_id):
76+
async def delete_resource(self, resource_type: str, resource_name: str) -> bool:
4877
# Implementation here
49-
pass
78+
return True
5079

51-
async def list_resources(self, resource_group):
80+
async def list_resources(self, resource_type: str, **filters) -> list:
5281
# Implementation here
53-
pass
82+
return []
5483

5584
# Register the provider
5685
provider = MyResourceProvider()
57-
registry.register_provider("myprovider", "myresourcetype", provider)
86+
registry.register_provider("MyProvider", provider)
5887
```
5988

6089
## Project Structure
@@ -64,54 +93,101 @@ ITL.ControlPlane.SDK/
6493
├── src/
6594
│ └── itl_controlplane_sdk/ # Core SDK package
6695
│ ├── __init__.py # Package exports
67-
│ ├── models.py # Data models
96+
│ ├── models.py # Pydantic data models
6897
│ ├── registry.py # Provider registry
69-
│ └── resource_provider.py # Base provider class
70-
├── providers/ # Isolated provider implementations
71-
│ ├── keycloak/ # Keycloak identity provider
72-
│ └── compute/ # Compute resource providers
98+
│ ├── resource_provider.py # Base provider class
99+
│ ├── base/ # Base classes and utilities
100+
│ └── common/ # Common utilities and shared models
101+
│ └── models/ # Shared model definitions
102+
│ └── core/ # Core resource models
103+
│ ├── base.py # Base resource classes
104+
│ ├── config.py # Configuration models
105+
│ ├── resources.py # Resource data classes
106+
│ └── __init__.py # Model exports
73107
├── examples/ # Usage examples
74108
│ └── quickstart.py # Getting started example
75109
├── .github/ # CI/CD workflows
76110
│ ├── workflows/ # GitHub Actions
77111
│ └── PYPI_SETUP.md # PyPI configuration guide
78112
├── test_sdk.py # SDK validation tests
79113
├── pyproject.toml # Package configuration
80-
└── documentation files # Architecture, pipeline, versioning docs
114+
├── ARCHITECTURE.md # Architecture documentation
115+
├── PIPELINE_SETUP.md # CI/CD pipeline setup
116+
├── AUTOMATED_VERSIONING.md # Versioning documentation
117+
└── VERSIONING_UPDATE.md # Version update guide
81118
```
82119

83120
## Architecture
84121

85122
The SDK follows a clean architecture with clear separation of concerns:
86123

87-
- **Registry**: Central registration and management of resource providers
88-
- **Providers**: Base classes and interfaces for implementing resource providers
89-
- **Models**: Data models for requests, responses, and resource metadata
90-
- **Isolation**: Support for standalone provider deployments
124+
- **Registry**: Central registration and management of resource providers with thread-safe operations
125+
- **Providers**: Abstract base classes and interfaces for implementing resource providers
126+
- **Models**: Pydantic-based data models for requests, responses, and resource metadata with full validation
127+
- **Base Classes**: Common base classes and utilities for provider implementations
128+
- **Common Models**: Shared model definitions for core resources (ResourceGroup, Deployment, etc.)
129+
- **Isolation**: Support for standalone provider deployments with independent lifecycles
130+
- **Type Safety**: Comprehensive type hints and runtime validation
91131

92132
## Related Components
93133

94134
This SDK is part of the ITL ControlPlane ecosystem. Other components have been separated into independent repositories for focused development:
95135

96136
- **ITL.ControlPlane.API**: REST API layer (separate repository)
97137
- **ITL.ControlPlane.GraphDB**: Graph database for metadata storage (separate repository)
138+
- **ITL.ControlPlane.ResourceProvider.Core**: Core resource provider for Azure-like resources
139+
- **ITL.ControlPlane.ResourceProvider.IAM**: Identity and access management provider (Keycloak)
140+
- **ITL.ControlPlane.ResourceProvider.Compute**: Compute resource provider for VMs and containers
141+
142+
## Provider Examples
143+
144+
The ITL ControlPlane ecosystem includes several reference provider implementations:
145+
146+
- **Core Provider**: Manages resource groups, subscriptions, deployments, and policies
147+
- **IAM Provider**: Integrates with Keycloak for identity and access management
148+
- **Compute Provider**: Manages virtual machines and compute resources
149+
150+
These providers demonstrate best practices for using the SDK's common models and base classes.
98151

99152
## Development
100153

101154
```bash
155+
# Clone the repository
156+
git clone https://github.com/ITlusions/ITL.ControlPlane.SDK.git
157+
cd ITL.ControlPlane.SDK
158+
102159
# Install development dependencies
103160
pip install -e ".[dev]"
104161

105162
# Run validation tests
106163
python test_sdk.py
107164

165+
# Run with pytest for more detailed output
166+
pytest test_sdk.py -v
167+
108168
# Format code
109169
black src/
110170

111171
# Type checking
112172
mypy src/
173+
174+
# Install SDK for use in other projects (editable install)
175+
pip install -e .
113176
```
114177

178+
## Getting Started with Provider Development
179+
180+
To create a new resource provider:
181+
182+
1. **Inherit from ResourceProvider**: Extend the base `ResourceProvider` class
183+
2. **Implement required methods**: `create_or_update_resource`, `get_resource`, `delete_resource`, `list_resources`
184+
3. **Define resource types**: Set `supported_resource_types` in your provider
185+
4. **Use common models**: Leverage shared models from `itl_controlplane_sdk.common.models.core`
186+
5. **Register with registry**: Use `ResourceProviderRegistry.register_provider()`
187+
6. **Add validation**: Use Pydantic models for request/response validation
188+
189+
See the [examples/quickstart.py](./examples/quickstart.py) for a complete example.
190+
115191
## CI/CD Pipeline
116192

117193
The repository includes a comprehensive CI/CD pipeline for automated testing and publishing:
@@ -121,17 +197,46 @@ The repository includes a comprehensive CI/CD pipeline for automated testing and
121197
- **Security Scanning**: Dependency and code vulnerability checks
122198
- **Provider Testing**: Validation of provider implementations
123199
- **Automated Versioning**: Git tag-based version management (no manual editing!)
200+
- **Quality Gates**: Code formatting, type checking, and test coverage validation
124201

125202
See [PIPELINE_SETUP.md](./PIPELINE_SETUP.md) for complete pipeline documentation and [AUTOMATED_VERSIONING.md](./AUTOMATED_VERSIONING.md) for version management details.
126203

204+
## Current Version
205+
206+
**Version**: 1.0.0
207+
208+
### Key Dependencies
209+
- **Pydantic**: ≥2.0.0 for data validation and serialization
210+
- **typing-extensions**: ≥4.0.0 for enhanced type hints
211+
- **Python**: ≥3.8 (tested on 3.8-3.12)
212+
213+
### Recent Updates
214+
- Enhanced type safety with comprehensive Pydantic models
215+
- Added shared common models for core resources
216+
- Improved provider registration and management
217+
- Added base classes and common utilities for provider development
218+
- Streamlined async operations with proper type hints
219+
- Updated documentation and examples with real-world usage patterns
220+
127221
## Documentation
128222

129223
- [Architecture Documentation](./ARCHITECTURE.md) - Detailed architecture overview
224+
- [Resource ID Strategy](./RESOURCE_ID_STRATEGY.md) - Hybrid path + GUID approach for resource identification
130225
- [CI/CD Pipeline Setup](./PIPELINE_SETUP.md) - Complete pipeline documentation
131226
- [Automated Versioning](./AUTOMATED_VERSIONING.md) - Git tag-based version management
132-
- [GitHub Workflows](./github/workflows/README.md) - CI/CD workflow details
227+
- [Versioning Update Guide](./VERSIONING_UPDATE.md) - Version update procedures
133228
- [PyPI Setup Guide](./.github/PYPI_SETUP.md) - Package publishing configuration
134229

230+
## Support and Contributing
231+
232+
For questions, issues, or contributions:
233+
234+
1. **Issues**: Report bugs or feature requests via GitHub Issues
235+
2. **Development**: Follow the development setup above
236+
3. **Testing**: Ensure all tests pass before submitting PRs
237+
4. **Documentation**: Update documentation for any API changes
238+
5. **Providers**: Use the common models and base classes for consistency
239+
135240
## License
136241

137242
This project is licensed under the terms specified in the LICENSE file.

0 commit comments

Comments
 (0)