Skip to content

Latest commit

 

History

History
173 lines (135 loc) · 5.32 KB

File metadata and controls

173 lines (135 loc) · 5.32 KB

PikaCloudConnector Implementation Summary

Overview

I have successfully created a PikaCloudConnector in the connectors package that supports uploading files through the StorageApiController#Upload action. The implementation bypasses authorization and antiforgery token validation as requested.

Files Created/Modified

New Files:

  1. connectors/PikaCloudConnector.go - Main connector implementation
  2. PikaCloudHandler.go - Integration with file watcher
  3. tools/test_pikacloud.go - Test utility for the connector
  4. config_with_pikacloud.json - Example configuration with PikaCloud settings
  5. connectors/README.md - Comprehensive documentation

Modified Files:

  1. Config.go - Added PikaCloud configuration support
  2. Main.go - Integrated PikaCloud handler initialization
  3. FileWatcher.go - Added PikaCloud-enabled file watching
  4. Makefile - Added build targets for tools

Key Features Implemented

PikaCloudConnector

  • HTTP Multipart Upload - Uploads files using multipart/form-data
  • Retry Logic - Configurable retry attempts with exponential backoff
  • Timeout Handling - Configurable request timeouts
  • Custom Path Support - Upload files with custom target paths
  • Connection Testing - Test connectivity to PikaCore API
  • Error Handling - Comprehensive error handling and logging
  • Background Uploads - Non-blocking uploads when integrated with file watcher

PikaCloudHandler

  • File Watcher Integration - Seamless integration with existing file watcher
  • Automatic Operations - Auto-upload on create, modify, rename events
  • Path Mapping - Intelligent relative path calculation
  • Dual Operation - Performs both local filesystem and cloud operations

Configuration

  • JSON Configuration - Easy configuration via JSON file
  • Optional Integration - PikaCloud can be enabled/disabled
  • Backward Compatibility - Existing configurations continue to work

API Compatibility

The connector is designed to work with PikaCore's StorageApiController:

[HttpPost]
[ActionName("{bucketId}")]
public async Task<IActionResult> Upload(string bucketId)

Request Format:

  • Method: POST
  • URL: /Api/v1/Storage/{bucketId}
  • Content-Type: multipart/form-data
  • Form Field: File content with field name as target path
  • File Name: Original filename in form disposition

Response Format:

{
    "detail": "Wgrano plik",
    "cgid": "generated-guid", 
    "bucketId": "bucket-id",
    "targetPath": "encoded-target-path"
}

Usage Examples

Basic Configuration

{
    "folders": ["/home/ofca/sync"],
    "workDir": "/home/ofca/sync", 
    "dstPath": "/mnt/public",
    "pikaCloud": {
        "baseUrl": "https://pikacore.example.com",
        "bucketId": "12345678-1234-1234-1234-123456789012",
        "timeout": 30,
        "retryCount": 3
    }
}

Manual Upload

config := connectors.PikaCloudConfig{
    BaseURL:    "https://pikacore.example.com",
    BucketID:   "your-bucket-id",
    Timeout:    30,
    RetryCount: 3,
}

connector := connectors.NewPikaCloudConnector(config)
response, err := connector.UploadFile("/path/to/file.txt")

Testing Connection

# Build test utility
make build-tools

# Test upload with auto-generated file
./tools/test_pikacloud -url https://pikacore.example.com -bucket your-bucket-id -test

# Test upload with specific file  
./tools/test_pikacloud -url https://pikacore.example.com -bucket your-bucket-id -file /path/to/test.txt

Security Considerations

⚠️ Current Implementation Notes (as requested):

  • Authorization bypassed - No authentication headers sent
  • CSRF protection bypassed - No antiforgery tokens included
  • TLS verification - Uses default Go HTTP client settings

For production deployment, consider implementing:

  • Authentication (JWT, API keys, etc.)
  • CSRF protection
  • Custom TLS configuration
  • Rate limiting compliance

Integration Flow

  1. File Event → File watcher detects change
  2. Local Operation → Standard filesystem operation executed
  3. Cloud Upload → If PikaCloud enabled, file uploaded in background
  4. Logging → All operations logged for monitoring

Build and Test

# Build main service
make build

# Build test utilities
make build-tools

# Test configuration (replace with actual values)
./tools/test_pikacloud \
  -url https://your-pikacore-instance.com \
  -bucket your-bucket-id \
  -test

# Run with PikaCloud enabled
./pikafileservice -c config_with_pikacloud.json -d

Error Handling

The implementation includes robust error handling for:

  • Network connectivity issues
  • HTTP errors (4xx/5xx responses)
  • File system errors
  • JSON parsing errors
  • Timeout conditions
  • Retry exhaustion

All errors are logged with appropriate detail levels for debugging.

Next Steps

The connector is ready for use with your PikaCore StorageApiController. To implement authentication and CSRF protection in the future:

  1. Add authentication header support to PikaCloudConfig
  2. Implement token acquisition/refresh logic
  3. Add antiforgery token handling
  4. Extend test utility to support authenticated testing

The current implementation provides a solid foundation that can be extended with security features when needed.