-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathvolume.go
More file actions
100 lines (79 loc) · 2.35 KB
/
volume.go
File metadata and controls
100 lines (79 loc) · 2.35 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package resources
import (
"context"
"net/url"
"strings"
"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/cli/libs/log"
"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/marshal"
"github.com/databricks/databricks-sdk-go/service/catalog"
)
type VolumeGrantPrivilege string
const (
VolumeGrantPrivilegeAllPrivileges VolumeGrantPrivilege = "ALL_PRIVILEGES"
VolumeGrantPrivilegeApplyTag VolumeGrantPrivilege = "APPLY_TAG"
VolumeGrantPrivilegeManage VolumeGrantPrivilege = "MANAGE"
VolumeGrantPrivilegeReadVolume VolumeGrantPrivilege = "READ_VOLUME"
VolumeGrantPrivilegeWriteVolume VolumeGrantPrivilege = "WRITE_VOLUME"
)
// Values returns all valid VolumeGrantPrivilege values
func (VolumeGrantPrivilege) Values() []VolumeGrantPrivilege {
return []VolumeGrantPrivilege{
VolumeGrantPrivilegeAllPrivileges,
VolumeGrantPrivilegeApplyTag,
VolumeGrantPrivilegeManage,
VolumeGrantPrivilegeReadVolume,
VolumeGrantPrivilegeWriteVolume,
}
}
type VolumeGrant struct {
Privileges []VolumeGrantPrivilege `json:"privileges"`
Principal string `json:"principal"`
}
type Volume struct {
BaseResource
// List of grants to apply on this volume.
Grants []VolumeGrant `json:"grants,omitempty"`
catalog.CreateVolumeRequestContent
}
func (v *Volume) UnmarshalJSON(b []byte) error {
return marshal.Unmarshal(b, v)
}
func (v Volume) MarshalJSON() ([]byte, error) {
return marshal.Marshal(v)
}
func (v *Volume) Exists(ctx context.Context, w *databricks.WorkspaceClient, fullyQualifiedName string) (bool, error) {
_, err := w.Volumes.Read(ctx, catalog.ReadVolumeRequest{
Name: fullyQualifiedName,
})
if err != nil {
log.Debugf(ctx, "volume with fully qualified name %s does not exist: %v", fullyQualifiedName, err)
if apierr.IsMissing(err) {
return false, nil
}
return false, err
}
return true, nil
}
func (*Volume) ResourceDescription() ResourceDescription {
return ResourceDescription{
SingularName: "volume",
PluralName: "volumes",
SingularTitle: "Volume",
PluralTitle: "Volumes",
}
}
func (v *Volume) InitializeURL(baseURL url.URL) {
if v.ID == "" {
return
}
baseURL.Path = "explore/data/volumes/" + strings.ReplaceAll(v.ID, ".", "/")
v.URL = baseURL.String()
}
func (v *Volume) GetURL() string {
return v.URL
}
func (v *Volume) GetName() string {
return v.Name
}