Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcast-db committed Jun 19, 2024
1 parent 5a4837b commit 3554e86
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ func (c *DatabricksClient) ConfiguredAccountID() string {
return c.Config.AccountID
}

// Returns the inner Api Client.
// ApiClient returns the inner Api Client.
func (c *DatabricksClient) ApiClient() *httpclient.ApiClient {
return c.client
}

// Returns a new OAuth token using the provided token. The token must be a JWT token.
// GetOAuthToken returns a new OAuth token using the provided token. The token must be a JWT token.
// The resulting token is scoped to the authorization details provided.
//
// **NOTE:** Experimental: This API may change or be removed in a future release
Expand Down
6 changes: 1 addition & 5 deletions httpclient/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,7 @@ func WithRequestHeaders(headers map[string]string) DoOption {

// WithToken uses the specified golang.org/x/oauth2 token on a request
func WithToken(token *oauth2.Token) DoOption {
visitor := WithRequestVisitor(func(r *http.Request) error {
auth := fmt.Sprintf("%s %s", token.TokenType, token.AccessToken)
r.Header.Set("Authorization", auth)
return nil
})
visitor := WithTokenSource(oauth2.StaticTokenSource(token))
visitor.isAuthOption = true
return visitor
}
Expand Down
2 changes: 1 addition & 1 deletion openapi/code/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Method struct {
shortcut bool
}

// Returns the fields which contains the DataPlane info. Each field is nested in the previous one.
// DataPlaneInfoFields returns the fields which contains the DataPlane info. Each field is nested in the previous one.
func (m *Method) DataPlaneInfoFields() []*Field {
if m.DataPlane == nil {
return nil
Expand Down
6 changes: 3 additions & 3 deletions openapi/code/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ type Service struct {
tag *openapi.Tag
}

// Returns whether this API has a DataPlane counterpart.
// HasDataPlaneAPI returns whether this API has a DataPlane counterpart.
func (svc *Service) HasDataPlaneAPI() bool {
return len(svc.DataPlaneServices) > 0
}

// Returns the method in the Control Plane which contains the DataInfo object
// DataPlaneInfoMethod returns the method in the Control Plane which contains the DataInfo object
func (svc *Service) DataPlaneInfoMethod() *Method {
methodName := ""
for _, m := range svc.methods {
Expand All @@ -61,7 +61,7 @@ func (svc *Service) HasParent() bool {
return svc.tag.ParentService != ""
}

// Returns whether the service is a DataPlane service
// IsDataPlane returns whether the service is a DataPlane service
// This is determined by the service having a matching control plane service
func (svc *Service) IsDataPlane() bool {
return svc.tag.ControlPlaneService != ""
Expand Down
8 changes: 4 additions & 4 deletions service/oauth2/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ import (
"golang.org/x/oauth2"
)

// DataPlaneHelper is a helper struct to fetch, refresh and manage DataPlane details and tokens.
type DataPlaneHelper struct {
infos map[string]*DataPlaneInfo
tokens map[string]*oauth2.Token
}

// GetDataPlaneDetails returns the endpoint URL and token. It returns a cached token if it is valid,
// otherwise it refreshes the token and returns the new token.
func (o *DataPlaneHelper) GetDataPlaneDetails(method string, params []string, refresh func(*DataPlaneInfo) (*oauth2.Token, error), infoGetter func() (*DataPlaneInfo, error)) (string, *oauth2.Token, error) {
if o.infos == nil {
o.infos = make(map[string]*DataPlaneInfo)
Expand All @@ -20,10 +23,6 @@ func (o *DataPlaneHelper) GetDataPlaneDetails(method string, params []string, re
}
key := o.generateKey(method, params)
info, infoOk := o.infos[key]
token, tokenOk := o.tokens[key]
if infoOk && tokenOk && token.Valid() {
return info.EndpointUrl, token, nil
}
if !infoOk {
newInfo, err := infoGetter()
if err != nil {
Expand All @@ -32,6 +31,7 @@ func (o *DataPlaneHelper) GetDataPlaneDetails(method string, params []string, re
o.infos[key] = newInfo
info = newInfo
}
token, tokenOk := o.tokens[key]
if !tokenOk || !token.Valid() {
newToken, err := refresh(info)
if err != nil {
Expand Down

0 comments on commit 3554e86

Please sign in to comment.