From 5131c8e98114157dcdda44f9459003af990eb9b2 Mon Sep 17 00:00:00 2001 From: Simon Johansson Date: Tue, 29 Oct 2024 12:00:23 +0100 Subject: [PATCH] Parse the platform API to determine scheme and host --- internal/provider/provider.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/provider/provider.go b/internal/provider/provider.go index c1ac1ae..c24fac1 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -11,8 +11,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/springernature/ee-platform/pkg/api_client" + "net/url" "os" - "strings" ) // Ensure the implementation satisfies the expected interfaces. @@ -77,8 +77,19 @@ func (p *eePlatformProvider) Configure(ctx context.Context, req provider.Configu } } + pAURL, err := url.Parse(platformAPI) + if err != nil { + resp.Diagnostics.AddError( + "Unable to parse API endpoint", + "", + ) + return + } + clientConfig := api_client.NewConfiguration() - clientConfig.Host = strings.TrimPrefix(platformAPI, "https://") + + clientConfig.Host = pAURL.Host + clientConfig.Scheme = pAURL.Scheme apiClient := api_client.NewAPIClient(clientConfig) resp.DataSourceData = apiClient }