Skip to content

Commit 518ed6c

Browse files
fixing issues related to DP to CP and AI Provider
1 parent 3b15f1e commit 518ed6c

File tree

2 files changed

+81
-29
lines changed

2 files changed

+81
-29
lines changed

apim-apk-agent/internal/synchronizer/aiproviders_fetcher.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ func createAIProvider(aiProvider *eventhubTypes.AIProvider) dpv1alpha4.AIProvide
191191
"InitiateFrom": "CP",
192192
"CPName": aiProvider.Name,
193193
}
194-
var modelInputSource string
195-
var modelAttributeIdentifier string
194+
var requestModelInputSource string
195+
var requestModelAttributeIdentifier string
196+
var responseModelInputSource string
197+
var responseModelAttributeIdentifier string
196198
var promptTokenCountInputSource string
197199
var promptTokenCountAttributeIdentifier string
198200
var completionTokenCountInputSource string
@@ -207,9 +209,12 @@ func createAIProvider(aiProvider *eventhubTypes.AIProvider) dpv1alpha4.AIProvide
207209
}
208210

209211
for _, field := range config.Metadata {
210-
if field.AttributeName == "model" {
211-
modelInputSource = field.InputSource
212-
modelAttributeIdentifier = field.AttributeIdentifier
212+
if field.AttributeName == "requestModel" {
213+
requestModelInputSource = field.InputSource
214+
requestModelAttributeIdentifier = field.AttributeIdentifier
215+
} else if field.AttributeName == "responseModel" {
216+
responseModelInputSource = field.InputSource
217+
responseModelAttributeIdentifier = field.AttributeIdentifier
213218
} else if field.AttributeName == "promptTokenCount" {
214219
promptTokenCountInputSource = field.InputSource
215220
promptTokenCountAttributeIdentifier = field.AttributeIdentifier
@@ -233,12 +238,12 @@ func createAIProvider(aiProvider *eventhubTypes.AIProvider) dpv1alpha4.AIProvide
233238
ProviderAPIVersion: aiProvider.APIVersion,
234239
Organization: aiProvider.Organization,
235240
RequestModel: dpv1alpha4.ValueDetails{
236-
In: modelInputSource,
237-
Value: modelAttributeIdentifier,
241+
In: requestModelInputSource,
242+
Value: requestModelAttributeIdentifier,
238243
},
239244
ResponseModel: dpv1alpha4.ValueDetails{
240-
In: modelInputSource,
241-
Value: modelAttributeIdentifier,
245+
In: responseModelInputSource,
246+
Value: responseModelAttributeIdentifier,
242247
},
243248
SupportedModels: []string{"gpt-4o", "gpt-3.5", "gpt-4o-mini"},
244249
RateLimitFields: dpv1alpha4.RateLimitFields{

apim-apk-agent/pkg/managementserver/rest_server.go

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,36 @@ func StartInternalServer(port uint) {
107107
if strings.ToUpper(event.API.APIType) == "GRAPHQL" {
108108
definitionPath = fmt.Sprintf("%s-%s/Definitions/schema.graphql", event.API.APIName, event.API.APIVersion)
109109
}
110-
zipFiles := []utils.ZipFile{{
111-
Path: fmt.Sprintf("%s-%s/api.yaml", event.API.APIName, event.API.APIVersion),
112-
Content: apiYaml,
113-
}, {
114-
Path: fmt.Sprintf("%s-%s/endpoints.yaml", event.API.APIName, event.API.APIVersion),
115-
Content: endpointsYaml,
116-
}, {
117-
Path: fmt.Sprintf("%s-%s/deployment_environments.yaml", event.API.APIName, event.API.APIVersion),
118-
Content: deploymentContent,
119-
}, {
120-
Path: definitionPath,
121-
Content: definition,
122-
}}
110+
var zipFiles []utils.ZipFile
111+
logger.LoggerMgtServer.Debugf("endpoints yaml: %s", endpointsYaml)
112+
if endpointsYaml != "{}\n" {
113+
logger.LoggerMgtServer.Debugf("Creating zip file with endpoints")
114+
zipFiles = []utils.ZipFile{{
115+
Path: fmt.Sprintf("%s-%s/api.yaml", event.API.APIName, event.API.APIVersion),
116+
Content: apiYaml,
117+
}, {
118+
Path: fmt.Sprintf("%s-%s/endpoints.yaml", event.API.APIName, event.API.APIVersion),
119+
Content: endpointsYaml,
120+
}, {
121+
Path: fmt.Sprintf("%s-%s/deployment_environments.yaml", event.API.APIName, event.API.APIVersion),
122+
Content: deploymentContent,
123+
}, {
124+
Path: definitionPath,
125+
Content: definition,
126+
}}
127+
} else {
128+
logger.LoggerMgtServer.Debugf("Creating zip file without endpoints")
129+
zipFiles = []utils.ZipFile{{
130+
Path: fmt.Sprintf("%s-%s/api.yaml", event.API.APIName, event.API.APIVersion),
131+
Content: apiYaml,
132+
}, {
133+
Path: fmt.Sprintf("%s-%s/deployment_environments.yaml", event.API.APIName, event.API.APIVersion),
134+
Content: deploymentContent,
135+
}, {
136+
Path: definitionPath,
137+
Content: definition,
138+
}}
139+
}
123140
var buf bytes.Buffer
124141
if err := utils.CreateZipFile(&buf, zipFiles); err != nil {
125142
logger.LoggerMgtServer.Errorf("Error while creating apim zip file for api uuid: %s. Error: %+v", event.API.APIUUID, err)
@@ -479,8 +496,8 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string, string) {
479496
for _, e := range apimEndpints {
480497
// Build the top-level map for this endpoint
481498
endpointMap := map[string]interface{}{
482-
"endpointUuid": e.EndpointUUID,
483-
"endpointName": e.EndpointName,
499+
"id": e.EndpointUUID,
500+
"name": e.EndpointName,
484501
"deploymentStage": e.DeploymentStage, // e.g. "PRODUCTION" or "SANDBOX"
485502
}
486503

@@ -513,7 +530,7 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string, string) {
513530
"apiKeyValue": sec.APIKeyValue,
514531
"apiKeyIdentifierType": sec.APIKeyIdentifierType,
515532
"username": sec.Username,
516-
"customParameters": sec.CustomParameters, // Or map[string]string{}
533+
"customParameters": "{}", // Or map[string]string{}
517534
"connectionTimeoutDuration": sec.ConnectionTimeoutDuration,
518535
"connectionRequestTimeoutDuration": sec.ConnectionRequestTimeoutDuration,
519536
"socketTimeoutDuration": sec.SocketTimeoutDuration,
@@ -537,7 +554,7 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string, string) {
537554
"apiKeyValue": sec.APIKeyValue,
538555
"apiKeyIdentifierType": sec.APIKeyIdentifierType,
539556
"username": sec.Username,
540-
"customParameters": sec.CustomParameters,
557+
"customParameters": "{}",
541558
"connectionTimeoutDuration": sec.ConnectionTimeoutDuration,
542559
"connectionRequestTimeoutDuration": sec.ConnectionRequestTimeoutDuration,
543560
"socketTimeoutDuration": sec.SocketTimeoutDuration,
@@ -566,7 +583,7 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string, string) {
566583
}
567584

568585
var endpointsData map[string]interface{}
569-
if prodCount > 0 || sandCount > 0 {
586+
if prodCount > 1 || sandCount > 1 {
570587
endpointsData = map[string]interface{}{
571588
"type": "endpoints",
572589
"version": "v4.5.0",
@@ -586,12 +603,42 @@ func createAPIYaml(apiCPEvent *APICPEvent) (string, string, string) {
586603
"production_endpoints": map[string]interface{}{
587604
"url": primaryProdcutionURL,
588605
},
606+
"endpoint_security": map[string]interface{}{
607+
"sandbox": map[string]interface{}{
608+
"apiKeyValue": apiCPEvent.API.SandEndpointSecurity.APIKeyValue,
609+
"apiKeyIdentifier": apiCPEvent.API.SandEndpointSecurity.APIKeyName,
610+
"apiKeyIdentifierType": "HEADER",
611+
"type": apiCPEvent.API.SandEndpointSecurity.SecurityType,
612+
"username": apiCPEvent.API.SandEndpointSecurity.BasicUsername,
613+
"password": apiCPEvent.API.SandEndpointSecurity.BasicPassword,
614+
"enabled": apiCPEvent.API.SandEndpointSecurity.Enabled,
615+
"additionalProperties": map[string]interface{}{},
616+
"customParameters": map[string]interface{}{},
617+
"connectionTimeoutDuration": -1.0,
618+
"socketTimeoutDuration": -1.0,
619+
"connectionRequestTimeoutDuration": -1.0,
620+
},
621+
"production": map[string]interface{}{
622+
"apiKeyValue": apiCPEvent.API.ProdEndpointSecurity.APIKeyValue,
623+
"apiKeyIdentifier": apiCPEvent.API.ProdEndpointSecurity.APIKeyName,
624+
"apiKeyIdentifierType": "HEADER",
625+
"type": apiCPEvent.API.ProdEndpointSecurity.SecurityType,
626+
"username": apiCPEvent.API.ProdEndpointSecurity.BasicUsername,
627+
"password": apiCPEvent.API.ProdEndpointSecurity.BasicPassword,
628+
"enabled": apiCPEvent.API.ProdEndpointSecurity.Enabled,
629+
"additionalProperties": map[string]interface{}{},
630+
"customParameters": map[string]interface{}{},
631+
"connectionTimeoutDuration": -1.0,
632+
"socketTimeoutDuration": -1.0,
633+
"connectionRequestTimeoutDuration": -1.0,
634+
},
635+
},
589636
}
590637
}
591638

592-
logger.LoggerMgtServer.Infof("API Yaml: %+v", data)
639+
logger.LoggerMgtServer.Debugf("API Yaml: %+v", data)
593640
yamlBytes, _ := yaml.Marshal(data)
594-
logger.LoggerMgtServer.Infof("Endpoint Yaml: %v", endpointsData)
641+
logger.LoggerMgtServer.Debugf("Endpoint Yaml: %v", endpointsData)
595642
endpointBytes, _ := yaml.Marshal(endpointsData)
596643
return string(yamlBytes), definition, string(endpointBytes)
597644
}

0 commit comments

Comments
 (0)