Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ require (
gopkg.in/ini.v1 v1.67.3 // Apache-2.0
)

require github.com/databricks/sdk-go/core v0.0.1-dev.1 // Apache-2.0
require github.com/databricks/sdk-go/core v0.0.1-dev.8 // Apache-2.0

require (
github.com/databricks/sdk-go/auth v0.0.1-dev.1 // Apache-2.0
github.com/databricks/sdk-go/files v0.0.1-dev.1 // Apache-2.0
github.com/databricks/sdk-go/options v0.0.1-dev.1 // Apache-2.0
github.com/databricks/sdk-go/auth v0.0.1-dev.8 // Apache-2.0
github.com/databricks/sdk-go/files v0.0.1-dev.9 // Apache-2.0
github.com/databricks/sdk-go/options v0.0.1-dev.8 // Apache-2.0

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tejaskochar-db Is the mix of .8 and .9 expected?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are only cutting releases for packages that have changes themselves or in their dependancies so their latest version numbers can differ.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for clarifying.

)

require (
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMF
github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs=
github.com/databricks/databricks-sdk-go v0.178.0 h1:OLHhYYTGCZ4iAEUYoARPeeCYFIvAmpLT+L4sxRayqIc=
github.com/databricks/databricks-sdk-go v0.178.0/go.mod h1:udBw6nxkaqa0fgPQ7ZW1kGFkltQncYx+qFJeVFmxtz8=
github.com/databricks/sdk-go/auth v0.0.1-dev.1 h1:lMCXzNoqx4zf80DnqJWCy2vShCBO0CZzMn0Dv/5y9l0=
github.com/databricks/sdk-go/auth v0.0.1-dev.1/go.mod h1:4PlaTh0fyJMZwlIagNibt/844szGh1h3VVDuurVmqhw=
github.com/databricks/sdk-go/core v0.0.1-dev.1 h1:8C3AVZiAHawsmt9e3pSEcciOq817ZXpd8sddsodEVac=
github.com/databricks/sdk-go/core v0.0.1-dev.1/go.mod h1:7Ckau34bOsaZhHJE6r7ORNa+/kO33jIs6DfrJL6UbsM=
github.com/databricks/sdk-go/files v0.0.1-dev.1 h1:k9stYespxjI4kWHQkjO73YaZOlC5Ye9WVuaHgcdyugM=
github.com/databricks/sdk-go/files v0.0.1-dev.1/go.mod h1:q8bdz5nOUsajkFEsqy3qa1JTBWk3hy45upBpqzuJs7o=
github.com/databricks/sdk-go/options v0.0.1-dev.1 h1:OKhzRiYvJ4Bxd1aaRXYLyUPtvvY0+hczNMuGZ2Nrx0o=
github.com/databricks/sdk-go/options v0.0.1-dev.1/go.mod h1:hKUy8P3+AWpzbMs3iA0vr85G9ibgICuv/pYqIjgutVQ=
github.com/databricks/sdk-go/auth v0.0.1-dev.8 h1:iMOsshXRZvOrOUVZdcAc4MWQ64mqcenf9Nl803OA8Lc=
github.com/databricks/sdk-go/auth v0.0.1-dev.8/go.mod h1:YliptECFkvwuHLoHiKRqo9Drx5RVM9u5J40UDmEq0iQ=
github.com/databricks/sdk-go/core v0.0.1-dev.8 h1:xUjpesiEAFvFtrMlV16+20Wx65VoE/ptr5KTFRFrFwQ=
github.com/databricks/sdk-go/core v0.0.1-dev.8/go.mod h1:7Ckau34bOsaZhHJE6r7ORNa+/kO33jIs6DfrJL6UbsM=
github.com/databricks/sdk-go/files v0.0.1-dev.9 h1:G8F4/uE1akngntl70jjZ/HEuWYZaOZ0E78awI6M+Gpg=
github.com/databricks/sdk-go/files v0.0.1-dev.9/go.mod h1:5pMBqpem7JO7sfwAhqdidVJsaw/TQZY2j8ZCNTnBcJ8=
github.com/databricks/sdk-go/options v0.0.1-dev.8 h1:3DSZGzO3Lt8UrMe2aMrCrVwRWSAf+HDnvdkE3I6stm0=
github.com/databricks/sdk-go/options v0.0.1-dev.8/go.mod h1:c74TPXhjRn3Zitpc9/brPEdvKS7lLURtlWjVOw4m2k4=
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
21 changes: 11 additions & 10 deletions libs/filer/files_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ func newFilesAPIClient(ctx context.Context, cfg *config.Config) (*files.Client,
copts := []client.Option{
client.WithHost(cfg.Host),
client.WithCredentials(configCredentials{cfg: cfg}),
client.WithoutProfileResolution(),
client.WithoutConfigFile(),
client.WithoutEnv(),
}
// The workspace routing header is needed on unified ("SPOG") hosts; the CLI's
// "none" sentinel means "no workspace ID", so it is not forwarded.
Expand All @@ -212,7 +213,7 @@ func (w *FilesClient) Write(ctx context.Context, name string, reader io.Reader,
// Check that target path exists if CreateParentDirectories mode is not set
if !slices.Contains(mode, CreateParentDirectories) {
dir := path.Dir(absPath)
_, err := w.client.GetDirectoryMetadata(ctx, &files.GetDirectoryMetadataRequest{DirectoryPath: &dir})
_, err := w.client.GetDirectoryMetadata(ctx, files.GetDirectoryMetadataRequest{DirectoryPath: &dir})
if err != nil {
// This API returns a 404 if the directory doesn't exist.
if httpStatus(err) == http.StatusNotFound {
Expand Down Expand Up @@ -246,7 +247,7 @@ func (w *FilesClient) Write(ctx context.Context, name string, reader io.Reader,
return mapUploadError(uerr, absPath)
}

_, err = w.client.UploadFile(ctx, &files.UploadFileRequest{
_, err = w.client.UploadFile(ctx, files.UploadFileRequest{
FilePath: &absPath,
Contents: io.NopCloser(reader),
Overwrite: &overwrite,
Expand Down Expand Up @@ -294,7 +295,7 @@ func (w *FilesClient) Read(ctx context.Context, name string) (io.ReadCloser, err
return nil, err
}

resp, err := w.client.DownloadFile(ctx, &files.DownloadFileRequest{FilePath: &absPath})
resp, err := w.client.DownloadFile(ctx, files.DownloadFileRequest{FilePath: &absPath})

// Return early on success.
if err == nil {
Expand Down Expand Up @@ -326,7 +327,7 @@ func (w *FilesClient) deleteFile(ctx context.Context, name string) error {
return cannotDeleteRootError{}
}

_, err = w.client.DeleteFile(ctx, &files.DeleteFileRequest{FilePath: &absPath})
_, err = w.client.DeleteFile(ctx, files.DeleteFileRequest{FilePath: &absPath})

// Return early on success.
if err == nil {
Expand All @@ -352,7 +353,7 @@ func (w *FilesClient) deleteDirectory(ctx context.Context, name string) error {
return cannotDeleteRootError{}
}

_, err = w.client.DeleteDirectory(ctx, &files.DeleteDirectoryRequest{DirectoryPath: &absPath})
_, err = w.client.DeleteDirectory(ctx, files.DeleteDirectoryRequest{DirectoryPath: &absPath})

// Return early on success.
if err == nil {
Expand Down Expand Up @@ -474,7 +475,7 @@ func (w *FilesClient) ReadDir(ctx context.Context, name string) ([]fs.DirEntry,
}

var entries []fs.DirEntry
for entry, err := range w.client.ListDirectoryContentsIter(ctx, &files.ListDirectoryContentsRequest{
for entry, err := range w.client.ListDirectoryContentsIter(ctx, files.ListDirectoryContentsRequest{
DirectoryPath: &absPath,
}) {
if err != nil {
Expand Down Expand Up @@ -512,7 +513,7 @@ func (w *FilesClient) Mkdir(ctx context.Context, name string) error {
return err
}

_, err = w.client.CreateDirectory(ctx, &files.CreateDirectoryRequest{DirectoryPath: &absPath})
_, err = w.client.CreateDirectory(ctx, files.CreateDirectoryRequest{DirectoryPath: &absPath})

// This API returns a 409 when a file already exists at the path (the create
// is not idempotent over a file).
Expand All @@ -530,7 +531,7 @@ func (w *FilesClient) statFile(ctx context.Context, name string) (fs.FileInfo, e
return nil, err
}

resp, err := w.client.GetFileMetadata(ctx, &files.GetFileMetadataRequest{FilePath: &absPath})
resp, err := w.client.GetFileMetadata(ctx, files.GetFileMetadataRequest{FilePath: &absPath})

// If the HEAD requests succeeds, the file exists.
if err == nil {
Expand All @@ -556,7 +557,7 @@ func (w *FilesClient) statDir(ctx context.Context, name string) (fs.FileInfo, er
return nil, err
}

_, err = w.client.GetDirectoryMetadata(ctx, &files.GetDirectoryMetadataRequest{DirectoryPath: &absPath})
_, err = w.client.GetDirectoryMetadata(ctx, files.GetDirectoryMetadataRequest{DirectoryPath: &absPath})

// If the HEAD requests succeeds, the directory exists.
if err == nil {
Expand Down
51 changes: 51 additions & 0 deletions libs/filer/files_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import (
"fmt"
"io"
"io/fs"
"os"
"path/filepath"
"testing"

cliauth "github.com/databricks/cli/libs/auth"
"github.com/databricks/cli/libs/env"
"github.com/databricks/cli/libs/testserver"
"github.com/databricks/databricks-sdk-go"
Expand All @@ -16,6 +19,54 @@ import (
"github.com/stretchr/testify/require"
)

func TestNewFilesAPIClientDoesNotResolveAmbientConfig(t *testing.T) {
server := testserver.New(t)
server.Handle("HEAD", "/api/2.0/fs/files/{path...}", func(req testserver.Request) any {
assert.Equal(t, "Bearer resolved-token", req.Headers.Get("Authorization"))
assert.Empty(t, req.Headers.Get(cliauth.WorkspaceIDHeader))
return ""
})

workspaceClient, err := databricks.NewWorkspaceClient(&databricks.Config{
Host: server.URL,
Token: "resolved-token",
WorkspaceID: cliauth.WorkspaceIDNone,
})
require.NoError(t, err)

configFile := filepath.Join(t.TempDir(), ".databrickscfg")
require.NoError(t, os.WriteFile(configFile, []byte(`
[DEFAULT]
host = https://ambient.test
token = ambient-token
workspace_id = ambient-profile-workspace
`), 0o600))

testCases := []struct {
name string
configFile string
workspaceID string
}{
{name: "config file", configFile: configFile},
{name: "environment", workspaceID: "ambient-env-workspace"},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
t.Setenv("DATABRICKS_CONFIG_FILE", tc.configFile)
t.Setenv("DATABRICKS_CONFIG_PROFILE", "")
t.Setenv("DATABRICKS_WORKSPACE_ID", tc.workspaceID)

client, err := newFilesAPIClient(t.Context(), workspaceClient.Config)
require.NoError(t, err)

filePath := "/Volumes/main/schema/volume/file"
_, err = client.GetFileMetadata(t.Context(), files.GetFileMetadataRequest{FilePath: &filePath})
require.NoError(t, err)
})
}
}

func deleteDirectoryWithError(t *testing.T, statusCode int, errorCode, reason string) error {
t.Helper()

Expand Down
Loading