This repository has been archived by the owner on Dec 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
permissions.go
102 lines (96 loc) · 3.26 KB
/
permissions.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
package services
import (
"context"
datadog "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
"github.com/andrewthetechie/cq-provider-datadog/client"
"github.com/cloudquery/cq-provider-sdk/provider/diag"
"github.com/cloudquery/cq-provider-sdk/provider/schema"
)
//go:generate cq-gen --resource permissions --config resources/services/permissions.hcl --output .
func Permissions() *schema.Table {
return &schema.Table{
Name: "datadog_permissions",
Description: "Role Role object returned by the API.",
Multiplex: client.AccountMultiplex,
Resolver: fetchPermissions,
Options: schema.TableCreationOptions{PrimaryKeys: []string{"id"}},
Columns: []schema.Column{
{
Name: "account_name",
Description: "The name of this datadog account from your config.",
Type: schema.TypeString,
Resolver: client.ResolveAccountName,
},
{
Name: "attributes_created_at",
Description: "Creation time of the role.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("Attributes.CreatedAt"),
},
{
Name: "attributes_modified_at",
Description: "Time of last role modification.",
Type: schema.TypeTimestamp,
Resolver: schema.PathResolver("Attributes.ModifiedAt"),
},
{
Name: "attributes_name",
Description: "The name of the role",
Type: schema.TypeString,
Resolver: schema.PathResolver("Attributes.Name"),
},
{
Name: "attributes_user_count",
Description: "Number of users with that role.",
Type: schema.TypeBigInt,
Resolver: schema.PathResolver("Attributes.UserCount"),
},
{
Name: "attributes_additional_properties",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Attributes.AdditionalProperties"),
},
{
Name: "id",
Description: "The unique identifier of the role.",
Type: schema.TypeString,
},
{
Name: "relationships_permissions_additional_properties",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Relationships.Permissions.AdditionalProperties"),
},
{
Name: "relationships_additional_properties",
Type: schema.TypeJSON,
Resolver: schema.PathResolver("Relationships.AdditionalProperties"),
},
{
Name: "type",
Description: "Roles type.",
Type: schema.TypeString,
},
{
Name: "additional_properties",
Type: schema.TypeJSON,
},
},
}
}
// ====================================================================================================================
// Table Resolver Functions
// ====================================================================================================================
func fetchPermissions(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- interface{}) error {
c := meta.(*client.Client)
logger := c.Logger()
logger.Debug("in fetchHosts")
// TODO: multiplexing
apiClient := datadog.NewAPIClient(&c.MultiPlexedAccount.V2Config)
resp, r, err := apiClient.RolesApi.ListPermissions(c.MultiPlexedAccount.V2Context)
logger.Debug(r.Status)
if err != nil {
return diag.FromError(err, diag.ACCESS)
}
res <- resp.Data
return nil
}