Files
CHORUS/internal/licensing/validator.go
anthonyrawlins 9bdcbe0447 Integrate BACKBEAT SDK and resolve KACHING license validation
Major integrations and fixes:
- Added BACKBEAT SDK integration for P2P operation timing
- Implemented beat-aware status tracking for distributed operations
- Added Docker secrets support for secure license management
- Resolved KACHING license validation via HTTPS/TLS
- Updated docker-compose configuration for clean stack deployment
- Disabled rollback policies to prevent deployment failures
- Added license credential storage (CHORUS-DEV-MULTI-001)

Technical improvements:
- BACKBEAT P2P operation tracking with phase management
- Enhanced configuration system with file-based secrets
- Improved error handling for license validation
- Clean separation of KACHING and CHORUS deployment stacks

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-06 07:56:26 +10:00

103 lines
2.7 KiB
Go

package licensing
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"time"
)
const (
DefaultKachingURL = "http://localhost:8083" // For development testing
LicenseTimeout = 30 * time.Second
)
// LicenseConfig holds licensing information
type LicenseConfig struct {
LicenseID string
ClusterID string
KachingURL string
}
// Validator handles license validation with KACHING
type Validator struct {
config LicenseConfig
kachingURL string
client *http.Client
}
// NewValidator creates a new license validator
func NewValidator(config LicenseConfig) *Validator {
kachingURL := config.KachingURL
if kachingURL == "" {
kachingURL = DefaultKachingURL
}
return &Validator{
config: config,
kachingURL: kachingURL,
client: &http.Client{
Timeout: LicenseTimeout,
},
}
}
// Validate performs license validation with KACHING license authority
// CRITICAL: CHORUS will not start without valid license validation
func (v *Validator) Validate() error {
if v.config.LicenseID == "" || v.config.ClusterID == "" {
return fmt.Errorf("license ID and cluster ID are required")
}
// Prepare validation request
request := map[string]interface{}{
"license_id": v.config.LicenseID,
"cluster_id": v.config.ClusterID,
"metadata": map[string]string{
"product": "CHORUS",
"version": "0.1.0-dev",
"container": "true",
},
}
requestBody, err := json.Marshal(request)
if err != nil {
return fmt.Errorf("failed to marshal license request: %w", err)
}
// Call KACHING license authority
licenseURL := fmt.Sprintf("%s/v1/license/activate", v.kachingURL)
resp, err := v.client.Post(licenseURL, "application/json", bytes.NewReader(requestBody))
if err != nil {
// FAIL-CLOSED: No network = No license = No operation
return fmt.Errorf("unable to contact license authority: %w", err)
}
defer resp.Body.Close()
// Parse response
var licenseResponse map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&licenseResponse); err != nil {
return fmt.Errorf("invalid license authority response: %w", err)
}
// Check validation result
if resp.StatusCode != http.StatusOK {
message := "license validation failed"
if msg, ok := licenseResponse["message"].(string); ok {
message = msg
}
return fmt.Errorf("license validation failed: %s", message)
}
// License is valid
return nil
}
// ValidateBackground performs background license validation (for runtime checks)
// This is used for periodic license validation during operation
func (v *Validator) ValidateBackground() error {
// Similar to Validate() but with longer timeout and retry logic
// Implementation would include retry logic and graceful degradation
return v.Validate()
}