Skip to content

Commit

Permalink
support CSE and filemap for cloud logs
Browse files Browse the repository at this point in the history
  • Loading branch information
kavya498 authored and hkantare committed Jan 30, 2025
1 parent d6375c4 commit aa987bd
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
9 changes: 4 additions & 5 deletions ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 18 additions & 3 deletions ibm/service/logs/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logs

import (
"fmt"
"log"
"os"
"strings"

Expand Down Expand Up @@ -51,20 +52,34 @@ 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(),
}

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
Expand Down
1 change: 1 addition & 0 deletions website/docs/guides/custom-service-endpoints.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit aa987bd

Please sign in to comment.