Skip to content

Commit

Permalink
[Dependency] Bump databricks-sdk-go to 0.44.0 (#3896)
Browse files Browse the repository at this point in the history
## Changes
This PR bumps the Databricks SDK for Go to v0.44.0.

This version removes the Impl()/WithImpl() methods of the SDK. The
cachedMe implementation is slightly dependent on this interface, so I
changed how it is initialized to work with the new version of the SDK.
Additionally, there were two tests depending on this and one line in the
exporter. The tests are probably left-over from when the provider
contained its own client implementation, but now that it uses the SDK's
client for these resources, they can be removed.

## Tests
<!-- 
How is this tested? Please see the checklist below and also describe any
other relevant tests
-->

- [ ] `make test` run locally
- [ ] relevant change in `docs/` folder
- [ ] covered with integration tests in `internal/acceptance`
- [ ] relevant acceptance tests are passing
- [ ] using Go SDK
  • Loading branch information
mgyucht authored Aug 14, 2024
1 parent 96f6c9c commit 1f8e5e1
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 66 deletions.
25 changes: 0 additions & 25 deletions access/resource_ip_access_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package access
// REST API: https://docs.databricks.com/dev-tools/api/latest/ip-access-list.html#operation/create-list

import (
"context"
"fmt"
"net/http"
"testing"
Expand All @@ -13,7 +12,6 @@ import (
"github.com/databricks/terraform-provider-databricks/qa"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

var (
Expand Down Expand Up @@ -311,26 +309,3 @@ func TestIPACLDelete_Error(t *testing.T) {
ID: TestingId,
}.ExpectError(t, "Something went wrong")
}

func TestListIpAccessLists(t *testing.T) {
client, server, err := qa.HttpFixtureClient(t, []qa.HTTPFixture{
{
Method: "GET",
Resource: "/api/2.0/ip-access-lists",
Response: map[string]any{},
},
})
require.NoError(t, err)

w, err := client.WorkspaceClient()
require.NoError(t, err)

defer server.Close()
require.NoError(t, err)

ctx := context.Background()
ipLists, err := w.IpAccessLists.Impl().List(ctx)

require.NoError(t, err)
assert.Equal(t, 0, len(ipLists.IpAccessLists))
}
25 changes: 0 additions & 25 deletions catalog/resource_volume_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package catalog

import (
"context"
"fmt"
"net/http"
"testing"
Expand All @@ -10,7 +9,6 @@ import (
"github.com/databricks/terraform-provider-databricks/common"
"github.com/databricks/terraform-provider-databricks/qa"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestVolumesCornerCases(t *testing.T) {
Expand Down Expand Up @@ -740,26 +738,3 @@ func TestVolumeDelete_Error(t *testing.T) {
ID: "testCatalogName.testSchemaName.testName",
}.ExpectError(t, "Something went wrong")
}

func TestVolumesList(t *testing.T) {
client, server, err := qa.HttpFixtureClient(t, []qa.HTTPFixture{
{
Method: http.MethodGet,
Resource: "/api/2.1/unity-catalog/volumes?catalog_name=&schema_name=",
Response: map[string]any{},
},
})
require.NoError(t, err)

w, err := client.WorkspaceClient()
require.NoError(t, err)

defer server.Close()
require.NoError(t, err)

ctx := context.Background()
vLists, err := w.Volumes.Impl().List(ctx, catalog.ListVolumesRequest{})

require.NoError(t, err)
assert.Equal(t, 0, len(vLists.Volumes))
}
6 changes: 1 addition & 5 deletions clusters/data_spark_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ func DataSourceSparkVersion() common.Resource {
return nil
}, func(s map[string]*schema.Schema) map[string]*schema.Schema {
common.CustomizeSchemaPath(s, "photon").SetDeprecated("Specify runtime_engine=\"PHOTON\" in the cluster configuration")
common.CustomizeSchemaPath(s).AddNewField("graviton", &schema.Schema{
Type: schema.TypeBool,
Optional: true,
Deprecated: "Not required anymore - it's automatically enabled on the Graviton-based node types",
})
common.CustomizeSchemaPath(s, "graviton").SetDeprecated("Not required anymore - it's automatically enabled on the Graviton-based node types")
return s
})
}
11 changes: 7 additions & 4 deletions common/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ type cachedMe struct {
mu sync.Mutex
}

func newCachedMe(inner iam.CurrentUserService) *cachedMe {
return &cachedMe{
internalImpl: inner,
}
}

func (a *cachedMe) Me(ctx context.Context) (*iam.User, error) {
a.mu.Lock()
defer a.mu.Unlock()
Expand Down Expand Up @@ -60,10 +66,7 @@ func (c *DatabricksClient) WorkspaceClient() (*databricks.WorkspaceClient, error
if err != nil {
return nil, err
}
internalImpl := w.CurrentUser.Impl()
w.CurrentUser.WithImpl(&cachedMe{
internalImpl: internalImpl,
})
w.CurrentUser = newCachedMe(w.CurrentUser)
c.cachedWorkspaceClient = w
return w, nil
}
Expand Down
20 changes: 20 additions & 0 deletions common/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/databricks/databricks-sdk-go/client"
"github.com/databricks/databricks-sdk-go/config"
"github.com/databricks/databricks-sdk-go/service/iam"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -315,3 +316,22 @@ func TestGetJWTProperty_Authenticate_Fail(t *testing.T) {
assert.True(t, strings.HasPrefix(err.Error(),
"default auth: azure-cli: cannot get access token: This is just a failing script"))
}

type mockInternalUserService struct {
count int
}

func (m *mockInternalUserService) Me(ctx context.Context) (user *iam.User, err error) {
m.count++
return &iam.User{
UserName: "test",
}, nil
}

func TestCachedMe_Me_MakesSingleRequest(t *testing.T) {
mock := &mockInternalUserService{}
cm := newCachedMe(mock)
cm.Me(context.Background())
cm.Me(context.Background())
assert.Equal(t, 1, mock.count)
}
3 changes: 1 addition & 2 deletions exporter/importables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1536,12 +1536,11 @@ var resourcesMap map[string]importable = map[string]importable{
return d.Get("list_type").(string) + "_" + d.Get("label").(string)
},
List: func(ic *importContext) error {
ipListsResp, err := ic.workspaceClient.IpAccessLists.Impl().List(ic.Context)
ipLists, err := ic.workspaceClient.IpAccessLists.ListAll(ic.Context)

if err != nil {
return err
}
ipLists := ipListsResp.IpAccessLists
for offset, ipList := range ipLists {
ic.EmitIfUpdatedAfterMillis(&resource{
Resource: "databricks_ip_access_list",
Expand Down
4 changes: 2 additions & 2 deletions exporter/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,15 +556,15 @@ func dltIsMatchingCatalogAndSchema(ic *importContext, res *resource, ra *resourc
}

func (ic *importContext) emitWorkspaceBindings(securableType, securableName string) {
bindings, err := ic.workspaceClient.WorkspaceBindings.GetBindings(ic.Context, catalog.GetBindingsRequest{
bindings, err := ic.workspaceClient.WorkspaceBindings.GetBindingsAll(ic.Context, catalog.GetBindingsRequest{
SecurableName: securableName,
SecurableType: catalog.GetBindingsSecurableType(securableType),
})
if err != nil {
log.Printf("[ERROR] listing %s bindings for %s: %s", securableType, securableName, err.Error())
return
}
for _, binding := range bindings.Bindings {
for _, binding := range bindings {
id := fmt.Sprintf("%d|%s|%s", binding.WorkspaceId, securableType, securableName)
// We were creating Data instance explicitly because of the bug in the databricks_catalog_workspace_binding
// implementation. Technically, after the fix is merged we can remove this, but we're keeping it as-is now
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/databricks/terraform-provider-databricks
go 1.22

require (
github.com/databricks/databricks-sdk-go v0.43.3-0.20240725113401-33ef9dbf3727
github.com/databricks/databricks-sdk-go v0.44.0
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/hcl v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBS
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg=
github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
github.com/databricks/databricks-sdk-go v0.43.3-0.20240725113401-33ef9dbf3727 h1:EwEUcWBPFBsosUGpyiiMXYbOfn+i5PM5hatP6gsDyXQ=
github.com/databricks/databricks-sdk-go v0.43.3-0.20240725113401-33ef9dbf3727/go.mod h1:ds+zbv5mlQG7nFEU5ojLtgN/u0/9YzZmKQES/CfedzU=
github.com/databricks/databricks-sdk-go v0.44.0 h1:9/FZACv4EFQIOYxfwYVKnY7v46xio9FKCw9tpKB2O/s=
github.com/databricks/databricks-sdk-go v0.44.0/go.mod h1:ds+zbv5mlQG7nFEU5ojLtgN/u0/9YzZmKQES/CfedzU=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down

0 comments on commit 1f8e5e1

Please sign in to comment.