Skip to content

Commit

Permalink
Move
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcast-db committed May 29, 2024
1 parent 6eb4951 commit 2a4517d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
4 changes: 2 additions & 2 deletions .codegen/impl.go.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (
"context"
"errors"
"fmt"
goauth "golang.org/x/oauth2"
"time"
"io"
"net/http"
"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/httpclient"
{{range .ImportedPackages}}
"github.com/databricks/databricks-sdk-go/service/{{.}}"{{end}}
goauth "golang.org/x/oauth2"
)
{{range .Services}}
// unexported type that holds implementations of just {{.Name}} API methods
type {{.CamelName}}Impl struct {
{{- if .IsDataPlane}}
dataplane.DataPlaneHelper
oauth2.DataPlaneHelper
controlPlane *{{.ControlPlaneService.PascalName}}API
{{end -}}
client *client.DatabricksClient
Expand Down
4 changes: 2 additions & 2 deletions service/iam/model.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions dataplane/data_plane.go → service/oauth2/data_plane.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package dataplane
package oauth2

import (
"strings"

dp "github.com/databricks/databricks-sdk-go/service/oauth2"
"golang.org/x/oauth2"
)

type DataPlaneHelper struct {
infos map[string]*dp.DataPlaneInfo
infos map[string]*DataPlaneInfo
tokens map[string]*oauth2.Token
}

func (o *DataPlaneHelper) GetDataPlaneDetails(method string, params []string, refresh func(*dp.DataPlaneInfo) (*oauth2.Token, error), infoGetter func() (*dp.DataPlaneInfo, error)) (string, *oauth2.Token, error) {
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]*dp.DataPlaneInfo)
o.infos = make(map[string]*DataPlaneInfo)
}
if o.tokens == nil {
o.tokens = make(map[string]*oauth2.Token)
Expand Down
23 changes: 11 additions & 12 deletions dataplane/data_plane_test.go → service/oauth2/data_plane_test.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
package dataplane
package oauth2

import (
"testing"
"time"

dp "github.com/databricks/databricks-sdk-go/service/oauth2"
"github.com/stretchr/testify/assert"
"golang.org/x/oauth2"
)

type infoMock struct {
called bool
info *dp.DataPlaneInfo
info *DataPlaneInfo
err error
}

func (i *infoMock) DataPlaneInfoGetter() (*dp.DataPlaneInfo, error) {
func (i *infoMock) DataPlaneInfoGetter() (*DataPlaneInfo, error) {
i.called = true
return i.info, i.err
}

type tokenRefreshSpy struct {
called bool
expectedInfo *dp.DataPlaneInfo
expectedInfo *DataPlaneInfo
token *oauth2.Token
err error
}

func (t *tokenRefreshSpy) TokenRefresh(info *dp.DataPlaneInfo) (*oauth2.Token, error) {
func (t *tokenRefreshSpy) TokenRefresh(info *DataPlaneInfo) (*oauth2.Token, error) {
t.expectedInfo = info
t.called = true
return t.token, t.err
}

func TestTokenNotCached(t *testing.T) {
info := infoMock{
info: &dp.DataPlaneInfo{
info: &DataPlaneInfo{
EndpointUrl: "url",
AuthorizationDetails: "authDetails",
},
Expand All @@ -62,7 +61,7 @@ func TestTokenNotCached(t *testing.T) {

func TestTokenCached(t *testing.T) {
info := infoMock{
info: &dp.DataPlaneInfo{
info: &DataPlaneInfo{
EndpointUrl: "url",
AuthorizationDetails: "authDetails",
},
Expand All @@ -77,7 +76,7 @@ func TestTokenCached(t *testing.T) {
err: nil,
}
c := DataPlaneHelper{}
c.infos = make(map[string]*dp.DataPlaneInfo)
c.infos = make(map[string]*DataPlaneInfo)
c.tokens = make(map[string]*oauth2.Token)
c.infos["method/params"] = info.info
c.tokens["method/params"] = s.token
Expand All @@ -93,7 +92,7 @@ func TestTokenCached(t *testing.T) {

func TestTokenExpired(t *testing.T) {
info := infoMock{
info: &dp.DataPlaneInfo{
info: &DataPlaneInfo{
EndpointUrl: "url",
AuthorizationDetails: "authDetails",
},
Expand All @@ -114,7 +113,7 @@ func TestTokenExpired(t *testing.T) {
err: nil,
}
c := DataPlaneHelper{}
c.infos = make(map[string]*dp.DataPlaneInfo)
c.infos = make(map[string]*DataPlaneInfo)
c.tokens = make(map[string]*oauth2.Token)
c.infos["method/params"] = info.info
c.tokens["method/params"] = expired
Expand Down Expand Up @@ -145,7 +144,7 @@ func TestTokenInfoError(t *testing.T) {

func TestTokenRefreshError(t *testing.T) {
info := infoMock{
info: &dp.DataPlaneInfo{
info: &DataPlaneInfo{
EndpointUrl: "url",
AuthorizationDetails: "authDetails",
},
Expand Down
5 changes: 2 additions & 3 deletions service/serving/impl.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2a4517d

Please sign in to comment.