@@ -11,44 +11,45 @@ import (
1111
1212// TableKey represents an API key configuration in the database
1313type TableKey struct {
14- ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
15- Name string `gorm:"type:varchar(255);uniqueIndex:idx_key_name;not null" json:"name"`
16- ProviderID uint `gorm:"index;not null" json:"provider_id"`
17- Provider string `gorm:"index;type:varchar(50)" json:"provider"` // ModelProvider as string
18- KeyID string `gorm:"type:varchar(255);uniqueIndex:idx_key_id;not null" json:"key_id"` // UUID from schemas.Key
14+ ID uint `gorm:"primaryKey;autoIncrement" json:"id"`
15+ Name string `gorm:"type:varchar(255);uniqueIndex:idx_key_name;not null" json:"name"`
16+ ProviderID uint `gorm:"index;not null" json:"provider_id"`
17+ Provider string `gorm:"index;type:varchar(50)" json:"provider"` // ModelProvider as string
18+ KeyID string `gorm:"type:varchar(255);uniqueIndex:idx_key_id;not null" json:"key_id"` // UUID from schemas.Key
1919 Value schemas.EnvVar `gorm:"type:text;not null" json:"value"`
20- ModelsJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
21- Weight * float64 `json:"weight"`
22- Enabled * bool `gorm:"default:true" json:"enabled,omitempty"`
23- CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
24- UpdatedAt time.Time `gorm:"index;not null" json:"updated_at"`
20+ ModelsJSON string `gorm:"type:text" json:"-"` // JSON serialized []string
21+ Weight * float64 `json:"weight"`
22+ Enabled * bool `gorm:"default:true" json:"enabled,omitempty"`
23+ CreatedAt time.Time `gorm:"index;not null" json:"created_at"`
24+ UpdatedAt time.Time `gorm:"index;not null" json:"updated_at"`
2525
2626 // Config hash is used to detect changes synced from config.json file
2727 ConfigHash string `gorm:"type:varchar(255);null" json:"config_hash"`
2828
2929 // Azure config fields (embedded instead of separate table for simplicity)
3030 AzureEndpoint * schemas.EnvVar `gorm:"type:text" json:"azure_endpoint,omitempty"`
3131 AzureAPIVersion * schemas.EnvVar `gorm:"type:varchar(50)" json:"azure_api_version,omitempty"`
32- AzureDeploymentsJSON * string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
32+ AzureDeploymentsJSON * string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
3333 AzureClientID * schemas.EnvVar `gorm:"type:varchar(255)" json:"azure_client_id,omitempty"`
3434 AzureClientSecret * schemas.EnvVar `gorm:"type:text" json:"azure_client_secret,omitempty"`
3535 AzureTenantID * schemas.EnvVar `gorm:"type:varchar(255)" json:"azure_tenant_id,omitempty"`
36+ AzureScopesJSON * string `gorm:"column:azure_scopes;type:text" json:"-"` // JSON serialized []string
3637
3738 // Vertex config fields (embedded)
3839 VertexProjectID * schemas.EnvVar `gorm:"type:varchar(255)" json:"vertex_project_id,omitempty"`
3940 VertexProjectNumber * schemas.EnvVar `gorm:"type:varchar(255)" json:"vertex_project_number,omitempty"`
4041 VertexRegion * schemas.EnvVar `gorm:"type:varchar(100)" json:"vertex_region,omitempty"`
4142 VertexAuthCredentials * schemas.EnvVar `gorm:"type:text" json:"vertex_auth_credentials,omitempty"`
42- VertexDeploymentsJSON * string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
43+ VertexDeploymentsJSON * string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
4344
4445 // Bedrock config fields (embedded)
4546 BedrockAccessKey * schemas.EnvVar `gorm:"type:varchar(255)" json:"bedrock_access_key,omitempty"`
4647 BedrockSecretKey * schemas.EnvVar `gorm:"type:text" json:"bedrock_secret_key,omitempty"`
4748 BedrockSessionToken * schemas.EnvVar `gorm:"type:text" json:"bedrock_session_token,omitempty"`
4849 BedrockRegion * schemas.EnvVar `gorm:"type:varchar(100)" json:"bedrock_region,omitempty"`
4950 BedrockARN * schemas.EnvVar `gorm:"type:text" json:"bedrock_arn,omitempty"`
50- BedrockDeploymentsJSON * string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
51- BedrockBatchS3ConfigJSON * string `gorm:"type:text" json:"-"` // JSON serialized schemas.BatchS3Config
51+ BedrockDeploymentsJSON * string `gorm:"type:text" json:"-"` // JSON serialized map[string]string
52+ BedrockBatchS3ConfigJSON * string `gorm:"type:text" json:"-"` // JSON serialized schemas.BatchS3Config
5253
5354 // Batch API configuration
5455 UseForBatchAPI * bool `gorm:"default:false" json:"use_for_batch_api,omitempty"` // Whether this key can be used for batch API operations
@@ -95,6 +96,16 @@ func (k *TableKey) BeforeSave(tx *gorm.DB) error {
9596 k .AzureClientID = k .AzureKeyConfig .ClientID
9697 k .AzureClientSecret = k .AzureKeyConfig .ClientSecret
9798 k .AzureTenantID = k .AzureKeyConfig .TenantID
99+ if len (k .AzureKeyConfig .Scopes ) > 0 {
100+ data , err := json .Marshal (k .AzureKeyConfig .Scopes )
101+ if err != nil {
102+ return err
103+ }
104+ s := string (data )
105+ k .AzureScopesJSON = & s
106+ } else {
107+ k .AzureScopesJSON = nil
108+ }
98109 if k .AzureKeyConfig .Deployments != nil {
99110 data , err := json .Marshal (k .AzureKeyConfig .Deployments )
100111 if err != nil {
@@ -112,6 +123,7 @@ func (k *TableKey) BeforeSave(tx *gorm.DB) error {
112123 k .AzureClientID = nil
113124 k .AzureClientSecret = nil
114125 k .AzureTenantID = nil
126+ k .AzureScopesJSON = nil
115127 }
116128 // BeforeSave is called before saving the key to the database
117129 if k .VertexKeyConfig != nil {
@@ -217,12 +229,19 @@ func (k *TableKey) AfterFind(tx *gorm.DB) error {
217229 }
218230 // Reconstruct Azure config if fields are present
219231 if k .AzureEndpoint != nil {
232+ var scopes []string
233+ if k .AzureScopesJSON != nil && * k .AzureScopesJSON != "" {
234+ if err := json .Unmarshal ([]byte (* k .AzureScopesJSON ), & scopes ); err != nil {
235+ return err
236+ }
237+ }
220238 azureConfig := & schemas.AzureKeyConfig {
221239 Endpoint : * schemas .NewEnvVar ("" ),
222240 APIVersion : k .AzureAPIVersion ,
223241 ClientID : k .AzureClientID ,
224242 ClientSecret : k .AzureClientSecret ,
225243 TenantID : k .AzureTenantID ,
244+ Scopes : scopes ,
226245 }
227246
228247 if k .AzureEndpoint != nil {
0 commit comments