From aa987bd050e6ddd03a6bfe4ddbe5a6fe5a5c035d Mon Sep 17 00:00:00 2001 From: hkavya26 Date: Wed, 29 Jan 2025 18:50:06 +0530 Subject: [PATCH] support CSE and filemap for cloud logs --- ibm/conns/config.go | 9 ++++---- ibm/service/logs/utils.go | 21 ++++++++++++++++--- .../guides/custom-service-endpoints.html.md | 1 + 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ibm/conns/config.go b/ibm/conns/config.go index 7bd053fd7e..7785d6c549 100644 --- a/ibm/conns/config.go +++ b/ibm/conns/config.go @@ -1683,16 +1683,15 @@ func (c *Config) ClientSession() (interface{}, error) { // Construct an "options" struct for creating the service client. logsEndpoint := ContructEndpoint(fmt.Sprintf("api.%s.logs", c.Region), cloudEndpoint) - if fileMap != nil && c.Visibility != "public-and-private" { - logsEndpoint = fileFallBack(fileMap, c.Visibility, "IBMCLOUD_LOGS_API_ENDPOINT", c.Region, logsEndpoint) - } if c.Visibility == "private" || c.Visibility == "public-and-private" { logsEndpoint = ContructEndpoint(fmt.Sprintf("api.private.%s.logs", c.Region), cloudEndpoint) } - + if fileMap != nil && c.Visibility != "public-and-private" { + logsEndpoint = fileFallBack(fileMap, c.Visibility, "IBMCLOUD_LOGS_API_ENDPOINT", c.Region, logsEndpoint) + } logsClientOptions := &logsv0.LogsV0Options{ Authenticator: authenticator, - URL: logsEndpoint, + URL: EnvFallBack([]string{"IBMCLOUD_LOGS_API_ENDPOINT"}, logsEndpoint), } // Construct the service client. diff --git a/ibm/service/logs/utils.go b/ibm/service/logs/utils.go index fc4c2876e0..4bb9b9077b 100644 --- a/ibm/service/logs/utils.go +++ b/ibm/service/logs/utils.go @@ -2,6 +2,7 @@ package logs import ( "fmt" + "log" "os" "strings" @@ -51,13 +52,25 @@ func getClientWithLogsInstanceEndpoint(originalClient *logsv0.LogsV0, instanceId if strings.Contains(os.Getenv("IBMCLOUD_IAM_API_ENDPOINT"), "test") { domain = testCloudEndpoint } + // getting originalConfigServiceURL to not miss filemap precedence from the url constructed in config.go file + originalConfigServiceURL := originalClient.GetServiceURL() + + log.Printf("Service URL from the config.go file %s", originalConfigServiceURL) + var endpoint string if endpointType == "private" { - endpoint = fmt.Sprintf("https://%s.api.private.%s.logs.%s", instanceId, region, domain) + if strings.Contains(originalConfigServiceURL, fmt.Sprintf("https://%s.api.private.%s.logs.%s", instanceId, region, domain)) { + endpoint = originalConfigServiceURL + } else { + endpoint = fmt.Sprintf("https://%s.api.private.%s.logs.%s:3443", instanceId, region, domain) + } } else { - endpoint = fmt.Sprintf("https://%s.api.%s.logs.%s", instanceId, region, domain) + if strings.Contains(originalConfigServiceURL, fmt.Sprintf("https://%s.api.%s.logs.%s", instanceId, region, domain)) { + endpoint = originalConfigServiceURL + } else { + endpoint = fmt.Sprintf("https://%s.api.%s.logs.%s", instanceId, region, domain) + } } - // clone the client and set endpoint newClient := &logsv0.LogsV0{ Service: originalClient.Service.Clone(), @@ -65,6 +78,8 @@ func getClientWithLogsInstanceEndpoint(originalClient *logsv0.LogsV0, instanceId endpoint = conns.EnvFallBack([]string{"IBMCLOUD_LOGS_API_ENDPOINT"}, endpoint) + log.Printf("Constructing client with new service URL %s", endpoint) + newClient.Service.SetServiceURL(endpoint) return newClient diff --git a/website/docs/guides/custom-service-endpoints.html.md b/website/docs/guides/custom-service-endpoints.html.md index e582ae430b..ff57658718 100644 --- a/website/docs/guides/custom-service-endpoints.html.md +++ b/website/docs/guides/custom-service-endpoints.html.md @@ -55,6 +55,7 @@ provider "ibm" { |Cloud Shell|IBMCLOUD_CLOUD_SHELL_API_ENDPOINT| |Compilance (Posture Management)|IBMCLOUD_COMPLIANCE_API_ENDPOINT| |Container Registry|IBMCLOUD_CR_API_ENDPOINT| +|Cloud Logs | IBMCLOUD_LOGS_API_ENDPOINT | |Kubernetes Service|IBMCLOUD_CS_API_ENDPOINT| |Metrics Router| IBMCLOUD_METRICS_ROUTING_API_ENDPOINT| |MQ on Cloud| IBMCLOUD_MQCLOUD_CONFIG_ENDPOINT|