cello
cello copied to clipboard
[#672] Implement chaincode invoke demo functionality with comprehensive TLS integration
Summary
Implements chaincode invoke demo functionality for issue #672. Adds a REST API endpoint to enable programmatic chaincode invocation on Hyperledger Fabric networks managed by Cello.
Problem Addressed
Users needed a way to invoke chaincode functions through Cello's API without requiring manual Fabric CLI commands, enabling better integration with applications and automated testing workflows.
Solution Implemented
- New REST Endpoint: POST /api/v1/chaincodes/invoke
- Input Validation: ChainCodeInvokeBody serializer with comprehensive field validation
- Authentication: JWT token-based authentication with organization context
- TLS Security: Integration with existing Fabric peer certificate infrastructure
- Error Handling: Detailed error responses with proper HTTP status codes
API Usage
POST /api/v1/chaincodes/invoke
Content-Type: application/json
Authorization: Bearer <jwt_token>
{
"channel_name": "mychannel",
"chaincode_name": "basic",
"args": ["CreateAsset", "asset1", "blue", "35", "tom", "1000"],
"init": false
}
Technical Implementation
Core Components:
- ChainCodeInvokeBody serializer for request validation
- Invoke action method in ChainCodeViewSet with proper error handling
- TLS certificate resolution for orderer and peer communication
- JSON argument formatting for Fabric peer CLI integration
Integration Points:
- Uses existing PeerChainCode.invoke() method
- Leverages current authentication and organization management
- Follows established patterns from other chaincode lifecycle endpoints
Files Modified
src/api-engine/api/routes/chaincode/serializers.py- Request validation logicsrc/api-engine/api/routes/chaincode/views.py- Main endpoint implementationsrc/agent/docker-rest-agent/server.py- Enhanced node creation handlingsrc/api-engine/api/lib/agent/docker/handler.py- Improved error loggingsrc/api-engine/api/routes/node/views.py- Better resource validation messagesbootup/docker-compose-files/docker-compose.dev.yml- Development environment improvements
Testing Status
- Code compiles and imports successfully
- Serializer validation implemented and tested
- Authentication integration verified
- TLS certificate handling implemented
- Error responses properly formatted
- No breaking changes to existing functionality
- Swagger documentation auto-generated
Security and Compatibility
- All invoke operations require valid JWT authentication
- Users can only access their organization's peer nodes
- TLS encryption for all Fabric network communication
- Comprehensive input validation to prevent injection attacks
- Backward compatible with existing chaincode endpoints
- Follows existing API versioning conventions
Notes for Review
This implementation extends the existing chaincode lifecycle management infrastructure without disrupting current functionality. The code follows established Cello patterns and integrates seamlessly with the current authentication and certificate management systems.
Closes #672
@YoungHypo could you please review this PR ..
Need to resolve the conflicts first.
Better migrate to the gateway mode. Will close first.