-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_databricks_catalog_storage_credential.go
223 lines (199 loc) · 6.82 KB
/
table_databricks_catalog_storage_credential.go
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
package databricks
import (
"context"
"github.com/databricks/databricks-sdk-go/service/catalog"
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
//// TABLE DEFINITION
func tableDatabricksCatalogStorageCredential(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "databricks_catalog_storage_credential",
Description: "Gets an array of storage credentials.",
List: &plugin.ListConfig{
Hydrate: listCatalogStorageCredentials,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("name"),
Hydrate: getCatalogStorageCredential,
},
Columns: databricksAccountColumns([]*plugin.Column{
{
Name: "id",
Description: "Unique identifier of the credential.",
Type: proto.ColumnType_STRING,
},
{
Name: "name",
Description: "The credential name.",
Type: proto.ColumnType_STRING,
},
{
Name: "comment",
Description: "Comment associated with the credential.",
Type: proto.ColumnType_STRING,
},
{
Name: "created_at",
Description: "Time at which this credential was created.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromGo().Transform(transform.UnixMsToTimestamp),
},
{
Name: "created_by",
Description: "The user who created this credential.",
Type: proto.ColumnType_STRING,
},
{
Name: "metastore_id",
Description: "Unique identifier of parent metastore.",
Type: proto.ColumnType_STRING,
},
{
Name: "owner",
Description: "Owner of the schema.",
Type: proto.ColumnType_STRING,
},
{
Name: "read_only",
Description: "Whether the storage credential is only usable for read operations.",
Type: proto.ColumnType_BOOL,
},
{
Name: "updated_at",
Description: "Time at which this credential was last updated.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromGo().Transform(transform.UnixMsToTimestamp),
},
{
Name: "updated_by",
Description: "The user who last updated this credential.",
Type: proto.ColumnType_STRING,
},
{
Name: "used_for_managed_storage",
Description: "Whether this credential is the current metastore's root storage credential.",
Type: proto.ColumnType_BOOL,
},
// JSON fields
{
Name: "aws_iam_role",
Description: "The AWS IAM role configuration.",
Type: proto.ColumnType_JSON,
},
{
Name: "azure_managed_identity",
Description: "The Azure managed identity configuration.",
Type: proto.ColumnType_JSON,
},
{
Name: "azure_service_principal",
Description: "The Azure service principal configuration.",
Type: proto.ColumnType_JSON,
},
{
Name: "databricks_gcp_service_account",
Description: "The Databricks GCP service account configuration.",
Type: proto.ColumnType_JSON,
},
{
Name: "storage_credential_permissions",
Description: "The storage credential permissions.",
Type: proto.ColumnType_JSON,
Hydrate: getCatalogStorageCredentialPermissions,
Transform: transform.FromValue(),
},
{
Name: "storage_credential_effective_permissions",
Description: "The storage credential effective permissions.",
Type: proto.ColumnType_JSON,
Hydrate: getCatalogStorageCredentialEffectivePermissions,
Transform: transform.FromValue(),
},
// Standard Steampipe columns
{
Name: "title",
Description: "The title of the resource.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
}),
}
}
//// LIST FUNCTION
func listCatalogStorageCredentials(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
// Create client
client, err := getWorkspaceClient(ctx, d)
if err != nil {
logger.Error("databricks_catalog_storage_credential.listCatalogStorageCredentials", "connection_error", err)
return nil, err
}
creds, err := client.StorageCredentials.ListAll(ctx)
if err != nil {
logger.Error("databricks_catalog_storage_credential.listCatalogStorageCredentials", "api_error", err)
return nil, err
}
for _, item := range creds {
d.StreamListItem(ctx, item)
// Context can be cancelled due to manual cancellation or the limit has been hit
if d.RowsRemaining(ctx) == 0 {
return nil, nil
}
}
return nil, nil
}
//// HYDRATE FUNCTIONS
func getCatalogStorageCredential(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
name := d.EqualsQualString("name")
// Return nil, if no input provided
if name == "" {
return nil, nil
}
// Create client
client, err := getWorkspaceClient(ctx, d)
if err != nil {
logger.Error("databricks_catalog_storage_credential.getCatalogStorageCredential", "connection_error", err)
return nil, err
}
cred, err := client.StorageCredentials.GetByName(ctx, name)
if err != nil {
logger.Error("databricks_catalog_storage_credential.getCatalogStorageCredential", "api_error", err)
return nil, err
}
return cred, nil
}
func getCatalogStorageCredentialPermissions(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
name := h.Item.(catalog.StorageCredentialInfo).Name
// Create client
client, err := getWorkspaceClient(ctx, d)
if err != nil {
logger.Error("databricks_catalog_storage_credential.getCatalogStorageCredentialPermissions", "connection_error", err)
return nil, err
}
permission, err := client.Grants.GetBySecurableTypeAndFullName(ctx, catalog.SecurableTypeStorageCredential, name)
if err != nil {
logger.Error("databricks_catalog_storage_credential.getCatalogStorageCredentialPermissions", "api_error", err)
return nil, err
}
return permission.PrivilegeAssignments, nil
}
func getCatalogStorageCredentialEffectivePermissions(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
name := h.Item.(catalog.StorageCredentialInfo).Name
// Create client
client, err := getWorkspaceClient(ctx, d)
if err != nil {
logger.Error("databricks_catalog_storage_credential.getCatalogStorageCredentialEffectivePermissions", "connection_error", err)
return nil, err
}
permission, err := client.Grants.GetEffectiveBySecurableTypeAndFullName(ctx, catalog.SecurableTypeStorageCredential, name)
if err != nil {
logger.Error("databricks_catalog_storage_credential.getCatalogStorageCredentialEffectivePermissions", "api_error", err)
return nil, err
}
return permission.PrivilegeAssignments, nil
}