Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support CSE and filemap for cloud logs #5952

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ibm/conns/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/IBM/cloud-db2-go-sdk/db2saasv1"
"io"
"io/ioutil"
"log"
Expand All @@ -18,6 +17,8 @@ import (
"strings"
"time"

"github.com/IBM/cloud-db2-go-sdk/db2saasv1"

// Added code for the Power Colo Offering

"github.com/IBM-Cloud/container-services-go-sdk/kubernetesserviceapiv1"
Expand Down Expand Up @@ -1671,16 +1672,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
Loading