-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathworkspace_functions.go
More file actions
35 lines (32 loc) · 1.14 KB
/
workspace_functions.go
File metadata and controls
35 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package databricks
import (
"context"
"strconv"
"github.com/databricks/databricks-sdk-go/httpclient"
)
// CurrentWorkspaceID returns the workspace ID of the workspace that this client is
// connected to.
//
// The ID is fetched from the X-Databricks-Org-Id response header on
// /api/2.0/preview/scim/v2/Me. On unified (SPOG) hosts, Config.WorkspaceID is
// sent in the X-Databricks-Org-Id request header to route the call to the
// correct workspace; on unified hosts with no WorkspaceID set, the request has
// no routing information and will fail.
func (w *WorkspaceClient) CurrentWorkspaceID(ctx context.Context) (int64, error) {
var workspaceIdStr string
opts := []httpclient.DoOption{
httpclient.WithResponseHeader("X-Databricks-Org-Id", &workspaceIdStr),
}
if w.Config != nil && w.Config.WorkspaceID != "" {
opts = append(opts, httpclient.WithRequestHeader("X-Databricks-Org-Id", w.Config.WorkspaceID))
}
err := w.apiClient.Do(ctx, "GET", "/api/2.0/preview/scim/v2/Me", opts...)
if err != nil {
return 0, err
}
workspaceId, err := strconv.ParseInt(workspaceIdStr, 10, 64)
if err != nil {
return 0, err
}
return workspaceId, nil
}