mirror of
https://github.com/andwati/telecom-platform.git
synced 2026-10-20 03:44:25 +00:00
feat: Add carrier configuration file loading with JSON-based carrier setup and validation
- Add carriers.json with AT&T US, Verizon US, T-Mobile Germany, Orange France, and Vodafone UK configurations - Add LoadCarriersFromFile with JSON parsing and config file reading - Add ConvertConfigToCarriers with model-to-carrier conversion logic - Add validateCarrier with ID, name, MCC, MNC, country code, and ES2 config validation - Replace hardcoded carrier setup with file-based configuration loading - Add success
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
{
|
||||
"carriers": [
|
||||
{
|
||||
"id": "att-us",
|
||||
"name": "AT&T US",
|
||||
"mcc": "310",
|
||||
"mnc": "410",
|
||||
"country_code": "US",
|
||||
"is_active": true,
|
||||
"priority": 90,
|
||||
"es2_config": {
|
||||
"base_url": "https://es2plus.att.com",
|
||||
"api_key": "production-api-key-att",
|
||||
"insecure_skip_verify": false,
|
||||
"functionality_requester_id": "telecom-platform"
|
||||
},
|
||||
"capabilities": {
|
||||
"supported_profile_types": ["operational", "testing"],
|
||||
"features": ["bulk_download", "remote_provisioning"],
|
||||
"max_concurrent_requests": 100
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "verizon-us",
|
||||
"name": "Verizon US",
|
||||
"mcc": "311",
|
||||
"mnc": "480",
|
||||
"country_code": "US",
|
||||
"is_active": true,
|
||||
"priority": 85,
|
||||
"es2_config": {
|
||||
"base_url": "https://es2plus.verizon.com",
|
||||
"api_key": "production-api-key-verizon",
|
||||
"insecure_skip_verify": false,
|
||||
"functionality_requester_id": "telecom-platform"
|
||||
},
|
||||
"capabilities": {
|
||||
"supported_profile_types": ["operational", "testing"],
|
||||
"features": ["bulk_download"],
|
||||
"max_concurrent_requests": 80
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "tmobile-de",
|
||||
"name": "T-Mobile Germany",
|
||||
"mcc": "262",
|
||||
"mnc": "01",
|
||||
"country_code": "DE",
|
||||
"is_active": true,
|
||||
"priority": 75,
|
||||
"es2_config": {
|
||||
"base_url": "https://es2plus.t-mobile.de",
|
||||
"api_key": "production-api-key-tmobile",
|
||||
"insecure_skip_verify": false,
|
||||
"functionality_requester_id": "telecom-platform"
|
||||
},
|
||||
"capabilities": {
|
||||
"supported_profile_types": ["operational"],
|
||||
"features": ["remote_provisioning"],
|
||||
"max_concurrent_requests": 60
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "orange-fr",
|
||||
"name": "Orange France",
|
||||
"mcc": "208",
|
||||
"mnc": "01",
|
||||
"country_code": "FR",
|
||||
"is_active": true,
|
||||
"priority": 70,
|
||||
"es2_config": {
|
||||
"base_url": "https://es2plus.orange.fr",
|
||||
"api_key": "production-api-key-orange",
|
||||
"insecure_skip_verify": false,
|
||||
"functionality_requester_id": "telecom-platform"
|
||||
},
|
||||
"capabilities": {
|
||||
"supported_profile_types": ["operational", "testing"],
|
||||
"features": [],
|
||||
"max_concurrent_requests": 50
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "vodafone-uk",
|
||||
"name": "Vodafone UK",
|
||||
"mcc": "234",
|
||||
"mnc": "15",
|
||||
"country_code": "GB",
|
||||
"is_active": true,
|
||||
"priority": 80,
|
||||
"es2_config": {
|
||||
"base_url": "https://es2plus.vodafone.co.uk",
|
||||
"api_key": "production-api-key-vodafone",
|
||||
"insecure_skip_verify": false,
|
||||
"functionality_requester_id": "telecom-platform"
|
||||
},
|
||||
"capabilities": {
|
||||
"supported_profile_types": ["operational", "testing"],
|
||||
"features": ["bulk_download", "remote_provisioning"],
|
||||
"max_concurrent_requests": 75
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,134 +1,86 @@
|
||||
package integration
|
||||
|
||||
import (
|
||||
"log"
|
||||
"time"
|
||||
"fmt"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/config"
|
||||
"github.com/nutcas3/telecom-platform/apps/carrier-connector/internal/smdp"
|
||||
)
|
||||
|
||||
// SetupCarriers configures default carriers for demonstration
|
||||
// SetupCarriers loads real carrier configurations from database or config files
|
||||
func (si *SelectionIntegration) SetupCarriers() error {
|
||||
// Configure sample carriers with different characteristics
|
||||
carriers := []*smdp.Carrier{
|
||||
{
|
||||
ID: "att-us",
|
||||
Name: "AT&T US",
|
||||
MCC: "310",
|
||||
MNC: "410",
|
||||
CountryCode: "US",
|
||||
IsActive: true,
|
||||
Priority: 90,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.att.com",
|
||||
APIKey: "demo-key-att",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{"bulk_download", "remote_provisioning"},
|
||||
MaxConcurrentRequests: 100,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 1000,
|
||||
SuccessfulRequests: 980,
|
||||
FailedRequests: 20,
|
||||
AverageResponseTime: 150 * time.Millisecond,
|
||||
RequestRate: 10.5,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "verizon-us",
|
||||
Name: "Verizon US",
|
||||
MCC: "311",
|
||||
MNC: "480",
|
||||
CountryCode: "US",
|
||||
IsActive: true,
|
||||
Priority: 85,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.verizon.com",
|
||||
APIKey: "demo-key-verizon",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{"bulk_download"},
|
||||
MaxConcurrentRequests: 80,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 800,
|
||||
SuccessfulRequests: 790,
|
||||
FailedRequests: 10,
|
||||
AverageResponseTime: 120 * time.Millisecond,
|
||||
RequestRate: 8.2,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "tmobile-de",
|
||||
Name: "T-Mobile Germany",
|
||||
MCC: "262",
|
||||
MNC: "01",
|
||||
CountryCode: "DE",
|
||||
IsActive: true,
|
||||
Priority: 75,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.t-mobile.de",
|
||||
APIKey: "demo-key-tmobile",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational"},
|
||||
Features: []string{"remote_provisioning"},
|
||||
MaxConcurrentRequests: 60,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 600,
|
||||
SuccessfulRequests: 570,
|
||||
FailedRequests: 30,
|
||||
AverageResponseTime: 200 * time.Millisecond,
|
||||
RequestRate: 6.8,
|
||||
},
|
||||
},
|
||||
{
|
||||
ID: "orange-fr",
|
||||
Name: "Orange France",
|
||||
MCC: "208",
|
||||
MNC: "01",
|
||||
CountryCode: "FR",
|
||||
IsActive: true,
|
||||
Priority: 70,
|
||||
ES2Config: &config.ES2Config{
|
||||
BaseURL: "https://es2plus.orange.fr",
|
||||
APIKey: "demo-key-orange",
|
||||
InsecureSkipVerify: false,
|
||||
FunctionalityRequesterID: "telecom-platform",
|
||||
},
|
||||
Capabilities: &smdp.CarrierCapabilities{
|
||||
SupportedProfileTypes: []string{"operational", "testing"},
|
||||
Features: []string{},
|
||||
MaxConcurrentRequests: 50,
|
||||
},
|
||||
Metrics: &smdp.CarrierMetrics{
|
||||
TotalRequests: 400,
|
||||
SuccessfulRequests: 380,
|
||||
FailedRequests: 20,
|
||||
AverageResponseTime: 180 * time.Millisecond,
|
||||
RequestRate: 4.5,
|
||||
},
|
||||
},
|
||||
logger := logrus.New()
|
||||
logger.SetLevel(logrus.InfoLevel)
|
||||
|
||||
logger.Info("Loading carriers from configuration")
|
||||
|
||||
// Load carriers from configuration file
|
||||
configPath := "configs/carriers.json"
|
||||
|
||||
config, err := LoadCarriersFromFile(configPath)
|
||||
if err != nil {
|
||||
logger.WithError(err).Error("Failed to load carriers from config file")
|
||||
return fmt.Errorf("failed to load carriers from config: %w", err)
|
||||
}
|
||||
|
||||
// Add carriers to the manager
|
||||
carriers, err := ConvertConfigToCarriers(config)
|
||||
if err != nil {
|
||||
logger.WithError(err).Error("Failed to convert config to carriers")
|
||||
return fmt.Errorf("failed to convert config: %w", err)
|
||||
}
|
||||
|
||||
// Validate and add carriers to SMDP manager
|
||||
successCount := 0
|
||||
for _, carrier := range carriers {
|
||||
if err := si.manager.AddCarrier(carrier); err != nil {
|
||||
return err
|
||||
if err := validateCarrier(carrier); err != nil {
|
||||
logger.WithError(err).WithField("carrier_id", carrier.ID).Error("Carrier validation failed")
|
||||
continue
|
||||
}
|
||||
|
||||
if err := si.manager.AddCarrier(carrier); err != nil {
|
||||
logger.WithError(err).WithField("carrier_id", carrier.ID).Error("Failed to add carrier to manager")
|
||||
continue
|
||||
}
|
||||
successCount++
|
||||
}
|
||||
|
||||
logger.WithFields(logrus.Fields{
|
||||
"config_file": configPath,
|
||||
"total_loaded": len(carriers),
|
||||
"success_count": successCount,
|
||||
"failed_count": len(carriers) - successCount,
|
||||
}).Info("Carriers loaded from configuration file")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// validateCarrier validates carrier configuration
|
||||
func validateCarrier(carrier *smdp.Carrier) error {
|
||||
if carrier.ID == "" {
|
||||
return fmt.Errorf("carrier ID is required")
|
||||
}
|
||||
if carrier.Name == "" {
|
||||
return fmt.Errorf("carrier name is required")
|
||||
}
|
||||
if carrier.MCC == "" {
|
||||
return fmt.Errorf("carrier MCC is required")
|
||||
}
|
||||
if carrier.MNC == "" {
|
||||
return fmt.Errorf("carrier MNC is required")
|
||||
}
|
||||
if carrier.CountryCode == "" {
|
||||
return fmt.Errorf("carrier country code is required")
|
||||
}
|
||||
if carrier.ES2Config == nil {
|
||||
return fmt.Errorf("carrier ES2 config is required")
|
||||
}
|
||||
if carrier.ES2Config.BaseURL == "" {
|
||||
return fmt.Errorf("carrier ES2 base URL is required")
|
||||
}
|
||||
if carrier.ES2Config.APIKey == "" {
|
||||
return fmt.Errorf("carrier ES2 API key is required")
|
||||
}
|
||||
|
||||
log.Printf("Added %d carriers to the selection manager", len(carriers))
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user