Compare commits

...

25 Commits

Author SHA1 Message Date
shreyas-goenka b8af03523b
Merge 48f3bfb008 into e81ec4ee23 2025-02-10 23:30:29 +05:30
Shreyas Goenka 48f3bfb008
pretty 2025-02-10 14:36:52 +01:00
Shreyas Goenka 2d449c3725
Merge remote-tracking branch 'origin' into auth-validate 2025-02-10 14:36:15 +01:00
Shreyas Goenka c0666e5115
address comments 2025-02-10 14:36:08 +01:00
Shreyas Goenka 7e141f5184
Merge remote-tracking branch 'origin' into auth-validate 2025-02-10 14:26:23 +01:00
Shreyas Goenka 44ed605a40
update main 2025-02-10 13:32:32 +01:00
Shreyas Goenka 440aafc0e5
Merge remote-tracking branch 'origin' into auth-validate 2025-02-10 13:28:55 +01:00
Shreyas Goenka 45ea71c442
- 2025-02-05 15:11:55 +01:00
Shreyas Goenka f9c450591c
- 2025-02-05 15:06:38 +01:00
Shreyas Goenka ffa8e6b01c
- 2025-02-05 15:05:49 +01:00
Shreyas Goenka 8399f0a8ca
- 2025-02-05 15:03:49 +01:00
Shreyas Goenka 61b2e22f5e
- 2025-02-05 15:03:27 +01:00
Shreyas Goenka 5a1f36e07d
- 2025-02-05 13:16:42 +01:00
Shreyas Goenka bbc23ad0f7
- 2025-02-05 13:14:10 +01:00
Shreyas Goenka 2253eb0590
merge 2025-02-05 13:13:14 +01:00
Shreyas Goenka 22fa6488fd
Merge remote-tracking branch 'origin' into auth-validate 2025-02-04 17:34:33 +01:00
Shreyas Goenka a40dc8cf3c
cleanup: 2025-02-03 20:05:30 +01:00
Shreyas Goenka 6fabd756f0
- 2025-02-03 20:01:06 +01:00
Shreyas Goenka eb8e9854d4
-gs 2025-02-03 20:01:01 +01:00
Shreyas Goenka b66bfb2c93
- 2025-02-03 19:50:16 +01:00
Shreyas Goenka b076b750f1
fix 2025-02-03 19:49:38 +01:00
Shreyas Goenka 5e9d63280a
- 2025-02-03 19:33:02 +01:00
Shreyas Goenka 9c0efb6212
- 2025-02-03 19:26:19 +01:00
Shreyas Goenka 6abfe52081
- 2025-02-03 19:25:15 +01:00
Shreyas Goenka a7e785d0e8
Add acceptance tests for auth resolution 2025-02-03 19:24:41 +01:00
12 changed files with 145 additions and 1 deletions

View File

@ -0,0 +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": ""
}

View File

@ -0,0 +1,4 @@
{
"id":"[USERID]",
"userName":"[USERNAME]"
}

View File

@ -0,0 +1,9 @@
# Unset the token which is configured by default
# 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
$CLI current-user me

View File

@ -0,0 +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": ""
}

View File

@ -0,0 +1,4 @@
{
"id":"[USERID]",
"userName":"[USERNAME]"
}

View File

@ -0,0 +1,10 @@
# Unset the token which is configured by default
# 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
$CLI current-user me

View File

@ -0,0 +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": ""
}

View File

@ -0,0 +1,4 @@
{
"id":"[USERID]",
"userName":"[USERNAME]"
}

View File

@ -0,0 +1,3 @@
export DATABRICKS_TOKEN=dapi1234
$CLI current-user me

View File

@ -0,0 +1,20 @@
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 = ""

View File

@ -161,6 +161,22 @@ func AddHandlers(server *testserver.Server) {
server.Handle("GET /api/2.1/jobs/list", func(fakeWorkspace *testserver.FakeWorkspace, r *http.Request) (any, int) {
return fakeWorkspace.JobsList()
})
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(fakeWorkspace *testserver.FakeWorkspace, r *http.Request) (any, int) {
return map[string]string{
"access_token": "oauth-token",
"expires_in": "3600",
"scope": "all-apis",
"token_type": "Bearer",
}, http.StatusOK
})
}
func internalError(err error) (any, int) {

View File

@ -119,11 +119,23 @@ func (s *Server) Handle(pattern string, handler HandlerFunc) {
}
}
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 {
// JSON marshal encodes []byte to base64. Typecase it to string
// to avoid this.
reqBody = string(body)
}
s.Requests = append(s.Requests, Request{
Headers: headers,
Method: r.Method,
Path: r.URL.Path,
Body: json.RawMessage(body),
Body: reqBody,
})
}