Skip to content

Commit

Permalink
feat: migrate to new auth provider (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
nrwiersma authored Mar 27, 2024
1 parent e2003bd commit f3e444e
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ec/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"net/url"
"sync"

"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
Expand Down Expand Up @@ -268,12 +269,12 @@ func resolveTokenURL(m map[string]any) (string, error) {
if err != nil {
return "", fmt.Errorf("invalid host: %w", err)
}
u.Host = "auth-" + u.Host
u.Path = "/auth/realms/enterprise-console/protocol/openid-connect/token"
u.Path = "/auth/token"
return u.String(), nil
}

type lazyTokenSource struct {
mu sync.Mutex
ts oauth2.TokenSource
newFn func() (oauth2.TokenSource, error)
}
Expand All @@ -283,6 +284,9 @@ func newLazyTokenSource(newFn func() (oauth2.TokenSource, error)) *lazyTokenSour
}

func (s *lazyTokenSource) Token() (*oauth2.Token, error) {
s.mu.Lock()
defer s.mu.Unlock()

if s.ts == nil {
var err error
s.ts, err = s.newFn()
Expand Down

0 comments on commit f3e444e

Please sign in to comment.