Skip to content

Commit

Permalink
Parse the platform API to determine scheme and host
Browse files Browse the repository at this point in the history
  • Loading branch information
simonjohansson committed Oct 29, 2024
1 parent ad3763d commit 5131c8e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 5131c8e

Please sign in to comment.