-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_databricks_compute_cluster_policy.go
145 lines (127 loc) · 4.27 KB
/
table_databricks_compute_cluster_policy.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
package databricks
import (
"context"
"github.com/databricks/databricks-sdk-go/service/compute"
"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 tableDatabricksComputeClusterPolicy(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "databricks_compute_cluster_policy",
Description: "Gets an array of cluster policies.",
List: &plugin.ListConfig{
Hydrate: listComputeClusterPolicies,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("policy_id"),
Hydrate: getComputeClusterPolicy,
},
Columns: databricksAccountColumns([]*plugin.Column{
{
Name: "policy_id",
Description: "Canonical unique identifier for the Cluster Policy.",
Type: proto.ColumnType_STRING,
},
{
Name: "name",
Description: "Cluster Policy name requested by the user.",
Type: proto.ColumnType_STRING,
},
{
Name: "created_at_timestamp",
Description: "The timestamp (in millisecond) when this Cluster Policy was created.",
Type: proto.ColumnType_TIMESTAMP,
Transform: transform.FromGo().Transform(transform.UnixMsToTimestamp),
},
{
Name: "creator_user_name",
Description: "Creator user name. The field won't be included if the user has already been deleted.",
Type: proto.ColumnType_STRING,
},
{
Name: "definition",
Description: "Policy definition document expressed in Databricks Cluster Policy Definition Language.",
Type: proto.ColumnType_JSON,
},
{
Name: "description",
Description: "Additional human-readable description of the cluster policy.",
Type: proto.ColumnType_STRING,
},
{
Name: "is_default",
Description: "If true, policy is a default policy created and managed by Databricks.",
Type: proto.ColumnType_BOOL,
},
{
Name: "max_clusters_per_user",
Description: "Max number of clusters per user that can be active using this policy. If not present, there is no max limit.",
Type: proto.ColumnType_INT,
},
{
Name: "policy_family_definition_overrides",
Description: "Policy definition JSON document expressed in Databricks Policy Definition Language.",
Type: proto.ColumnType_STRING,
},
{
Name: "policy_family_id",
Description: "ID of the policy family.",
Type: proto.ColumnType_STRING,
},
// Standard Steampipe columns
{
Name: "title",
Description: "The title of the resource.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("Name"),
},
}),
}
}
//// LIST FUNCTION
func listComputeClusterPolicies(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_compute_cluster_policy.listComputeClusterPolicies", "connection_error", err)
return nil, err
}
request := compute.ListClusterPoliciesRequest{}
policies, err := client.ClusterPolicies.ListAll(ctx, request)
if err != nil {
logger.Error("databricks_compute_cluster_policy.listComputeClusterPolicies", "api_error", err)
return nil, err
}
for _, item := range policies {
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 getComputeClusterPolicy(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
id := d.EqualsQualString("policy_id")
// Return nil, if no input provided
if id == "" {
return nil, nil
}
// Create client
client, err := getWorkspaceClient(ctx, d)
if err != nil {
logger.Error("databricks_compute_cluster_policy.getComputeClusterPolicy", "connection_error", err)
return nil, err
}
policy, err := client.ClusterPolicies.GetByPolicyId(ctx, id)
if err != nil {
logger.Error("databricks_compute_cluster_policy.getComputeClusterPolicy", "api_error", err)
return nil, err
}
return policy, nil
}