-
Notifications
You must be signed in to change notification settings - Fork 2
/
table_databricks_iam_account_user.go
192 lines (169 loc) · 4.74 KB
/
table_databricks_iam_account_user.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
package databricks
import (
"context"
"github.com/databricks/databricks-sdk-go/service/iam"
"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 tableDatabricksIAMAccountUser(_ context.Context) *plugin.Table {
return &plugin.Table{
Name: "databricks_iam_account_user",
Description: "List details for all the users associated with a Databricks account.",
List: &plugin.ListConfig{
KeyColumns: []*plugin.KeyColumn{
{
Name: "id",
Require: plugin.Optional,
Operators: []string{"=", "<>"},
},
{
Name: "user_name",
Require: plugin.Optional,
Operators: []string{"=", "<>"},
},
{
Name: "display_name",
Require: plugin.Optional,
Operators: []string{"=", "<>"},
},
},
Hydrate: listIAMAccountUsers,
},
Get: &plugin.GetConfig{
KeyColumns: plugin.SingleColumn("id"),
ShouldIgnoreError: isNotFoundError([]string{"SCIM_404"}),
Hydrate: getIAMAccountUser,
},
Columns: databricksAccountColumns([]*plugin.Column{
{
Name: "id",
Description: "Databricks user ID.",
Type: proto.ColumnType_STRING,
},
{
Name: "user_name",
Description: "Email address of the Databricks user.",
Type: proto.ColumnType_STRING,
},
{
Name: "active",
Description: "Whether the user is active.",
Type: proto.ColumnType_BOOL,
},
{
Name: "display_name",
Description: "String that represents a concatenation of given and family names.",
Type: proto.ColumnType_STRING,
},
{
Name: "external_id",
Description: "External ID of the user.",
Type: proto.ColumnType_STRING,
},
// JSON fields
{
Name: "emails",
Description: "All the emails associated with the Databricks user.",
Type: proto.ColumnType_JSON,
},
{
Name: "entitlements",
Description: "All the entitlements associated with the Databricks user.",
Type: proto.ColumnType_JSON,
},
{
Name: "groups",
Description: "All the groups the user belongs to.",
Type: proto.ColumnType_JSON,
},
{
Name: "name",
Description: "Name of the user.",
Type: proto.ColumnType_JSON,
},
{
Name: "roles",
Description: "All the roles associated with the Databricks user.",
Type: proto.ColumnType_JSON,
},
// Standard Steampipe columns
{
Name: "title",
Description: "The title of the resource.",
Type: proto.ColumnType_STRING,
Transform: transform.FromField("DisplayName"),
},
}),
}
}
//// LIST FUNCTION
func listIAMAccountUsers(ctx context.Context, d *plugin.QueryData, h *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
// Limiting the results
maxLimit := int32(10000)
if d.QueryContext.Limit != nil {
limit := int32(*d.QueryContext.Limit)
if limit < maxLimit {
maxLimit = limit
}
}
// Create client
client, err := getAccountClient(ctx, d)
if err != nil {
logger.Error("databricks_iam_account_user.listIAMAccountUsers", "connection_error", err)
return nil, err
}
filterQuals := []filterQualMap{
{"id", "id", "string"},
{"user_name", "userName", "string"},
{"display_name", "displayName", "string"},
}
filter := buildQueryFilterFromQuals(filterQuals, d.Quals)
request := iam.ListAccountUsersRequest{
Count: int(maxLimit),
StartIndex: 1,
Filter: filter,
}
for {
users, err := client.Users.ListAll(ctx, request)
if err != nil {
logger.Error("databricks_iam_account_user.listIAMAccountUsers", "api_error", err)
return nil, err
}
for _, item := range users {
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
}
}
if len(users) < request.Count {
return nil, nil
} else {
request.StartIndex = request.StartIndex + request.Count
}
}
}
//// HYDRATE FUNCTIONS
func getIAMAccountUser(ctx context.Context, d *plugin.QueryData, _ *plugin.HydrateData) (interface{}, error) {
logger := plugin.Logger(ctx)
id := d.EqualsQualString("id")
// Return nil, if no input provided
if id == "" {
return nil, nil
}
// Create client
client, err := getAccountClient(ctx, d)
if err != nil {
logger.Error("databricks_iam_account_user.getIAMAccountUser", "connection_error", err)
return nil, err
}
user, err := client.Users.GetById(ctx, id)
if err != nil {
logger.Error("databricks_iam_account_user.getIAMAccountUser", "api_error", err)
return nil, err
}
return *user, nil
}