From a7e785d0e84fcb5813e9b380ae5dd0d5ac16a3cb Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 19:24:41 +0100 Subject: [PATCH 01/19] Add acceptance tests for auth resolution --- acceptance/acceptance_test.go | 11 +++++- acceptance/auth/basic/out.requests.txt | 1 + acceptance/auth/basic/output.txt | 4 ++ acceptance/auth/basic/script | 8 ++++ acceptance/auth/basic/test.toml | 2 + acceptance/auth/oauth/out.requests.txt | 3 ++ acceptance/auth/oauth/output.txt | 4 ++ acceptance/auth/oauth/script | 8 ++++ acceptance/auth/oauth/test.toml | 2 + acceptance/auth/pat/out.requests.txt | 1 + acceptance/auth/pat/output.txt | 4 ++ acceptance/auth/pat/script | 3 ++ acceptance/auth/pat/test.toml | 2 + acceptance/config_test.go | 2 + acceptance/server_test.go | 16 ++++++++ libs/testdiff/golden.go | 2 +- libs/testdiff/replacement.go | 23 +++++++++++ libs/testdiff/replacement_test.go | 9 +++++ libs/testserver/server.go | 55 ++++++++++++++++++++++---- 19 files changed, 151 insertions(+), 9 deletions(-) create mode 100644 acceptance/auth/basic/out.requests.txt create mode 100644 acceptance/auth/basic/output.txt create mode 100644 acceptance/auth/basic/script create mode 100644 acceptance/auth/basic/test.toml create mode 100644 acceptance/auth/oauth/out.requests.txt create mode 100644 acceptance/auth/oauth/output.txt create mode 100644 acceptance/auth/oauth/script create mode 100644 acceptance/auth/oauth/test.toml create mode 100644 acceptance/auth/pat/out.requests.txt create mode 100644 acceptance/auth/pat/output.txt create mode 100644 acceptance/auth/pat/script create mode 100644 acceptance/auth/pat/test.toml diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 871b8bd62..fc83dcea5 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -35,7 +35,7 @@ var ( // In order to debug CLI running under acceptance test, set this to full subtest name, e.g. "bundle/variables/empty" // Then install your breakpoints and click "debug test" near TestAccept in VSCODE. // example: var SingleTest = "bundle/variables/empty" -var SingleTest = "" +var SingleTest = "auth/oauth" // If enabled, instead of compiling and running CLI externally, we'll start in-process server that accepts and runs // CLI commands. The $CLI in test scripts is a helper that just forwards command-line arguments to this server (see bin/callserver.py). @@ -120,6 +120,7 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int { if cloudEnv == "" { defaultServer := testserver.New(t) + defaultServer.HandleUnknown() AddHandlers(defaultServer) // Redirect API access to local server: t.Setenv("DATABRICKS_HOST", defaultServer.URL) @@ -156,6 +157,8 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int { testdiff.PrepareReplacementsWorkspaceClient(t, &repls, workspaceClient) testdiff.PrepareReplacementsUUID(t, &repls) testdiff.PrepareReplacementsDevVersion(t, &repls) + testdiff.PrepareReplacementSdkVersion(t, &repls) + testdiff.PrepareReplacementsGoVersion(t, &repls) testDirs := getTests(t) require.NotEmpty(t, testDirs) @@ -252,7 +255,9 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont // server otherwise is a shared resource. if len(config.Server) > 0 || config.RecordRequests { server = testserver.New(t) + server.HandleUnknown() server.RecordRequests = config.RecordRequests + server.IncludeReqHeaders = config.IncludeReqHeaders // If no custom server stubs are defined, add the default handlers. if len(config.Server) == 0 { @@ -294,8 +299,12 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont for _, req := range server.Requests { reqJson, err := json.Marshal(req) + if err == nil { + } require.NoError(t, err) + // if + line := fmt.Sprintf("%s\n", reqJson) _, err = f.WriteString(line) require.NoError(t, err) diff --git a/acceptance/auth/basic/out.requests.txt b/acceptance/auth/basic/out.requests.txt new file mode 100644 index 000000000..c2356ff6a --- /dev/null +++ b/acceptance/auth/basic/out.requests.txt @@ -0,0 +1 @@ +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"body":null} diff --git a/acceptance/auth/basic/output.txt b/acceptance/auth/basic/output.txt new file mode 100644 index 000000000..c5747c9e4 --- /dev/null +++ b/acceptance/auth/basic/output.txt @@ -0,0 +1,4 @@ +{ + "id":"[USERID]", + "userName":"[USERNAME]" +} diff --git a/acceptance/auth/basic/script b/acceptance/auth/basic/script new file mode 100644 index 000000000..aae249083 --- /dev/null +++ b/acceptance/auth/basic/script @@ -0,0 +1,8 @@ +# Unset the token which is configured by default +# in acceptance tests +export DATABRICKS_TOKEN="" + +export DATABRICKS_USERNAME=username +export DATABRICKS_PASSWORD=password + +$CLI current-user me diff --git a/acceptance/auth/basic/test.toml b/acceptance/auth/basic/test.toml new file mode 100644 index 000000000..478a09c9e --- /dev/null +++ b/acceptance/auth/basic/test.toml @@ -0,0 +1,2 @@ +RecordRequests = true +IncludeReqHeaders = ["Authorization", "User-Agent"] diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/oauth/out.requests.txt new file mode 100644 index 000000000..2918b2fb9 --- /dev/null +++ b/acceptance/auth/oauth/out.requests.txt @@ -0,0 +1,3 @@ +{"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin"},"body":""} +{"method":"POST","path":"/oidc/v1/token","headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin"},"body":"grant_type=client_credentials\u0026scope=all-apis"} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"body":""} diff --git a/acceptance/auth/oauth/output.txt b/acceptance/auth/oauth/output.txt new file mode 100644 index 000000000..c5747c9e4 --- /dev/null +++ b/acceptance/auth/oauth/output.txt @@ -0,0 +1,4 @@ +{ + "id":"[USERID]", + "userName":"[USERNAME]" +} diff --git a/acceptance/auth/oauth/script b/acceptance/auth/oauth/script new file mode 100644 index 000000000..e4519e41b --- /dev/null +++ b/acceptance/auth/oauth/script @@ -0,0 +1,8 @@ +# Unset the token which is configured by default +# in acceptance tests +export DATABRICKS_TOKEN="" + +export DATABRICKS_CLIENT_ID=client_id +export DATABRICKS_CLIENT_SECRET=client_secret + +$CLI current-user me diff --git a/acceptance/auth/oauth/test.toml b/acceptance/auth/oauth/test.toml new file mode 100644 index 000000000..478a09c9e --- /dev/null +++ b/acceptance/auth/oauth/test.toml @@ -0,0 +1,2 @@ +RecordRequests = true +IncludeReqHeaders = ["Authorization", "User-Agent"] diff --git a/acceptance/auth/pat/out.requests.txt b/acceptance/auth/pat/out.requests.txt new file mode 100644 index 000000000..40f6206d5 --- /dev/null +++ b/acceptance/auth/pat/out.requests.txt @@ -0,0 +1 @@ +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"body":null} diff --git a/acceptance/auth/pat/output.txt b/acceptance/auth/pat/output.txt new file mode 100644 index 000000000..c5747c9e4 --- /dev/null +++ b/acceptance/auth/pat/output.txt @@ -0,0 +1,4 @@ +{ + "id":"[USERID]", + "userName":"[USERNAME]" +} diff --git a/acceptance/auth/pat/script b/acceptance/auth/pat/script new file mode 100644 index 000000000..ccf1098e7 --- /dev/null +++ b/acceptance/auth/pat/script @@ -0,0 +1,3 @@ +export DATABRICKS_TOKEN=dapi1234 + +$CLI current-user me diff --git a/acceptance/auth/pat/test.toml b/acceptance/auth/pat/test.toml new file mode 100644 index 000000000..478a09c9e --- /dev/null +++ b/acceptance/auth/pat/test.toml @@ -0,0 +1,2 @@ +RecordRequests = true +IncludeReqHeaders = ["Authorization", "User-Agent"] diff --git a/acceptance/config_test.go b/acceptance/config_test.go index c7be223de..f232c3cf7 100644 --- a/acceptance/config_test.go +++ b/acceptance/config_test.go @@ -47,6 +47,8 @@ type TestConfig struct { // Record the requests made to the server and write them as output to // out.requests.txt RecordRequests bool + // Include the following request headers in the recorded requests + IncludeReqHeaders []string } type ServerStub struct { diff --git a/acceptance/server_test.go b/acceptance/server_test.go index 4957a7668..e47c1b0f1 100644 --- a/acceptance/server_test.go +++ b/acceptance/server_test.go @@ -94,4 +94,20 @@ func AddHandlers(server *testserver.Server) { server.Handle("POST /api/2.0/workspace/mkdirs", func(r *http.Request) (any, error) { return "{}", nil }) + + server.Handle("GET /oidc/.well-known/oauth-authorization-server", func(r *http.Request) (any, error) { + return map[string]string{ + "authorization_endpoint": server.URL + "oidc/v1/authorize", + "token_endpoint": server.URL + "/oidc/v1/token", + }, nil + }) + + server.Handle("POST /oidc/v1/token", func(r *http.Request) (any, error) { + return map[string]string{ + "access_token": "oauth-token", + "expires_in": "3600", + "scope": "all-apis", + "token_type": "Bearer", + }, nil + }) } diff --git a/libs/testdiff/golden.go b/libs/testdiff/golden.go index c1c51b6c5..bc1e738e4 100644 --- a/libs/testdiff/golden.go +++ b/libs/testdiff/golden.go @@ -14,7 +14,7 @@ import ( var OverwriteMode = false func init() { - flag.BoolVar(&OverwriteMode, "update", false, "Overwrite golden files") + flag.BoolVar(&OverwriteMode, "update", true, "Overwrite golden files") } func ReadFile(t testutil.TestingT, ctx context.Context, filename string) string { diff --git a/libs/testdiff/replacement.go b/libs/testdiff/replacement.go index 5bbba1be1..241988819 100644 --- a/libs/testdiff/replacement.go +++ b/libs/testdiff/replacement.go @@ -12,6 +12,7 @@ import ( "github.com/databricks/cli/libs/iamutil" "github.com/databricks/databricks-sdk-go" "github.com/databricks/databricks-sdk-go/service/iam" + "golang.org/x/mod/semver" ) const ( @@ -208,3 +209,25 @@ func PrepareReplacementsDevVersion(t testutil.TestingT, r *ReplacementsContext) t.Helper() r.append(devVersionRegex, "[DEV_VERSION]") } + +func PrepareReplacementSdkVersion(t testutil.TestingT, r *ReplacementsContext) { + t.Helper() + r.Set(databricks.Version(), "[SDK_VERSION]") +} + +func goVersion() string { + gv := runtime.Version() + ssv := strings.ReplaceAll(gv, "go", "v") + sv := semver.Canonical(ssv) + return strings.TrimPrefix(sv, "v") +} + +func PrepareReplacementsGoVersion(t testutil.TestingT, r *ReplacementsContext) { + t.Helper() + r.Set(goVersion(), "[GO_VERSION]") +} + +func PrepareReplaceOS(t testutil.TestingT, r *ReplacementsContext) { + t.Helper() + r.Set(runtime.GOOS, "[OS]") +} diff --git a/libs/testdiff/replacement_test.go b/libs/testdiff/replacement_test.go index 1b6c5fe2d..f5d08d81e 100644 --- a/libs/testdiff/replacement_test.go +++ b/libs/testdiff/replacement_test.go @@ -1,6 +1,7 @@ package testdiff import ( + "runtime" "testing" "github.com/stretchr/testify/assert" @@ -44,3 +45,11 @@ func TestReplacement_TemporaryDirectory(t *testing.T) { assert.Equal(t, "/tmp/.../tail", repls.Replace("/tmp/foo/bar/qux/tail")) } + +func TestReplacement_OS(t *testing.T) { + var repls ReplacementsContext + + PrepareReplaceOS(t, &repls) + + assert.Equal(t, "[OS]", repls.Replace(runtime.GOOS)) +} diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 2e8dbdfda..a51ef6f54 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -2,9 +2,12 @@ package testserver import ( "encoding/json" + "errors" + "fmt" "io" "net/http" "net/http/httptest" + "slices" "github.com/stretchr/testify/assert" @@ -17,15 +20,17 @@ type Server struct { t testutil.TestingT - RecordRequests bool + RecordRequests bool + IncludeReqHeaders []string Requests []Request } type Request struct { - Method string `json:"method"` - Path string `json:"path"` - Body any `json:"body"` + Method string `json:"method"` + Path string `json:"path"` + Headers map[string]string `json:"headers,omitempty"` + Body any `json:"body,omitempty"` } func New(t testutil.TestingT) *Server { @@ -40,6 +45,23 @@ func New(t testutil.TestingT) *Server { } } +func (s *Server) HandleUnknown() { + s.Handle("/", func(req *http.Request) (any, error) { + msg := fmt.Sprintf(` +unknown API request received. Please add a handler for this request in +your test. You can copy the following snippet in your test.toml file: + +[[Server]] +Pattern = %s %s +Response = ''' + +'''`, req.Method, req.URL.Path) + + s.t.Fatalf(msg) + return nil, errors.New("unknown API request") + }) +} + type HandlerFunc func(req *http.Request) (resp any, err error) func (s *Server) Handle(pattern string, handler HandlerFunc) { @@ -54,10 +76,29 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) { body, err := io.ReadAll(r.Body) assert.NoError(s.t, err) + headers := make(map[string]string) + for k, v := range r.Header { + if !slices.Contains(s.IncludeReqHeaders, k) { + continue + } + if len(v) == 0 { + continue + } + headers[k] = v[0] + } + + var reqBody any + if len(body) > 0 && body[0] == '{' { + reqBody = json.RawMessage(body) + } else { + reqBody = string(body) + } + s.Requests = append(s.Requests, Request{ - Method: r.Method, - Path: r.URL.Path, - Body: json.RawMessage(body), + Method: r.Method, + Path: r.URL.Path, + Headers: headers, + Body: reqBody, }) } From 6abfe52081a03552e739baead0f83c1274fe3d7e Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 19:25:15 +0100 Subject: [PATCH 02/19] - --- acceptance/acceptance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index fc83dcea5..0fc8d8484 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -35,7 +35,7 @@ var ( // In order to debug CLI running under acceptance test, set this to full subtest name, e.g. "bundle/variables/empty" // Then install your breakpoints and click "debug test" near TestAccept in VSCODE. // example: var SingleTest = "bundle/variables/empty" -var SingleTest = "auth/oauth" +var SingleTest = "" // If enabled, instead of compiling and running CLI externally, we'll start in-process server that accepts and runs // CLI commands. The $CLI in test scripts is a helper that just forwards command-line arguments to this server (see bin/callserver.py). From 9c0efb62124ba2ae9aa9da7de6d4391d6fdcff0e Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 19:26:19 +0100 Subject: [PATCH 03/19] - --- acceptance/acceptance_test.go | 2 +- acceptance/auth/basic/out.requests.txt | 2 +- acceptance/auth/oauth/out.requests.txt | 6 ++-- acceptance/auth/pat/out.requests.txt | 2 +- acceptance/bundle/scripts/output.txt | 6 +--- acceptance/terraform/output.txt | 50 +++++--------------------- libs/testdiff/golden.go | 2 +- 7 files changed, 16 insertions(+), 54 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 0fc8d8484..66caf0e83 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -158,7 +158,7 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int { testdiff.PrepareReplacementsUUID(t, &repls) testdiff.PrepareReplacementsDevVersion(t, &repls) testdiff.PrepareReplacementSdkVersion(t, &repls) - testdiff.PrepareReplacementsGoVersion(t, &repls) + testdiff.PrepareReplaceOS(t, &repls) testDirs := getTests(t) require.NotEmpty(t, testDirs) diff --git a/acceptance/auth/basic/out.requests.txt b/acceptance/auth/basic/out.requests.txt index c2356ff6a..f02ed1801 100644 --- a/acceptance/auth/basic/out.requests.txt +++ b/acceptance/auth/basic/out.requests.txt @@ -1 +1 @@ -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"body":null} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"body":""} diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/oauth/out.requests.txt index 2918b2fb9..22fa2530b 100644 --- a/acceptance/auth/oauth/out.requests.txt +++ b/acceptance/auth/oauth/out.requests.txt @@ -1,3 +1,3 @@ -{"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin"},"body":""} -{"method":"POST","path":"/oidc/v1/token","headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin"},"body":"grant_type=client_credentials\u0026scope=all-apis"} -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"body":""} +{"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS]"},"body":""} +{"method":"POST","path":"/oidc/v1/token","headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS]"},"body":"grant_type=client_credentials\u0026scope=all-apis"} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"body":""} diff --git a/acceptance/auth/pat/out.requests.txt b/acceptance/auth/pat/out.requests.txt index 40f6206d5..65dc766d1 100644 --- a/acceptance/auth/pat/out.requests.txt +++ b/acceptance/auth/pat/out.requests.txt @@ -1 +1 @@ -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/darwin cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"body":null} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"body":""} diff --git a/acceptance/bundle/scripts/output.txt b/acceptance/bundle/scripts/output.txt index 2deedb0e7..c0142c0ac 100644 --- a/acceptance/bundle/scripts/output.txt +++ b/acceptance/bundle/scripts/output.txt @@ -42,11 +42,7 @@ from myscript.py 0 postbuild: hello stderr! Executing 'predeploy' script from myscript.py 0 predeploy: hello stdout! from myscript.py 0 predeploy: hello stderr! -Error: unable to deploy to /Workspace/Users/[USERNAME]/.bundle/scripts/default/state as [USERNAME]. -Please make sure the current user or one of their groups is listed under the permissions of this bundle. -For assistance, contact the owners of this project. -They may need to redeploy the bundle to apply the new permissions. -Please refer to https://docs.databricks.com/dev-tools/bundles/permissions.html for more on managing permissions. +Error: Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Fscripts%2Fdefault%2Fstate%2Fdeploy.lock?overwrite=false": EOF Exit code: 1 diff --git a/acceptance/terraform/output.txt b/acceptance/terraform/output.txt index 6bdc809f6..b25aef04b 100644 --- a/acceptance/terraform/output.txt +++ b/acceptance/terraform/output.txt @@ -1,51 +1,17 @@ >>> [TERRAFORM] init -no-color -get=false +Error: Failed to install provider + +Error while installing databricks/databricks v1.64.1: provider binary not +found: could not find executable file starting with +terraform-provider-databricks + + Initializing the backend... Initializing provider plugins... - Finding databricks/databricks versions matching "1.64.1"... - Installing databricks/databricks v1.64.1... -- Installed databricks/databricks v1.64.1 (unauthenticated) -Terraform has created a lock file .terraform.lock.hcl to record the provider -selections it made above. Include this file in your version control repository -so that Terraform can guarantee to make the same selections by default when -you run "terraform init" in the future. - - -Warning: Incomplete lock file information for providers - -Due to your customized provider installation methods, Terraform was forced to -calculate lock file checksums locally for the following providers: - - databricks/databricks - - -To calculate additional checksums for another platform, run: - terraform providers lock -platform=linux_amd64 -(where linux_amd64 is the platform to generate) - -Terraform has been successfully initialized! - -You may now begin working with Terraform. Try running "terraform plan" to see -any changes that are required for your infrastructure. All Terraform commands -should now work. - -If you ever set or change modules or backend configuration for Terraform, -rerun this command to reinitialize your working directory. If you forget, other -commands will detect it and remind you to do so if necessary. - ->>> [TERRAFORM] plan -no-color -data.databricks_current_user.me: Reading... -data.databricks_current_user.me: Read complete after (redacted) [id=[USERID]] - -Changes to Outputs: - + username = "[USERNAME]" - -You can apply this plan to save these new output values to the Terraform -state, without changing any real infrastructure. - -───────────────────────────────────────────────────────────────────────────── - -Note: You didn't use the -out option to save this plan, so Terraform can't -guarantee to take exactly these actions if you run "terraform apply" now. +Exit code: 1 diff --git a/libs/testdiff/golden.go b/libs/testdiff/golden.go index bc1e738e4..c1c51b6c5 100644 --- a/libs/testdiff/golden.go +++ b/libs/testdiff/golden.go @@ -14,7 +14,7 @@ import ( var OverwriteMode = false func init() { - flag.BoolVar(&OverwriteMode, "update", true, "Overwrite golden files") + flag.BoolVar(&OverwriteMode, "update", false, "Overwrite golden files") } func ReadFile(t testutil.TestingT, ctx context.Context, filename string) string { From 5e9d63280ab8cc358d91200a1a8eca2ff7a7e020 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 19:33:02 +0100 Subject: [PATCH 04/19] - --- acceptance/acceptance_test.go | 1 + acceptance/auth/basic/out.requests.txt | 2 +- acceptance/auth/basic/test.toml | 2 ++ acceptance/auth/oauth/out.requests.txt | 6 +++--- acceptance/auth/oauth/test.toml | 2 ++ acceptance/auth/pat/out.requests.txt | 2 +- acceptance/auth/pat/test.toml | 2 ++ acceptance/bundle/scripts/test.toml | 1 + acceptance/server.go | 0 9 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 acceptance/server.go diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 66caf0e83..d9970f66f 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -158,6 +158,7 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int { testdiff.PrepareReplacementsUUID(t, &repls) testdiff.PrepareReplacementsDevVersion(t, &repls) testdiff.PrepareReplacementSdkVersion(t, &repls) + testdiff.PrepareReplacementsGoVersion(t, &repls) testdiff.PrepareReplaceOS(t, &repls) testDirs := getTests(t) diff --git a/acceptance/auth/basic/out.requests.txt b/acceptance/auth/basic/out.requests.txt index f02ed1801..03ebfd5a2 100644 --- a/acceptance/auth/basic/out.requests.txt +++ b/acceptance/auth/basic/out.requests.txt @@ -1 +1 @@ -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"body":""} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"body":""} diff --git a/acceptance/auth/basic/test.toml b/acceptance/auth/basic/test.toml index 478a09c9e..9dae1dca7 100644 --- a/acceptance/auth/basic/test.toml +++ b/acceptance/auth/basic/test.toml @@ -1,2 +1,4 @@ +LocalOnly = true + RecordRequests = true IncludeReqHeaders = ["Authorization", "User-Agent"] diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/oauth/out.requests.txt index 22fa2530b..41d09042e 100644 --- a/acceptance/auth/oauth/out.requests.txt +++ b/acceptance/auth/oauth/out.requests.txt @@ -1,3 +1,3 @@ -{"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS]"},"body":""} -{"method":"POST","path":"/oidc/v1/token","headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS]"},"body":"grant_type=client_credentials\u0026scope=all-apis"} -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"body":""} +{"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"body":""} +{"method":"POST","path":"/oidc/v1/token","headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"body":"grant_type=client_credentials\u0026scope=all-apis"} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"body":""} diff --git a/acceptance/auth/oauth/test.toml b/acceptance/auth/oauth/test.toml index 478a09c9e..9dae1dca7 100644 --- a/acceptance/auth/oauth/test.toml +++ b/acceptance/auth/oauth/test.toml @@ -1,2 +1,4 @@ +LocalOnly = true + RecordRequests = true IncludeReqHeaders = ["Authorization", "User-Agent"] diff --git a/acceptance/auth/pat/out.requests.txt b/acceptance/auth/pat/out.requests.txt index 65dc766d1..694f2e8e2 100644 --- a/acceptance/auth/pat/out.requests.txt +++ b/acceptance/auth/pat/out.requests.txt @@ -1 +1 @@ -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/1.23.4 os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"body":""} +{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"body":""} diff --git a/acceptance/auth/pat/test.toml b/acceptance/auth/pat/test.toml index 478a09c9e..9dae1dca7 100644 --- a/acceptance/auth/pat/test.toml +++ b/acceptance/auth/pat/test.toml @@ -1,2 +1,4 @@ +LocalOnly = true + RecordRequests = true IncludeReqHeaders = ["Authorization", "User-Agent"] diff --git a/acceptance/bundle/scripts/test.toml b/acceptance/bundle/scripts/test.toml index 1dbd78681..02e9f423c 100644 --- a/acceptance/bundle/scripts/test.toml +++ b/acceptance/bundle/scripts/test.toml @@ -1 +1,2 @@ LocalOnly = true # Deployment currently fails when run locally; once that is fixed, remove this setting + diff --git a/acceptance/server.go b/acceptance/server.go new file mode 100644 index 000000000..e69de29bb From b076b750f15e3bc7690031d6d3e1f32fe97eac7c Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 19:49:38 +0100 Subject: [PATCH 05/19] fix --- acceptance/server.go | 0 acceptance/server_test.go | 4 ++++ 2 files changed, 4 insertions(+) delete mode 100644 acceptance/server.go diff --git a/acceptance/server.go b/acceptance/server.go deleted file mode 100644 index e69de29bb..000000000 diff --git a/acceptance/server_test.go b/acceptance/server_test.go index e47c1b0f1..50319a1c8 100644 --- a/acceptance/server_test.go +++ b/acceptance/server_test.go @@ -110,4 +110,8 @@ func AddHandlers(server *testserver.Server) { "token_type": "Bearer", }, nil }) + + server.Handle("POST /api/2.0/workspace-files/import-file/", func(r *http.Request) (any, error) { + return "{}", nil + }) } From b66bfb2c932aa25cdb1e281e3d6c4072552c5ce7 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 19:50:16 +0100 Subject: [PATCH 06/19] - --- acceptance/acceptance_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index d9970f66f..976c63f74 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -300,12 +300,8 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont for _, req := range server.Requests { reqJson, err := json.Marshal(req) - if err == nil { - } require.NoError(t, err) - // if - line := fmt.Sprintf("%s\n", reqJson) _, err = f.WriteString(line) require.NoError(t, err) From eb8e9854d4a564d67b0bedc6f78e5bccaceda6cb Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 20:01:01 +0100 Subject: [PATCH 07/19] -gs --- acceptance/bundle/scripts/output.txt | 23 ++++++++++++++++++++++- acceptance/server_test.go | 3 ++- libs/testdiff/golden.go | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/acceptance/bundle/scripts/output.txt b/acceptance/bundle/scripts/output.txt index c0142c0ac..8a1fa8409 100644 --- a/acceptance/bundle/scripts/output.txt +++ b/acceptance/bundle/scripts/output.txt @@ -42,7 +42,28 @@ from myscript.py 0 postbuild: hello stderr! Executing 'predeploy' script from myscript.py 0 predeploy: hello stdout! from myscript.py 0 predeploy: hello stderr! -Error: Post "[DATABRICKS_URL]/api/2.0/workspace-files/import-file/Workspace%2FUsers%2F[USERNAME]%2F.bundle%2Fscripts%2Fdefault%2Fstate%2Fdeploy.lock?overwrite=false": EOF +Error: unable to parse response. This is likely a bug in the Databricks SDK for Go or the underlying REST API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-go/issues. Request log: +``` +POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/scripts/default/state/deploy.lock?overwrite=false +> * Host: +> * Accept: application/json +> * Authorization: REDACTED +> * Traceparent: 00-065d5ec735d5eae4dab651801abba98f-05acfeff8caffc7c-01 +> * User-Agent: cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] auth/pat +> { +> "AcquisitionTime": "2025-02-03T20:00:19.375383+01:00", +> "ID": "[UUID]", +> "IsForced": false, +> "User": "[USERNAME]" +> } +< HTTP/1.1 500 Internal Server Error +< * Content-Length: 16 +< * Content-Type: text/plain; charset=utf-8 +< * Date: Mon, 03 Feb 2025 19:00:19 GMT +< * X-Content-Type-Options: nosniff +< not implemented +< +``` Exit code: 1 diff --git a/acceptance/server_test.go b/acceptance/server_test.go index 50319a1c8..7b860063c 100644 --- a/acceptance/server_test.go +++ b/acceptance/server_test.go @@ -1,6 +1,7 @@ package acceptance_test import ( + "errors" "net/http" "github.com/databricks/cli/libs/testserver" @@ -112,6 +113,6 @@ func AddHandlers(server *testserver.Server) { }) server.Handle("POST /api/2.0/workspace-files/import-file/", func(r *http.Request) (any, error) { - return "{}", nil + return "{}", errors.New("not implemented") }) } diff --git a/libs/testdiff/golden.go b/libs/testdiff/golden.go index c1c51b6c5..bc1e738e4 100644 --- a/libs/testdiff/golden.go +++ b/libs/testdiff/golden.go @@ -14,7 +14,7 @@ import ( var OverwriteMode = false func init() { - flag.BoolVar(&OverwriteMode, "update", false, "Overwrite golden files") + flag.BoolVar(&OverwriteMode, "update", true, "Overwrite golden files") } func ReadFile(t testutil.TestingT, ctx context.Context, filename string) string { From 6fabd756f0181576bb135dbb3c3e0e2f228df1db Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 20:01:06 +0100 Subject: [PATCH 08/19] - --- libs/testdiff/golden.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/testdiff/golden.go b/libs/testdiff/golden.go index bc1e738e4..c1c51b6c5 100644 --- a/libs/testdiff/golden.go +++ b/libs/testdiff/golden.go @@ -14,7 +14,7 @@ import ( var OverwriteMode = false func init() { - flag.BoolVar(&OverwriteMode, "update", true, "Overwrite golden files") + flag.BoolVar(&OverwriteMode, "update", false, "Overwrite golden files") } func ReadFile(t testutil.TestingT, ctx context.Context, filename string) string { From a40dc8cf3cab685a81ff9c245774a0820618a8f6 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 3 Feb 2025 20:05:30 +0100 Subject: [PATCH 09/19] cleanup: --- acceptance/bundle/scripts/test.toml | 1 - libs/testserver/server.go | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/acceptance/bundle/scripts/test.toml b/acceptance/bundle/scripts/test.toml index 02e9f423c..1dbd78681 100644 --- a/acceptance/bundle/scripts/test.toml +++ b/acceptance/bundle/scripts/test.toml @@ -1,2 +1 @@ LocalOnly = true # Deployment currently fails when run locally; once that is fixed, remove this setting - diff --git a/libs/testserver/server.go b/libs/testserver/server.go index a51ef6f54..e73b4f565 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -54,7 +54,7 @@ your test. You can copy the following snippet in your test.toml file: [[Server]] Pattern = %s %s Response = ''' - + '''`, req.Method, req.URL.Path) s.t.Fatalf(msg) @@ -89,6 +89,7 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) { var reqBody any if len(body) > 0 && body[0] == '{' { + // serialize the body as is, if it's JSON reqBody = json.RawMessage(body) } else { reqBody = string(body) From bbc23ad0f7ed2b04518d0c7be7cb1a3aecaf439b Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 13:14:10 +0100 Subject: [PATCH 10/19] - --- acceptance/acceptance_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index b5ef48424..f205217ff 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -120,7 +120,6 @@ func testAccept(t *testing.T, InprocessMode bool, singleTest string) int { if cloudEnv == "" { defaultServer := testserver.New(t) - defaultServer.HandleUnknown() AddHandlers(defaultServer) // Redirect API access to local server: t.Setenv("DATABRICKS_HOST", defaultServer.URL) @@ -255,7 +254,6 @@ func runTest(t *testing.T, dir, coverDir string, repls testdiff.ReplacementsCont // server otherwise is a shared resource. if len(config.Server) > 0 || config.RecordRequests { server = testserver.New(t) - server.HandleUnknown() server.RecordRequests = config.RecordRequests server.IncludeRequestHeaders = config.IncludeRequestHeaders From 5a1f36e07ddf56cd7662cba7cb07b02a17fbe5c0 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 13:16:42 +0100 Subject: [PATCH 11/19] - --- acceptance/bundle/scripts/output.txt | 27 +++------------ acceptance/server_test.go | 13 +++----- acceptance/terraform/output.txt | 50 +++++++++++++++++++++++----- libs/testdiff/replacement_test.go | 9 ----- libs/testserver/server.go | 2 -- 5 files changed, 51 insertions(+), 50 deletions(-) diff --git a/acceptance/bundle/scripts/output.txt b/acceptance/bundle/scripts/output.txt index 8a1fa8409..2deedb0e7 100644 --- a/acceptance/bundle/scripts/output.txt +++ b/acceptance/bundle/scripts/output.txt @@ -42,28 +42,11 @@ from myscript.py 0 postbuild: hello stderr! Executing 'predeploy' script from myscript.py 0 predeploy: hello stdout! from myscript.py 0 predeploy: hello stderr! -Error: unable to parse response. This is likely a bug in the Databricks SDK for Go or the underlying REST API. Please report this issue with the following debugging information to the SDK issue tracker at https://github.com/databricks/databricks-sdk-go/issues. Request log: -``` -POST /api/2.0/workspace-files/import-file/Workspace/Users/[USERNAME]/.bundle/scripts/default/state/deploy.lock?overwrite=false -> * Host: -> * Accept: application/json -> * Authorization: REDACTED -> * Traceparent: 00-065d5ec735d5eae4dab651801abba98f-05acfeff8caffc7c-01 -> * User-Agent: cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/bundle_deploy cmd-exec-id/[UUID] auth/pat -> { -> "AcquisitionTime": "2025-02-03T20:00:19.375383+01:00", -> "ID": "[UUID]", -> "IsForced": false, -> "User": "[USERNAME]" -> } -< HTTP/1.1 500 Internal Server Error -< * Content-Length: 16 -< * Content-Type: text/plain; charset=utf-8 -< * Date: Mon, 03 Feb 2025 19:00:19 GMT -< * X-Content-Type-Options: nosniff -< not implemented -< -``` +Error: unable to deploy to /Workspace/Users/[USERNAME]/.bundle/scripts/default/state as [USERNAME]. +Please make sure the current user or one of their groups is listed under the permissions of this bundle. +For assistance, contact the owners of this project. +They may need to redeploy the bundle to apply the new permissions. +Please refer to https://docs.databricks.com/dev-tools/bundles/permissions.html for more on managing permissions. Exit code: 1 diff --git a/acceptance/server_test.go b/acceptance/server_test.go index 67109d56c..d714bdcd2 100644 --- a/acceptance/server_test.go +++ b/acceptance/server_test.go @@ -1,7 +1,6 @@ package acceptance_test import ( - "errors" "net/http" "github.com/databricks/cli/libs/testserver" @@ -96,23 +95,19 @@ func AddHandlers(server *testserver.Server) { return "{}", http.StatusOK }) - server.Handle("GET /oidc/.well-known/oauth-authorization-server", func(r *http.Request) (any, error) { + server.Handle("GET /oidc/.well-known/oauth-authorization-server", func(r *http.Request) (any, int) { return map[string]string{ "authorization_endpoint": server.URL + "oidc/v1/authorize", "token_endpoint": server.URL + "/oidc/v1/token", - }, nil + }, http.StatusOK }) - server.Handle("POST /oidc/v1/token", func(r *http.Request) (any, error) { + server.Handle("POST /oidc/v1/token", func(r *http.Request) (any, int) { return map[string]string{ "access_token": "oauth-token", "expires_in": "3600", "scope": "all-apis", "token_type": "Bearer", - }, nil - }) - - server.Handle("POST /api/2.0/workspace-files/import-file/", func(r *http.Request) (any, error) { - return "{}", errors.New("not implemented") + }, http.StatusOK }) } diff --git a/acceptance/terraform/output.txt b/acceptance/terraform/output.txt index b25aef04b..6bdc809f6 100644 --- a/acceptance/terraform/output.txt +++ b/acceptance/terraform/output.txt @@ -1,17 +1,51 @@ >>> [TERRAFORM] init -no-color -get=false -Error: Failed to install provider - -Error while installing databricks/databricks v1.64.1: provider binary not -found: could not find executable file starting with -terraform-provider-databricks - - Initializing the backend... Initializing provider plugins... - Finding databricks/databricks versions matching "1.64.1"... - Installing databricks/databricks v1.64.1... +- Installed databricks/databricks v1.64.1 (unauthenticated) -Exit code: 1 +Terraform has created a lock file .terraform.lock.hcl to record the provider +selections it made above. Include this file in your version control repository +so that Terraform can guarantee to make the same selections by default when +you run "terraform init" in the future. + + +Warning: Incomplete lock file information for providers + +Due to your customized provider installation methods, Terraform was forced to +calculate lock file checksums locally for the following providers: + - databricks/databricks + + +To calculate additional checksums for another platform, run: + terraform providers lock -platform=linux_amd64 +(where linux_amd64 is the platform to generate) + +Terraform has been successfully initialized! + +You may now begin working with Terraform. Try running "terraform plan" to see +any changes that are required for your infrastructure. All Terraform commands +should now work. + +If you ever set or change modules or backend configuration for Terraform, +rerun this command to reinitialize your working directory. If you forget, other +commands will detect it and remind you to do so if necessary. + +>>> [TERRAFORM] plan -no-color +data.databricks_current_user.me: Reading... +data.databricks_current_user.me: Read complete after (redacted) [id=[USERID]] + +Changes to Outputs: + + username = "[USERNAME]" + +You can apply this plan to save these new output values to the Terraform +state, without changing any real infrastructure. + +───────────────────────────────────────────────────────────────────────────── + +Note: You didn't use the -out option to save this plan, so Terraform can't +guarantee to take exactly these actions if you run "terraform apply" now. diff --git a/libs/testdiff/replacement_test.go b/libs/testdiff/replacement_test.go index f5d08d81e..1b6c5fe2d 100644 --- a/libs/testdiff/replacement_test.go +++ b/libs/testdiff/replacement_test.go @@ -1,7 +1,6 @@ package testdiff import ( - "runtime" "testing" "github.com/stretchr/testify/assert" @@ -45,11 +44,3 @@ func TestReplacement_TemporaryDirectory(t *testing.T) { assert.Equal(t, "/tmp/.../tail", repls.Replace("/tmp/foo/bar/qux/tail")) } - -func TestReplacement_OS(t *testing.T) { - var repls ReplacementsContext - - PrepareReplaceOS(t, &repls) - - assert.Equal(t, "[OS]", repls.Replace(runtime.GOOS)) -} diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 6ccd155ce..5e3efe1c5 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -2,8 +2,6 @@ package testserver import ( "encoding/json" - "errors" - "fmt" "io" "net/http" "net/http/httptest" From 61b2e22f5eeebc07a067011fc585f5a4543ec047 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 15:03:27 +0100 Subject: [PATCH 12/19] - --- acceptance/acceptance_test.go | 2 +- acceptance/auth/basic/out.requests.txt | 2 +- acceptance/auth/basic/test.toml | 18 +++++++++++++++++- acceptance/auth/oauth/test.toml | 18 +++++++++++++++++- acceptance/auth/pat/test.toml | 18 +++++++++++++++++- libs/testserver/server.go | 12 +++++++++++- 6 files changed, 64 insertions(+), 6 deletions(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index f205217ff..7126ccb83 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -35,7 +35,7 @@ var ( // In order to debug CLI running under acceptance test, set this to full subtest name, e.g. "bundle/variables/empty" // Then install your breakpoints and click "debug test" near TestAccept in VSCODE. // example: var SingleTest = "bundle/variables/empty" -var SingleTest = "" +var SingleTest = "auth/basic" // If enabled, instead of compiling and running CLI externally, we'll start in-process server that accepts and runs // CLI commands. The $CLI in test scripts is a helper that just forwards command-line arguments to this server (see bin/callserver.py). diff --git a/acceptance/auth/basic/out.requests.txt b/acceptance/auth/basic/out.requests.txt index 03ebfd5a2..0d005d5e6 100644 --- a/acceptance/auth/basic/out.requests.txt +++ b/acceptance/auth/basic/out.requests.txt @@ -1 +1 @@ -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"body":""} +{"headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/acceptance/auth/basic/test.toml b/acceptance/auth/basic/test.toml index 9dae1dca7..89438f43a 100644 --- a/acceptance/auth/basic/test.toml +++ b/acceptance/auth/basic/test.toml @@ -1,4 +1,20 @@ LocalOnly = true RecordRequests = true -IncludeReqHeaders = ["Authorization", "User-Agent"] +IncludeRequestHeaders = ["Authorization", "User-Agent"] + +[[Repls]] +Old = '(linux|darwin|windows)' +New = '[OS]' + +[[Repls]] +Old = " upstream/[A-Za-z0-9.-]+" +New = "" + +[[Repls]] +Old = " upstream-version/[A-Za-z0-9.-]+" +New = "" + +[[Repls]] +Old = " cicd/[A-Za-z0-9.-]+" +New = "" diff --git a/acceptance/auth/oauth/test.toml b/acceptance/auth/oauth/test.toml index 9dae1dca7..89438f43a 100644 --- a/acceptance/auth/oauth/test.toml +++ b/acceptance/auth/oauth/test.toml @@ -1,4 +1,20 @@ LocalOnly = true RecordRequests = true -IncludeReqHeaders = ["Authorization", "User-Agent"] +IncludeRequestHeaders = ["Authorization", "User-Agent"] + +[[Repls]] +Old = '(linux|darwin|windows)' +New = '[OS]' + +[[Repls]] +Old = " upstream/[A-Za-z0-9.-]+" +New = "" + +[[Repls]] +Old = " upstream-version/[A-Za-z0-9.-]+" +New = "" + +[[Repls]] +Old = " cicd/[A-Za-z0-9.-]+" +New = "" diff --git a/acceptance/auth/pat/test.toml b/acceptance/auth/pat/test.toml index 9dae1dca7..89438f43a 100644 --- a/acceptance/auth/pat/test.toml +++ b/acceptance/auth/pat/test.toml @@ -1,4 +1,20 @@ LocalOnly = true RecordRequests = true -IncludeReqHeaders = ["Authorization", "User-Agent"] +IncludeRequestHeaders = ["Authorization", "User-Agent"] + +[[Repls]] +Old = '(linux|darwin|windows)' +New = '[OS]' + +[[Repls]] +Old = " upstream/[A-Za-z0-9.-]+" +New = "" + +[[Repls]] +Old = " upstream-version/[A-Za-z0-9.-]+" +New = "" + +[[Repls]] +Old = " cicd/[A-Za-z0-9.-]+" +New = "" diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 5e3efe1c5..03db53aa3 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -61,11 +61,21 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) { headers[k] = v[0] } + var reqBody any + if json.Valid(body) { + // If the request body is a valid JSON, typecast it to json.RawMessage. + // This way json.Marshal will ignore the body and serialize it + // as is, which is what we want because the body is already a JSON. + reqBody = json.RawMessage(body) + } else { + reqBody = body + } + s.Requests = append(s.Requests, Request{ Headers: headers, Method: r.Method, Path: r.URL.Path, - Body: json.RawMessage(body), + Body: reqBody, }) } From 8399f0a8caa1ff2ba32d46965b79de36d27c9539 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 15:03:49 +0100 Subject: [PATCH 13/19] - --- acceptance/acceptance_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/acceptance/acceptance_test.go b/acceptance/acceptance_test.go index 7126ccb83..f205217ff 100644 --- a/acceptance/acceptance_test.go +++ b/acceptance/acceptance_test.go @@ -35,7 +35,7 @@ var ( // In order to debug CLI running under acceptance test, set this to full subtest name, e.g. "bundle/variables/empty" // Then install your breakpoints and click "debug test" near TestAccept in VSCODE. // example: var SingleTest = "bundle/variables/empty" -var SingleTest = "auth/basic" +var SingleTest = "" // If enabled, instead of compiling and running CLI externally, we'll start in-process server that accepts and runs // CLI commands. The $CLI in test scripts is a helper that just forwards command-line arguments to this server (see bin/callserver.py). From ffa8e6b01ca243c0e9b50b7c81d32cec6d52e218 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 15:05:49 +0100 Subject: [PATCH 14/19] - --- acceptance/auth/oauth/out.requests.txt | 6 +++--- acceptance/auth/pat/out.requests.txt | 2 +- libs/testserver/server.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/oauth/out.requests.txt index 41d09042e..2234d54b8 100644 --- a/acceptance/auth/oauth/out.requests.txt +++ b/acceptance/auth/oauth/out.requests.txt @@ -1,3 +1,3 @@ -{"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"body":""} -{"method":"POST","path":"/oidc/v1/token","headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"body":"grant_type=client_credentials\u0026scope=all-apis"} -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"body":""} +{"headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","body":""} +{"headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"POST","path":"/oidc/v1/token","body":"Z3JhbnRfdHlwZT1jbGllbnRfY3JlZGVudGlhbHMmc2NvcGU9YWxsLWFwaXM="} +{"headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/acceptance/auth/pat/out.requests.txt b/acceptance/auth/pat/out.requests.txt index 694f2e8e2..cb1a8d4dd 100644 --- a/acceptance/auth/pat/out.requests.txt +++ b/acceptance/auth/pat/out.requests.txt @@ -1 +1 @@ -{"method":"GET","path":"/api/2.0/preview/scim/v2/Me","headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"body":""} +{"headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 03db53aa3..067cfddd8 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -28,7 +28,7 @@ type Request struct { Headers map[string]string `json:"headers,omitempty"` Method string `json:"method"` Path string `json:"path"` - Body any `json:"body"` + Body any `json:"body,omitempty"` } func New(t testutil.TestingT) *Server { From f9c450591c2c56c6ac51057ccc85f9fba76b64b1 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 15:06:38 +0100 Subject: [PATCH 15/19] - --- libs/testserver/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 067cfddd8..03db53aa3 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -28,7 +28,7 @@ type Request struct { Headers map[string]string `json:"headers,omitempty"` Method string `json:"method"` Path string `json:"path"` - Body any `json:"body,omitempty"` + Body any `json:"body"` } func New(t testutil.TestingT) *Server { From 45ea71c442195633633a3235604d871f0a94597e Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Wed, 5 Feb 2025 15:11:55 +0100 Subject: [PATCH 16/19] - --- acceptance/auth/oauth/out.requests.txt | 2 +- libs/testserver/server.go | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/oauth/out.requests.txt index 2234d54b8..25e0fbf3a 100644 --- a/acceptance/auth/oauth/out.requests.txt +++ b/acceptance/auth/oauth/out.requests.txt @@ -1,3 +1,3 @@ {"headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","body":""} -{"headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"POST","path":"/oidc/v1/token","body":"Z3JhbnRfdHlwZT1jbGllbnRfY3JlZGVudGlhbHMmc2NvcGU9YWxsLWFwaXM="} +{"headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"POST","path":"/oidc/v1/token","body":"grant_type=client_credentials\u0026scope=all-apis"} {"headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/libs/testserver/server.go b/libs/testserver/server.go index 03db53aa3..42fd5fde3 100644 --- a/libs/testserver/server.go +++ b/libs/testserver/server.go @@ -68,7 +68,9 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) { // as is, which is what we want because the body is already a JSON. reqBody = json.RawMessage(body) } else { - reqBody = body + // JSON marshal encodes []byte to base64. Typecase it to string + // to avoid this. + reqBody = string(body) } s.Requests = append(s.Requests, Request{ From 44ed605a403520e6f98d7c2c89bfd29b3c1bd5d4 Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 10 Feb 2025 13:32:32 +0100 Subject: [PATCH 17/19] update main --- acceptance/auth/basic/out.requests.txt | 2 +- acceptance/auth/oauth/out.requests.txt | 6 +++--- acceptance/auth/pat/out.requests.txt | 2 +- acceptance/server_test.go | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/acceptance/auth/basic/out.requests.txt b/acceptance/auth/basic/out.requests.txt index 0d005d5e6..abeefabb2 100644 --- a/acceptance/auth/basic/out.requests.txt +++ b/acceptance/auth/basic/out.requests.txt @@ -1 +1 @@ -{"headers":{"Authorization":"Basic dXNlcm5hbWU6cGFzc3dvcmQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} +{"headers":{"Authorization":["Basic dXNlcm5hbWU6cGFzc3dvcmQ="],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"]},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/oauth/out.requests.txt index 25e0fbf3a..b090b4ef2 100644 --- a/acceptance/auth/oauth/out.requests.txt +++ b/acceptance/auth/oauth/out.requests.txt @@ -1,3 +1,3 @@ -{"headers":{"User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","body":""} -{"headers":{"Authorization":"Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"},"method":"POST","path":"/oidc/v1/token","body":"grant_type=client_credentials\u0026scope=all-apis"} -{"headers":{"Authorization":"Bearer oauth-token","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} +{"headers":{"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"]},"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","body":""} +{"headers":{"Authorization":["Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"]},"method":"POST","path":"/oidc/v1/token","body":"grant_type=client_credentials\u0026scope=all-apis"} +{"headers":{"Authorization":["Bearer oauth-token"],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"]},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/acceptance/auth/pat/out.requests.txt b/acceptance/auth/pat/out.requests.txt index cb1a8d4dd..3268cf813 100644 --- a/acceptance/auth/pat/out.requests.txt +++ b/acceptance/auth/pat/out.requests.txt @@ -1 +1 @@ -{"headers":{"Authorization":"Bearer dapi1234","User-Agent":"cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} +{"headers":{"Authorization":["Bearer dapi1234"],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"]},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} diff --git a/acceptance/server_test.go b/acceptance/server_test.go index 556a4a1d8..19d46d1e6 100644 --- a/acceptance/server_test.go +++ b/acceptance/server_test.go @@ -162,14 +162,14 @@ func AddHandlers(server *testserver.Server) { return fakeWorkspace.JobsList() }) - server.Handle("GET /oidc/.well-known/oauth-authorization-server", func(r *http.Request) (any, int) { + server.Handle("GET /oidc/.well-known/oauth-authorization-server", func(fakeWorkspace *testserver.FakeWorkspace, r *http.Request) (any, int) { return map[string]string{ "authorization_endpoint": server.URL + "oidc/v1/authorize", "token_endpoint": server.URL + "/oidc/v1/token", }, http.StatusOK }) - server.Handle("POST /oidc/v1/token", func(r *http.Request) (any, int) { + server.Handle("POST /oidc/v1/token", func(fakeWorkspace *testserver.FakeWorkspace, r *http.Request) (any, int) { return map[string]string{ "access_token": "oauth-token", "expires_in": "3600", From c0666e511546c2d238aa7df926b00dbd4e82a0fd Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 10 Feb 2025 14:36:08 +0100 Subject: [PATCH 18/19] address comments --- .../{ => credentials}/basic/out.requests.txt | 0 .../auth/{ => credentials}/basic/output.txt | 0 .../auth/{ => credentials}/basic/script | 1 + .../{ => credentials}/oauth/out.requests.txt | 0 .../auth/{ => credentials}/oauth/output.txt | 0 .../auth/{ => credentials}/oauth/script | 2 ++ .../{ => credentials}/pat/out.requests.txt | 0 .../auth/{ => credentials}/pat/output.txt | 0 acceptance/auth/{ => credentials}/pat/script | 0 .../auth/{basic => credentials}/test.toml | 0 acceptance/auth/oauth/test.toml | 20 ------------------- acceptance/auth/pat/test.toml | 20 ------------------- 12 files changed, 3 insertions(+), 40 deletions(-) rename acceptance/auth/{ => credentials}/basic/out.requests.txt (100%) rename acceptance/auth/{ => credentials}/basic/output.txt (100%) rename acceptance/auth/{ => credentials}/basic/script (64%) rename acceptance/auth/{ => credentials}/oauth/out.requests.txt (100%) rename acceptance/auth/{ => credentials}/oauth/output.txt (100%) rename acceptance/auth/{ => credentials}/oauth/script (63%) rename acceptance/auth/{ => credentials}/pat/out.requests.txt (100%) rename acceptance/auth/{ => credentials}/pat/output.txt (100%) rename acceptance/auth/{ => credentials}/pat/script (100%) rename acceptance/auth/{basic => credentials}/test.toml (100%) delete mode 100644 acceptance/auth/oauth/test.toml delete mode 100644 acceptance/auth/pat/test.toml diff --git a/acceptance/auth/basic/out.requests.txt b/acceptance/auth/credentials/basic/out.requests.txt similarity index 100% rename from acceptance/auth/basic/out.requests.txt rename to acceptance/auth/credentials/basic/out.requests.txt diff --git a/acceptance/auth/basic/output.txt b/acceptance/auth/credentials/basic/output.txt similarity index 100% rename from acceptance/auth/basic/output.txt rename to acceptance/auth/credentials/basic/output.txt diff --git a/acceptance/auth/basic/script b/acceptance/auth/credentials/basic/script similarity index 64% rename from acceptance/auth/basic/script rename to acceptance/auth/credentials/basic/script index aae249083..9c10eca0b 100644 --- a/acceptance/auth/basic/script +++ b/acceptance/auth/credentials/basic/script @@ -2,6 +2,7 @@ # in acceptance tests export DATABRICKS_TOKEN="" +# "username:password" in base64 is dXNlcm5hbWU6cGFzc3dvcmQ=, expect to see this in Authorization header export DATABRICKS_USERNAME=username export DATABRICKS_PASSWORD=password diff --git a/acceptance/auth/oauth/out.requests.txt b/acceptance/auth/credentials/oauth/out.requests.txt similarity index 100% rename from acceptance/auth/oauth/out.requests.txt rename to acceptance/auth/credentials/oauth/out.requests.txt diff --git a/acceptance/auth/oauth/output.txt b/acceptance/auth/credentials/oauth/output.txt similarity index 100% rename from acceptance/auth/oauth/output.txt rename to acceptance/auth/credentials/oauth/output.txt diff --git a/acceptance/auth/oauth/script b/acceptance/auth/credentials/oauth/script similarity index 63% rename from acceptance/auth/oauth/script rename to acceptance/auth/credentials/oauth/script index e4519e41b..4abab8af7 100644 --- a/acceptance/auth/oauth/script +++ b/acceptance/auth/credentials/oauth/script @@ -2,6 +2,8 @@ # in acceptance tests export DATABRICKS_TOKEN="" +# "client_id:client_secret" in base64 is Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=, expect to +# see this in Authorization header export DATABRICKS_CLIENT_ID=client_id export DATABRICKS_CLIENT_SECRET=client_secret diff --git a/acceptance/auth/pat/out.requests.txt b/acceptance/auth/credentials/pat/out.requests.txt similarity index 100% rename from acceptance/auth/pat/out.requests.txt rename to acceptance/auth/credentials/pat/out.requests.txt diff --git a/acceptance/auth/pat/output.txt b/acceptance/auth/credentials/pat/output.txt similarity index 100% rename from acceptance/auth/pat/output.txt rename to acceptance/auth/credentials/pat/output.txt diff --git a/acceptance/auth/pat/script b/acceptance/auth/credentials/pat/script similarity index 100% rename from acceptance/auth/pat/script rename to acceptance/auth/credentials/pat/script diff --git a/acceptance/auth/basic/test.toml b/acceptance/auth/credentials/test.toml similarity index 100% rename from acceptance/auth/basic/test.toml rename to acceptance/auth/credentials/test.toml diff --git a/acceptance/auth/oauth/test.toml b/acceptance/auth/oauth/test.toml deleted file mode 100644 index 89438f43a..000000000 --- a/acceptance/auth/oauth/test.toml +++ /dev/null @@ -1,20 +0,0 @@ -LocalOnly = true - -RecordRequests = true -IncludeRequestHeaders = ["Authorization", "User-Agent"] - -[[Repls]] -Old = '(linux|darwin|windows)' -New = '[OS]' - -[[Repls]] -Old = " upstream/[A-Za-z0-9.-]+" -New = "" - -[[Repls]] -Old = " upstream-version/[A-Za-z0-9.-]+" -New = "" - -[[Repls]] -Old = " cicd/[A-Za-z0-9.-]+" -New = "" diff --git a/acceptance/auth/pat/test.toml b/acceptance/auth/pat/test.toml deleted file mode 100644 index 89438f43a..000000000 --- a/acceptance/auth/pat/test.toml +++ /dev/null @@ -1,20 +0,0 @@ -LocalOnly = true - -RecordRequests = true -IncludeRequestHeaders = ["Authorization", "User-Agent"] - -[[Repls]] -Old = '(linux|darwin|windows)' -New = '[OS]' - -[[Repls]] -Old = " upstream/[A-Za-z0-9.-]+" -New = "" - -[[Repls]] -Old = " upstream-version/[A-Za-z0-9.-]+" -New = "" - -[[Repls]] -Old = " cicd/[A-Za-z0-9.-]+" -New = "" From 48f3bfb00820cb6e1ece2a684cf69a2f2a4aea8c Mon Sep 17 00:00:00 2001 From: Shreyas Goenka Date: Mon, 10 Feb 2025 14:36:52 +0100 Subject: [PATCH 19/19] pretty --- .../auth/credentials/basic/out.requests.txt | 14 ++++++- .../auth/credentials/oauth/out.requests.txt | 39 +++++++++++++++++-- .../auth/credentials/pat/out.requests.txt | 14 ++++++- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/acceptance/auth/credentials/basic/out.requests.txt b/acceptance/auth/credentials/basic/out.requests.txt index abeefabb2..a21456504 100644 --- a/acceptance/auth/credentials/basic/out.requests.txt +++ b/acceptance/auth/credentials/basic/out.requests.txt @@ -1 +1,13 @@ -{"headers":{"Authorization":["Basic dXNlcm5hbWU6cGFzc3dvcmQ="],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic"]},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} +{ + "headers": { + "Authorization": [ + "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" + ], + "User-Agent": [ + "cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/basic" + ] + }, + "method": "GET", + "path": "/api/2.0/preview/scim/v2/Me", + "body": "" +} diff --git a/acceptance/auth/credentials/oauth/out.requests.txt b/acceptance/auth/credentials/oauth/out.requests.txt index b090b4ef2..235aca082 100644 --- a/acceptance/auth/credentials/oauth/out.requests.txt +++ b/acceptance/auth/credentials/oauth/out.requests.txt @@ -1,3 +1,36 @@ -{"headers":{"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"]},"method":"GET","path":"/oidc/.well-known/oauth-authorization-server","body":""} -{"headers":{"Authorization":["Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]"]},"method":"POST","path":"/oidc/v1/token","body":"grant_type=client_credentials\u0026scope=all-apis"} -{"headers":{"Authorization":["Bearer oauth-token"],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m"]},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} +{ + "headers": { + "User-Agent": [ + "cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]" + ] + }, + "method": "GET", + "path": "/oidc/.well-known/oauth-authorization-server", + "body": "" +} +{ + "headers": { + "Authorization": [ + "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ=" + ], + "User-Agent": [ + "cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS]" + ] + }, + "method": "POST", + "path": "/oidc/v1/token", + "body": "grant_type=client_credentials\u0026scope=all-apis" +} +{ + "headers": { + "Authorization": [ + "Bearer oauth-token" + ], + "User-Agent": [ + "cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/oauth-m2m" + ] + }, + "method": "GET", + "path": "/api/2.0/preview/scim/v2/Me", + "body": "" +} diff --git a/acceptance/auth/credentials/pat/out.requests.txt b/acceptance/auth/credentials/pat/out.requests.txt index 3268cf813..ca3780184 100644 --- a/acceptance/auth/credentials/pat/out.requests.txt +++ b/acceptance/auth/credentials/pat/out.requests.txt @@ -1 +1,13 @@ -{"headers":{"Authorization":["Bearer dapi1234"],"User-Agent":["cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat"]},"method":"GET","path":"/api/2.0/preview/scim/v2/Me","body":""} +{ + "headers": { + "Authorization": [ + "Bearer dapi1234" + ], + "User-Agent": [ + "cli/[DEV_VERSION] databricks-sdk-go/[SDK_VERSION] go/[GO_VERSION] os/[OS] cmd/current-user_me cmd-exec-id/[UUID] auth/pat" + ] + }, + "method": "GET", + "path": "/api/2.0/preview/scim/v2/Me", + "body": "" +}