Skip to content

Commit a2d2e6f

Browse files
committed
Add missing security configs to llms
1 parent 3258763 commit a2d2e6f

File tree

4 files changed

+100
-8
lines changed

4 files changed

+100
-8
lines changed

platform-api/src/internal/dto/llm.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ type LLMProvider struct {
160160
AccessControl LLMAccessControl `json:"accessControl" yaml:"accessControl" binding:"required"`
161161
RateLimiting *LLMRateLimitingConfig `json:"rateLimiting,omitempty" yaml:"rateLimiting,omitempty"`
162162
Policies []LLMPolicy `json:"policies,omitempty" yaml:"policies,omitempty"`
163+
Security *SecurityConfig `json:"security,omitempty" yaml:"security,omitempty"`
163164
CreatedAt time.Time `json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
164165
UpdatedAt time.Time `json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
165166
}
@@ -193,8 +194,9 @@ type LLMProxy struct {
193194
VHost string `json:"vhost,omitempty" yaml:"vhost,omitempty"`
194195
Provider string `json:"provider" yaml:"provider" binding:"required"`
195196
OpenAPI string `json:"openapi,omitempty" yaml:"openapi,omitempty"`
196-
Policies []LLMPolicy `json:"policies,omitempty" yaml:"policies,omitempty"`
197-
CreatedAt time.Time `json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
197+
Policies []LLMPolicy `json:"policies,omitempty" yaml:"policies,omitempty"`
198+
Security *SecurityConfig `json:"security,omitempty" yaml:"security,omitempty"`
199+
CreatedAt time.Time `json:"createdAt,omitempty" yaml:"createdAt,omitempty"`
198200
UpdatedAt time.Time `json:"updatedAt,omitempty" yaml:"updatedAt,omitempty"`
199201
}
200202

@@ -216,3 +218,14 @@ type LLMProxyListResponse struct {
216218
List []LLMProxyListItem `json:"list" yaml:"list"`
217219
Pagination Pagination `json:"pagination" yaml:"pagination"`
218220
}
221+
222+
type SecurityConfig struct {
223+
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
224+
APIKey *APIKeySecurity `json:"apiKey,omitempty" yaml:"apiKey,omitempty"`
225+
}
226+
227+
type APIKeySecurity struct {
228+
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
229+
Key string `json:"key,omitempty" yaml:"key,omitempty"`
230+
In string `json:"in,omitempty" yaml:"in,omitempty"`
231+
}

platform-api/src/internal/model/llm.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ type LLMProviderConfig struct {
154154
AccessControl *LLMAccessControl `json:"accessControl,omitempty" db:"-"`
155155
RateLimiting *LLMRateLimitingConfig `json:"rateLimiting,omitempty" db:"-"`
156156
Policies []LLMPolicy `json:"policies,omitempty" db:"-"`
157+
Security *SecurityConfig `json:"security,omitempty" db:"-"`
157158
}
158159

159160
// LLMProxy represents an LLM proxy entity
@@ -175,10 +176,22 @@ type LLMProxy struct {
175176
}
176177

177178
type LLMProxyConfig struct {
178-
Name string `json:"name,omitempty" db:"-"`
179-
Version string `json:"version,omitempty" db:"-"`
180-
Context *string `json:"context,omitempty" db:"-"`
181-
Vhost *string `json:"vhost,omitempty" db:"-"`
182-
Provider string `json:"provider,omitempty" db:"-"`
183-
Policies []LLMPolicy `json:"policies,omitempty" db:"-"`
179+
Name string `json:"name,omitempty" db:"-"`
180+
Version string `json:"version,omitempty" db:"-"`
181+
Context *string `json:"context,omitempty" db:"-"`
182+
Vhost *string `json:"vhost,omitempty" db:"-"`
183+
Provider string `json:"provider,omitempty" db:"-"`
184+
Policies []LLMPolicy `json:"policies,omitempty" db:"-"`
185+
Security *SecurityConfig `json:"security,omitempty" db:"-"`
186+
}
187+
188+
type SecurityConfig struct {
189+
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
190+
APIKey *APIKeySecurity `json:"apiKey,omitempty" yaml:"apiKey,omitempty"`
191+
}
192+
193+
type APIKeySecurity struct {
194+
Enabled *bool `json:"enabled,omitempty" yaml:"enabled,omitempty"`
195+
Key string `json:"key,omitempty" yaml:"key,omitempty"`
196+
In string `json:"in,omitempty" yaml:"in,omitempty"`
184197
}

platform-api/src/internal/service/llm.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ func (s *LLMProviderService) Create(orgUUID, createdBy string, req *dto.LLMProvi
277277
AccessControl: mapAccessControl(&req.AccessControl),
278278
RateLimiting: mapRateLimiting(req.RateLimiting),
279279
Policies: mapPolicies(req.Policies),
280+
Security: mapSecurityDTOToModel(req.Security),
280281
},
281282
}
282283

@@ -414,6 +415,7 @@ func (s *LLMProviderService) Update(orgUUID, handle string, req *dto.LLMProvider
414415
AccessControl: mapAccessControl(&req.AccessControl),
415416
RateLimiting: mapRateLimiting(req.RateLimiting),
416417
Policies: mapPolicies(req.Policies),
418+
Security: mapSecurityDTOToModel(req.Security),
417419
},
418420
}
419421

@@ -498,6 +500,7 @@ func (s *LLMProxyService) Create(orgUUID, createdBy string, req *dto.LLMProxy) (
498500
Vhost: &req.VHost,
499501
Provider: req.Provider,
500502
Policies: mapPolicies(req.Policies),
503+
Security: mapSecurityDTOToModel(req.Security),
501504
},
502505
}
503506

@@ -672,6 +675,7 @@ func (s *LLMProxyService) Update(orgUUID, handle string, req *dto.LLMProxy) (*dt
672675
Vhost: &req.VHost,
673676
Provider: req.Provider,
674677
Policies: mapPolicies(req.Policies),
678+
Security: mapSecurityDTOToModel(req.Security),
675679
},
676680
}
677681
if err := s.repo.Update(m); err != nil {
@@ -981,6 +985,7 @@ func mapProviderModelToDTO(m *model.LLMProvider, templateHandle string) *dto.LLM
981985
RateLimiting: mapRateLimitingDTO(m.Configuration.RateLimiting),
982986
Upstream: mapUpstreamConfigToDTO(m.Configuration.Upstream),
983987
AccessControl: dto.LLMAccessControl{Mode: "deny_all"},
988+
Security: mapSecurityModelToDTO(m.Configuration.Security),
984989
CreatedAt: m.CreatedAt,
985990
UpdatedAt: m.UpdatedAt,
986991
}
@@ -1278,6 +1283,7 @@ func mapProxyModelToDTO(m *model.LLMProxy) *dto.LLMProxy {
12781283
VHost: vhostValue,
12791284
Provider: m.Configuration.Provider,
12801285
OpenAPI: m.OpenAPISpec,
1286+
Security: mapSecurityModelToDTO(m.Configuration.Security),
12811287
CreatedAt: m.CreatedAt,
12821288
UpdatedAt: m.UpdatedAt,
12831289
}
@@ -1293,3 +1299,25 @@ func mapProxyModelToDTO(m *model.LLMProxy) *dto.LLMProxy {
12931299
}
12941300
return out
12951301
}
1302+
1303+
func mapSecurityDTOToModel(in *dto.SecurityConfig) *model.SecurityConfig {
1304+
if in == nil {
1305+
return nil
1306+
}
1307+
out := &model.SecurityConfig{Enabled: in.Enabled}
1308+
if in.APIKey != nil {
1309+
out.APIKey = &model.APIKeySecurity{Enabled: in.APIKey.Enabled, Key: in.APIKey.Key, In: in.APIKey.In}
1310+
}
1311+
return out
1312+
}
1313+
1314+
func mapSecurityModelToDTO(in *model.SecurityConfig) *dto.SecurityConfig {
1315+
if in == nil {
1316+
return nil
1317+
}
1318+
out := &dto.SecurityConfig{Enabled: in.Enabled}
1319+
if in.APIKey != nil {
1320+
out.APIKey = &dto.APIKeySecurity{Enabled: in.APIKey.Enabled, Key: in.APIKey.Key, In: in.APIKey.In}
1321+
}
1322+
return out
1323+
}

platform-api/src/resources/openapi.yaml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,6 +2466,40 @@ components:
24662466
description: List of channels exposed by this API
24672467
items:
24682468
$ref: '#/components/schemas/Channel'
2469+
2470+
SecurityConfig:
2471+
title: Security Configuration
2472+
description: Defines security mechanisms (API key, OAuth2) applicable to the API
2473+
type: object
2474+
properties:
2475+
enabled:
2476+
type: boolean
2477+
description: Whether security is enabled
2478+
example: true
2479+
apiKey:
2480+
$ref: '#/components/schemas/APIKeySecurity'
2481+
2482+
APIKeySecurity:
2483+
title: API Key Security
2484+
description: Configuration for API key based authentication
2485+
type: object
2486+
properties:
2487+
enabled:
2488+
type: boolean
2489+
description: Whether API key authentication is enabled
2490+
example: true
2491+
key:
2492+
type: string
2493+
description: Name of the header or query parameter to be used for the API key
2494+
example: "X-API-Key"
2495+
in:
2496+
type: string
2497+
description: Location of the API key (header or query)
2498+
enum:
2499+
- header
2500+
- query
2501+
example: "header"
2502+
24692503
Operation:
24702504
title: API Operation
24712505
type: object
@@ -4413,6 +4447,8 @@ components:
44134447
description: List of policies applied only to this operation (overrides or adds to API-level policies)
44144448
items:
44154449
$ref: "#/components/schemas/LLMPolicy"
4450+
security:
4451+
$ref: '#/components/schemas/SecurityConfig'
44164452
createdAt:
44174453
type: string
44184454
format: date-time
@@ -4592,6 +4628,8 @@ components:
45924628
description: List of policies applied only to this operation (overrides or adds to API-level policies)
45934629
items:
45944630
$ref: "#/components/schemas/LLMPolicy"
4631+
security:
4632+
$ref: '#/components/schemas/SecurityConfig'
45954633
createdAt:
45964634
type: string
45974635
format: date-time

0 commit comments

Comments
 (0)