diff --git a/apim-apk-agent/internal/utils/apis_fetcher.go b/apim-apk-agent/internal/utils/apis_fetcher.go index ec1e4a3e..7ac1bd8c 100644 --- a/apim-apk-agent/internal/utils/apis_fetcher.go +++ b/apim-apk-agent/internal/utils/apis_fetcher.go @@ -109,12 +109,13 @@ func FetchAPIsOnEvent(conf *config.Config, apiUUID *string, k8sClient client.Cli return nil, err } apkConf, apiUUID, revisionID, apkErr := transformer.GenerateAPKConf(artifact.APIJson, artifact.ClientCerts) + logger.LoggerSync.Infof("APK COnf: %s", apkConf) if apkErr != nil { logger.LoggerSync.Errorf("Error while generating APK-Conf: %v", apkErr) return nil, err } k8ResourceEndpoint := conf.DataPlane.K8ResourceEndpoint - crResponse, err := transformer.GenerateCRs(apkConf, artifact.Swagger, k8ResourceEndpoint) + crResponse, err := transformer.GenerateCRs(apkConf, artifact.Schema, k8ResourceEndpoint) if err != nil { logger.LoggerSync.Errorf("Error occured in receiving the updated CRDs: %v", err) return nil, err diff --git a/apim-apk-agent/pkg/transformer/api_model.go b/apim-apk-agent/pkg/transformer/api_model.go index 9a0235d2..a6d2a3ef 100644 --- a/apim-apk-agent/pkg/transformer/api_model.go +++ b/apim-apk-agent/pkg/transformer/api_model.go @@ -111,7 +111,7 @@ type APIArtifact struct { APIJson string `json:"apiJson"` APIFileName string `json:"apiFileName"` EnvConfig string `json:"envConfig"` - Swagger string `json:"swagger"` + Schema string `json:"schema"` DeploymentDescriptor string `json:"deploymentDescriptor"` ClientCerts string `json:"clientCert"` RevisionID uint32 `json:"revisionId"` diff --git a/apim-apk-agent/pkg/transformer/transformer.go b/apim-apk-agent/pkg/transformer/transformer.go index 98a0f0d5..8b1d8d97 100644 --- a/apim-apk-agent/pkg/transformer/transformer.go +++ b/apim-apk-agent/pkg/transformer/transformer.go @@ -67,29 +67,36 @@ func GenerateAPKConf(APIJson string, clientCerts string) (string, string, uint32 apk.Name = apiYamlData.Name apk.Context = apiYamlData.Context apk.Version = apiYamlData.Version + logger.LoggerTransformer.Infof("Type: %s", apiYamlData.Type) apk.Type = getAPIType(apiYamlData.Type) + logger.LoggerTransformer.Infof("API Type: %s", apk.Type) apk.DefaultVersion = apiYamlData.DefaultVersion apk.DefinitionPath = "/definition" apk.SubscriptionValidation = true apkOperations := make([]Operation, len(apiYamlData.Operations)) + logger.LoggerTransformer.Infof("apiYamlData.Operations: %v", apiYamlData.Operations) for i, operation := range apiYamlData.Operations { - - reqPolicyCount := len(operation.OperationPolicies.Request) - resPolicyCount := len(operation.OperationPolicies.Response) - reqInterceptor, resInterceptor := getReqAndResInterceptors(reqPolicyCount, resPolicyCount) - - op := &Operation{ - Target: operation.Target, - Verb: operation.Verb, - Scopes: operation.Scopes, - Secured: true, - OperationPolicies: &OperationPolicies{ - Request: *reqInterceptor, - Response: *resInterceptor, - }, + logger.LoggerTransformer.Infof("Operation: %v", operation) + + if operation.Verb != "SUBSCRIPTION" { + + reqPolicyCount := len(operation.OperationPolicies.Request) + resPolicyCount := len(operation.OperationPolicies.Response) + reqInterceptor, resInterceptor := getReqAndResInterceptors(reqPolicyCount, resPolicyCount) + + op := &Operation{ + Target: operation.Target, + Verb: operation.Verb, + Scopes: operation.Scopes, + Secured: true, + OperationPolicies: &OperationPolicies{ + Request: *reqInterceptor, + Response: *resInterceptor, + }, + } + apkOperations[i] = *op } - apkOperations[i] = *op } apk.Operations = &apkOperations @@ -150,8 +157,8 @@ func getAPIType(protocolType string) string { switch protocolType { case "HTTP", "HTTPS": apiType = "REST" - case "GraphQL": - apiType = "GraphQL" + case "GRAPHQL": + apiType = "GRAPHQL" } return apiType } diff --git a/apim-apk-agent/pkg/transformer/utils.go b/apim-apk-agent/pkg/transformer/utils.go index fb8d5a34..fff4dff0 100644 --- a/apim-apk-agent/pkg/transformer/utils.go +++ b/apim-apk-agent/pkg/transformer/utils.go @@ -73,12 +73,21 @@ func readZipFile(file *zip.File) (*APIArtifact, error) { return nil, err } for _, file := range zipReader.File { + logger.LoggerTransformer.Info("Reading " + file.Name) if strings.Contains(file.Name, "swagger.json") { openAPIContent, err := ReadContent(file) if err != nil { return nil, err } - apiArtifact.Swagger = string(openAPIContent) + apiArtifact.Schema = string(openAPIContent) + } + + if strings.Contains(file.Name, "schema.graphql") { + graphqlContent, err := ReadContent(file) + if err != nil { + return nil, err + } + apiArtifact.Schema = string(graphqlContent) } if strings.Contains(file.Name, "api.json") { @@ -118,8 +127,11 @@ func readAPIZipFile(file *zip.File, apiArtifact *APIArtifact) error { } if strings.Contains(file.Name, "swagger.json") { - apiArtifact.Swagger = string(content) + apiArtifact.Schema = string(content) + } + if strings.Contains(file.Name, "schema.graphql") { + apiArtifact.Schema = string(content) } if strings.Contains(file.Name, "api.json") { @@ -215,7 +227,7 @@ func DecodeAPIArtifacts(payload []byte) ([]APIArtifact, error) { apiArtifacts = append(apiArtifacts, apiArtifact) } apiArtifact.APIJson = "" - apiArtifact.Swagger = "" + apiArtifact.Schema = "" apiArtifact.RevisionID = 0 apiArtifact.APIFileName = "" }