-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathcatalog.go
More file actions
74 lines (59 loc) · 1.81 KB
/
catalog.go
File metadata and controls
74 lines (59 loc) · 1.81 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package resources
import (
"context"
"net/url"
"strings"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/databricks/cli/libs/log"
)
type Catalog struct {
BaseResource
catalog.CreateCatalog
// Fields that can only be set via update, not during creation.
EnablePredictiveOptimization catalog.EnablePredictiveOptimization `json:"enable_predictive_optimization,omitempty"`
IsolationMode catalog.CatalogIsolationMode `json:"isolation_mode,omitempty"`
Owner string `json:"owner,omitempty"`
// List of grants to apply on this catalog.
Grants []catalog.PrivilegeAssignment `json:"grants,omitempty"`
}
func (c *Catalog) Exists(ctx context.Context, w *databricks.WorkspaceClient, name string) (bool, error) {
_, err := w.Catalogs.GetByName(ctx, name)
if err != nil {
log.Debugf(ctx, "catalog with name %s does not exist: %v", name, err)
if apierr.IsMissing(err) {
return false, nil
}
return false, err
}
return true, nil
}
func (*Catalog) ResourceDescription() ResourceDescription {
return ResourceDescription{
SingularName: "catalog",
PluralName: "catalogs",
SingularTitle: "Catalog",
PluralTitle: "Catalogs",
}
}
func (c *Catalog) InitializeURL(baseURL url.URL) {
if c.ID == "" {
return
}
baseURL.Path = "explore/data/" + strings.ReplaceAll(c.ID, ".", "/")
c.URL = baseURL.String()
}
func (c *Catalog) GetURL() string {
return c.URL
}
func (c *Catalog) GetName() string {
return c.Name
}
func (c *Catalog) UnmarshalJSON(b []byte) error {
return marshal.Unmarshal(b, c)
}
func (c Catalog) MarshalJSON() ([]byte, error) {
return marshal.Marshal(c)
}