Skip to content

Commit

Permalink
Add dataservices sub-client
Browse files Browse the repository at this point in the history
This client will be used by terraform providers or data sources
to access the dataservices API, eg to read the `/secrets` endpoint.
  • Loading branch information
stuart-mclaren-hpe committed Dec 13, 2024
1 parent 8d78a96 commit c80d3ed
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/debug"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/defaults"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/async"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/dataservices"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/systems"
"github.com/HewlettPackard/hpegl-pcbe-terraform-resources/internal/sdk/virt"
"github.com/microsoft/kiota-abstractions-go/authentication"
Expand Down Expand Up @@ -121,6 +122,38 @@ func (c *PCBeClient) NewSysClient(
return sysClient, headerOpts, nil
}

func (c *PCBeClient) NewDataServicesClient(
ctx context.Context,
) (*dataservices.ApiClient, *nethttplibrary.HeadersInspectionOptions, error) {
var middlewares []nethttplibrary.Middleware

tp := auth.NewPcbeAccessTokenProvider(c.Config.Token)
authProvider := authentication.NewBaseBearerTokenAuthenticationProvider(tp)
observeOpts := nethttplibrary.ObservabilityOptions{}
if c.Config.HTTPDump {
debugOpts := debug.NewInspectionOptions()
debugOpts.Enabled = true
debugOptsHandler := debug.NewInspectionHandlerWithOptions(*debugOpts)
middlewares = append(middlewares, debugOptsHandler)
}
headerOpts := nethttplibrary.NewHeadersInspectionOptions()
headerOpts.InspectResponseHeaders = true
headerOptsHandler := nethttplibrary.NewHeadersInspectionHandlerWithOptions(*headerOpts)
middlewares = append(middlewares, headerOptsHandler)
httpclient := nethttplibrary.GetDefaultClient(middlewares...)
httpclient.Timeout = c.Config.HTTPTimeout

adapter, err := nethttplibrary.NewNetHttpRequestAdapterWithParseNodeFactoryAndSerializationWriterFactoryAndHttpClientAndObservabilityOptions(authProvider, nil, nil, httpclient, observeOpts) // nolint: lll
if err != nil {
return nil, nil, err
}

adapter.SetBaseUrl(c.Config.Host)
sysClient := dataservices.NewApiClient(adapter)

return sysClient, headerOpts, nil
}

func NewPCBeClient(ctx context.Context, cfg Config) (*PCBeClient, error) {
if cfg.MaxPolls == 0 {
cfg.MaxPolls = defaults.MaxPolls
Expand Down

0 comments on commit c80d3ed

Please sign in to comment.