Skip to content

Commit

Permalink
Fixed #527
Browse files Browse the repository at this point in the history
  • Loading branch information
Reinhard-Pilz-Dynatrace committed Sep 11, 2024
1 parent 1a21e9b commit 57ad2ba
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dynatrace/api/cluster/v1/bindings/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SchemaID = "accounts:policy-bindings"

func Service(credentials *settings.Credentials) settings.CRUDService[*bindings.PolicyBinding] {
return &service{
serviceClient: NewPolicyService(fmt.Sprintf("%s%s", credentials.Cluster.URL, "/api/cluster/v2"), credentials.Cluster.Token),
serviceClient: NewPolicyService(fmt.Sprintf("%s%s", strings.TrimSuffix(credentials.Cluster.URL, "/"), "/api/cluster/v2"), credentials.Cluster.Token),
}
}

Expand Down
3 changes: 2 additions & 1 deletion dynatrace/api/cluster/v1/groups/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package groups
import (
"context"
"fmt"
"strings"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
groups "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/cluster/v1/groups/settings"
Expand All @@ -14,7 +15,7 @@ const SchemaID = "accounts:groups"

func Service(credentials *settings.Credentials) settings.CRUDService[*groups.GroupConfig] {
return &service{
serviceClient: NewService(fmt.Sprintf("%s%s", credentials.Cluster.URL, "/api/v1.0/onpremise"), credentials.Cluster.Token),
serviceClient: NewService(fmt.Sprintf("%s%s", strings.TrimSuffix(credentials.Cluster.URL, "/"), "/api/v1.0/onpremise"), credentials.Cluster.Token),
}
}

Expand Down
2 changes: 1 addition & 1 deletion dynatrace/api/cluster/v1/permissions/mgmz/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const SchemaID = "accounts:groups-mgmz"

func Service(credentials *settings.Credentials) settings.CRUDService[*mgmz.Permission] {
return &service{
serviceClient: NewService(fmt.Sprintf("%s%s", credentials.Cluster.URL, "/api/v1.0/onpremise"), credentials.Cluster.Token),
serviceClient: NewService(fmt.Sprintf("%s%s", strings.TrimSuffix(credentials.Cluster.URL, "/"), "/api/v1.0/onpremise"), credentials.Cluster.Token),
}
}

Expand Down
2 changes: 1 addition & 1 deletion dynatrace/api/cluster/v1/policies/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func NewPolicyService(baseURL string, apiToken string) *PolicyServiceClient {

func Service(credentials *settings.Credentials) settings.CRUDService[*policies.Policy] {
return &service{
serviceClient: NewPolicyService(fmt.Sprintf("%s%s", credentials.Cluster.URL, "/api/cluster/v2"), credentials.Cluster.Token),
serviceClient: NewPolicyService(fmt.Sprintf("%s%s", strings.TrimSuffix(credentials.Cluster.URL, "/"), "/api/cluster/v2"), credentials.Cluster.Token),
}
}

Expand Down
2 changes: 1 addition & 1 deletion dynatrace/api/cluster/v1/users/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const SchemaID = "accounts:users"

func Service(credentials *settings.Credentials) settings.CRUDService[*users.UserConfig] {
return &service{
serviceClient: NewService(fmt.Sprintf("%s%s", credentials.Cluster.URL, "/api/v1.0/onpremise"), credentials.Cluster.Token),
serviceClient: NewService(fmt.Sprintf("%s%s", strings.TrimSuffix(credentials.Cluster.URL, "/"), "/api/v1.0/onpremise"), credentials.Cluster.Token),
}
}

Expand Down
3 changes: 2 additions & 1 deletion dynatrace/api/cluster/v2/networkzones/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"fmt"
"net/url"
"strings"

"github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api"
networkzones "github.com/dynatrace-oss/terraform-provider-dynatrace/dynatrace/api/cluster/v2/networkzones/settings"
Expand All @@ -33,7 +34,7 @@ const SchemaID = "cluster:networkzones"

func Service(credentials *settings.Credentials) settings.CRUDService[*networkzones.NetworkZone] {
return &service{
serviceClient: NewService(fmt.Sprintf("%s%s", credentials.Cluster.URL, "/api/cluster/v2"), credentials.Cluster.Token),
serviceClient: NewService(fmt.Sprintf("%s%s", strings.TrimSuffix(credentials.Cluster.URL, "/"), "/api/cluster/v2"), credentials.Cluster.Token),
}
}

Expand Down
5 changes: 5 additions & 0 deletions dynatrace/settings/credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ func getEnv(names ...string) string {
return ""
}
for _, name := range names {
fmt.Println("-GETENV-", name)
if value := os.Getenv(name); len(value) > 0 {
fmt.Println(" ", value)
return value
}
}
Expand Down Expand Up @@ -150,6 +152,9 @@ func CreateExportCredentials() (*Credentials, error) {
}

clusterURL := getEnv("DYNATRACE_CLUSTER_URL", "DT_CLUSTER_URL")
for strings.HasSuffix(clusterURL, "/") {
clusterURL = strings.TrimSuffix(clusterURL, "/")
}
clusterAPIToken := getEnv("DYNATRACE_CLUSTER_API_TOKEN", "DT_CLUSTER_API_TOKEN")

if environmentURL == "" && clusterURL == "" && iam_account_id == "" {
Expand Down

0 comments on commit 57ad2ba

Please sign in to comment.