-
Notifications
You must be signed in to change notification settings - Fork 14
/
column.go
89 lines (75 loc) · 2.75 KB
/
column.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
package plugin
import (
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"
)
/*
Column defines a column of a table.
A column may be populated by a List or Get call. It may alternatively define its own [HydrateFunc] that makes an additional API call for each row.
A column may transform the data it receives using one or more [transform functions].
To define a column populated by a List or Get call:
func itemCols() []*plugin.Column {
return []*plugin.Column{
{Name: "id", Type: proto.ColumnType_INT, Description: "The item's unique id."},
}
}
To define a column populated by a HydrateFunc:
Columns: awsColumns([]*plugin.Column{
{
Name: "permissions_boundary_arn",
Description: "The ARN of the policy used to set the permissions boundary for the user.",
Type: proto.ColumnType_STRING,
Hydrate: getAwsIamUserData,
},
}
To define columns that transform the data:
Columns: awsColumns([]*plugin.Column{
{
Name: "mfa_enabled",
Description: "The MFA status of the user.",
Type: proto.ColumnType_BOOL,
Hydrate: getAwsIamUserMfaDevices,
Transform: transform.From(handleEmptyUserMfaStatus),
},
{
Name: "login_profile",
Description: "Contains the user name and password create date for a user.",
Type: proto.ColumnType_JSON,
Hydrate: getAwsIamUserLoginProfile,
Transform: transform.FromValue(),
},
...
}
Examples:
- [hackernews]
- [aws]
[transform functions]: https://steampipe.io/docs/develop/writing-plugins#transform-functions
[hackernews]: https://github.com/turbot/steampipe-plugin-hackernews/blob/d14efdd3f2630f0146e575fe07666eda4e126721/hackernews/item.go#L14
[aws]: https://github.com/turbot/steampipe-plugin-aws/blob/7d17ee78e56da592e0a4e82b90b557225d1a6c11/aws/table_aws_iam_user.go#L22
*/
type Column struct {
// column name
Name string
// column type
Type proto.ColumnType
// column description
Description string
// explicitly specify the function which populates this data
// - this is only needed if any of the default hydrate functions will NOT return this column
Hydrate HydrateFunc
// the default column value
Default interface{}
// a list of transforms to generate the column value
Transform *transform.ColumnTransforms
}
// QueryColumn is struct storing column name and resolved hydrate name
// this is used in the query data when the hydrate function has been resolved
type QueryColumn struct {
*Column
// the name of the hydrate function which will be used to populate this column
// - this may be a default hydrate function
hydrateName string
}
func NewQueryColumn(column *Column, hydrateName string) *QueryColumn {
return &QueryColumn{column, hydrateName}
}