diff --git a/.codegen/_openapi_sha b/.codegen/_openapi_sha index 784f606d..3cf20d57 100644 --- a/.codegen/_openapi_sha +++ b/.codegen/_openapi_sha @@ -1 +1 @@ -821ab6511c9a977bae10cdcd2cf5aa0ad6ab8f8f \ No newline at end of file +- \ No newline at end of file diff --git a/service/oauth2/model.go b/service/oauth2/model.go index 8c4bc6c6..08de08f9 100755 --- a/service/oauth2/model.go +++ b/service/oauth2/model.go @@ -155,23 +155,6 @@ func (s CreateServicePrincipalSecretResponse) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } -type DataPlaneInfo struct { - // Authorization details as a string. - AuthorizationDetails string `json:"authorization_details,omitempty"` - // The URL of the endpoint for this operation in the dataplane. - EndpointUrl string `json:"endpoint_url,omitempty"` - - ForceSendFields []string `json:"-"` -} - -func (s *DataPlaneInfo) UnmarshalJSON(b []byte) error { - return marshal.Unmarshal(b, s) -} - -func (s DataPlaneInfo) MarshalJSON() ([]byte, error) { - return marshal.Marshal(s) -} - // Delete account federation policy type DeleteAccountFederationPolicyRequest struct { // The identifier for the federation policy. diff --git a/service/serving/ext_data_plane.go b/service/serving/ext_data_plane.go index c4ec977b..37c80aed 100644 --- a/service/serving/ext_data_plane.go +++ b/service/serving/ext_data_plane.go @@ -4,24 +4,23 @@ import ( "strings" "sync" - "github.com/databricks/databricks-sdk-go/service/oauth2" goauth "golang.org/x/oauth2" ) // DataPlaneService is an interface for services that access DataPlane. type DataPlaneService interface { - GetDataPlaneDetails(method string, params []string, refresh func(*oauth2.DataPlaneInfo) (*goauth.Token, error), infoGetter func() (*oauth2.DataPlaneInfo, error)) (string, *goauth.Token, error) + GetDataPlaneDetails(method string, params []string, refresh func(*DataPlaneInfo) (*goauth.Token, error), infoGetter func() (*DataPlaneInfo, error)) (string, *goauth.Token, error) } func NewDataPlaneService() DataPlaneService { return &dataPlaneServiceImpl{ - infos: make(map[string]*oauth2.DataPlaneInfo), + infos: make(map[string]*DataPlaneInfo), tokens: make(map[string]*goauth.Token), } } type dataPlaneServiceImpl struct { - infos map[string]*oauth2.DataPlaneInfo + infos map[string]*DataPlaneInfo tokens map[string]*goauth.Token // This class can be shared across multiple threads. // This mutex is used to synchronize access to the infos and tokens maps. @@ -30,7 +29,7 @@ type dataPlaneServiceImpl struct { // 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 *dataPlaneServiceImpl) GetDataPlaneDetails(method string, params []string, refresh func(*oauth2.DataPlaneInfo) (*goauth.Token, error), infoGetter func() (*oauth2.DataPlaneInfo, error)) (string, *goauth.Token, error) { +func (o *dataPlaneServiceImpl) GetDataPlaneDetails(method string, params []string, refresh func(*DataPlaneInfo) (*goauth.Token, error), infoGetter func() (*DataPlaneInfo, error)) (string, *goauth.Token, error) { key := o.generateKey(method, params) info, err := o.getInfo(key, infoGetter) if err != nil { @@ -43,7 +42,7 @@ func (o *dataPlaneServiceImpl) GetDataPlaneDetails(method string, params []strin return info.EndpointUrl, token, nil } -func (o *dataPlaneServiceImpl) getInfo(key string, infoGetter func() (*oauth2.DataPlaneInfo, error)) (*oauth2.DataPlaneInfo, error) { +func (o *dataPlaneServiceImpl) getInfo(key string, infoGetter func() (*DataPlaneInfo, error)) (*DataPlaneInfo, error) { info, infoOk := o.infos[key] if !infoOk { o.mu.Lock() @@ -61,7 +60,7 @@ func (o *dataPlaneServiceImpl) getInfo(key string, infoGetter func() (*oauth2.Da return info, nil } -func (o *dataPlaneServiceImpl) refreshToken(key string, info *oauth2.DataPlaneInfo, refresh func(*oauth2.DataPlaneInfo) (*goauth.Token, error)) (*goauth.Token, error) { +func (o *dataPlaneServiceImpl) refreshToken(key string, info *DataPlaneInfo, refresh func(*DataPlaneInfo) (*goauth.Token, error)) (*goauth.Token, error) { token, tokenOk := o.tokens[key] if !tokenOk || !token.Valid() { o.mu.Lock() diff --git a/service/serving/ext_data_plane_test.go b/service/serving/ext_data_plane_test.go index 4fa3ca3d..27a0972a 100644 --- a/service/serving/ext_data_plane_test.go +++ b/service/serving/ext_data_plane_test.go @@ -4,30 +4,29 @@ import ( "testing" "time" - "github.com/databricks/databricks-sdk-go/service/oauth2" "github.com/stretchr/testify/assert" goauth "golang.org/x/oauth2" ) type infoMock struct { called bool - info *oauth2.DataPlaneInfo + info *DataPlaneInfo err error } -func (i *infoMock) DataPlaneInfoGetter() (*oauth2.DataPlaneInfo, error) { +func (i *infoMock) DataPlaneInfoGetter() (*DataPlaneInfo, error) { i.called = true return i.info, i.err } type tokenRefreshSpy struct { called bool - expectedInfo *oauth2.DataPlaneInfo + expectedInfo *DataPlaneInfo token *goauth.Token err error } -func (t *tokenRefreshSpy) TokenRefresh(info *oauth2.DataPlaneInfo) (*goauth.Token, error) { +func (t *tokenRefreshSpy) TokenRefresh(info *DataPlaneInfo) (*goauth.Token, error) { t.expectedInfo = info t.called = true return t.token, t.err @@ -35,7 +34,7 @@ func (t *tokenRefreshSpy) TokenRefresh(info *oauth2.DataPlaneInfo) (*goauth.Toke func TestTokenNotCached(t *testing.T) { info := infoMock{ - info: &oauth2.DataPlaneInfo{ + info: &DataPlaneInfo{ EndpointUrl: "url", AuthorizationDetails: "authDetails", }, @@ -50,7 +49,7 @@ func TestTokenNotCached(t *testing.T) { err: nil, } c := dataPlaneServiceImpl{ - infos: make(map[string]*oauth2.DataPlaneInfo), + infos: make(map[string]*DataPlaneInfo), tokens: make(map[string]*goauth.Token), } url, token, err := c.GetDataPlaneDetails("method", []string{"params"}, s.TokenRefresh, info.DataPlaneInfoGetter) @@ -65,7 +64,7 @@ func TestTokenNotCached(t *testing.T) { func TestTokenCached(t *testing.T) { info := infoMock{ - info: &oauth2.DataPlaneInfo{ + info: &DataPlaneInfo{ EndpointUrl: "url", AuthorizationDetails: "authDetails", }, @@ -80,7 +79,7 @@ func TestTokenCached(t *testing.T) { err: nil, } c := dataPlaneServiceImpl{} - c.infos = make(map[string]*oauth2.DataPlaneInfo) + c.infos = make(map[string]*DataPlaneInfo) c.tokens = make(map[string]*goauth.Token) c.infos["method/params"] = info.info c.tokens["method/params"] = s.token @@ -96,7 +95,7 @@ func TestTokenCached(t *testing.T) { func TestTokenExpired(t *testing.T) { info := infoMock{ - info: &oauth2.DataPlaneInfo{ + info: &DataPlaneInfo{ EndpointUrl: "url", AuthorizationDetails: "authDetails", }, @@ -117,7 +116,7 @@ func TestTokenExpired(t *testing.T) { err: nil, } c := dataPlaneServiceImpl{} - c.infos = make(map[string]*oauth2.DataPlaneInfo) + c.infos = make(map[string]*DataPlaneInfo) c.tokens = make(map[string]*goauth.Token) c.infos["method/params"] = info.info c.tokens["method/params"] = expired @@ -138,7 +137,7 @@ func TestTokenInfoError(t *testing.T) { } s := tokenRefreshSpy{} c := dataPlaneServiceImpl{ - infos: make(map[string]*oauth2.DataPlaneInfo), + infos: make(map[string]*DataPlaneInfo), tokens: make(map[string]*goauth.Token), } url, token, err := c.GetDataPlaneDetails("method", []string{"params"}, s.TokenRefresh, info.DataPlaneInfoGetter) @@ -151,7 +150,7 @@ func TestTokenInfoError(t *testing.T) { func TestTokenRefreshError(t *testing.T) { info := infoMock{ - info: &oauth2.DataPlaneInfo{ + info: &DataPlaneInfo{ EndpointUrl: "url", AuthorizationDetails: "authDetails", }, @@ -162,7 +161,7 @@ func TestTokenRefreshError(t *testing.T) { err: assert.AnError, } c := dataPlaneServiceImpl{ - infos: make(map[string]*oauth2.DataPlaneInfo), + infos: make(map[string]*DataPlaneInfo), tokens: make(map[string]*goauth.Token), } url, token, err := c.GetDataPlaneDetails("method", []string{"params"}, s.TokenRefresh, info.DataPlaneInfoGetter) diff --git a/service/serving/impl.go b/service/serving/impl.go index 1261c1b7..77476ef7 100755 --- a/service/serving/impl.go +++ b/service/serving/impl.go @@ -11,8 +11,6 @@ import ( "github.com/databricks/databricks-sdk-go/client" "github.com/databricks/databricks-sdk-go/httpclient" goauth "golang.org/x/oauth2" - - "github.com/databricks/databricks-sdk-go/service/oauth2" ) // unexported type that holds implementations of just ServingEndpoints API methods @@ -196,7 +194,7 @@ func (a *servingEndpointsDataPlaneImpl) Query(ctx context.Context, request Query if err != nil { return nil, err } - infoGetter := func() (*oauth2.DataPlaneInfo, error) { + infoGetter := func() (*DataPlaneInfo, error) { response, err := a.controlPlane.Get(ctx, getRequest) if err != nil { return nil, err @@ -206,7 +204,7 @@ func (a *servingEndpointsDataPlaneImpl) Query(ctx context.Context, request Query } return response.DataPlaneInfo.QueryInfo, nil } - refresh := func(info *oauth2.DataPlaneInfo) (*goauth.Token, error) { + refresh := func(info *DataPlaneInfo) (*goauth.Token, error) { return a.client.GetOAuthToken(ctx, info.AuthorizationDetails, token) } getParams := []string{ diff --git a/service/serving/model.go b/service/serving/model.go index 6ac7eb49..ade65278 100755 --- a/service/serving/model.go +++ b/service/serving/model.go @@ -7,7 +7,6 @@ import ( "io" "github.com/databricks/databricks-sdk-go/marshal" - "github.com/databricks/databricks-sdk-go/service/oauth2" ) type Ai21LabsConfig struct { @@ -498,6 +497,23 @@ func (s CreateServingEndpoint) MarshalJSON() ([]byte, error) { return marshal.Marshal(s) } +type DataPlaneInfo struct { + // Authorization details as a string. + AuthorizationDetails string `json:"authorization_details,omitempty"` + // The URL of the endpoint for this operation in the dataplane. + EndpointUrl string `json:"endpoint_url,omitempty"` + + ForceSendFields []string `json:"-"` +} + +func (s *DataPlaneInfo) UnmarshalJSON(b []byte) error { + return marshal.Unmarshal(b, s) +} + +func (s DataPlaneInfo) MarshalJSON() ([]byte, error) { + return marshal.Marshal(s) +} + type DatabricksModelServingConfig struct { // The Databricks secret key reference for a Databricks API token that // corresponds to a user or service principal with Can Query access to the @@ -981,7 +997,7 @@ type LogsRequest struct { type ModelDataPlaneInfo struct { // Information required to query DataPlane API 'query' endpoint. - QueryInfo *oauth2.DataPlaneInfo `json:"query_info,omitempty"` + QueryInfo *DataPlaneInfo `json:"query_info,omitempty"` } type OpenAiConfig struct {