-
Notifications
You must be signed in to change notification settings - Fork 504
/
provisions.go
54 lines (46 loc) · 1.33 KB
/
provisions.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
package organization
import (
"context"
"github.com/apache/arrow/go/v14/arrow"
"github.com/cloudquery/cloudquery/plugins/source/snyk/client"
"github.com/cloudquery/plugin-sdk/v4/schema"
"github.com/cloudquery/plugin-sdk/v4/transformers"
"github.com/pavel-snyk/snyk-sdk-go/snyk"
)
func pendingUserProvisions() *schema.Table {
return &schema.Table{
Name: "snyk_organization_provisions",
Description: `https://snyk.docs.apiary.io/#reference/organizations/provision-user/list-pending-user-provisions`,
Resolver: fetchPendingProvisions,
Multiplex: client.ByOrganization,
Transform: transformers.TransformWithStruct(&snyk.PendingProvision{},
transformers.WithPrimaryKeys("Email", "Created")),
Columns: []schema.Column{
{
Name: "organization_id",
Type: arrow.BinaryTypes.String,
PrimaryKey: true,
Resolver: schema.ParentColumnResolver("id"),
},
},
}
}
func fetchPendingProvisions(ctx context.Context, meta schema.ClientMeta, _ *schema.Resource, res chan<- any) error {
c := meta.(*client.Client)
opts := snyk.ListPendingUserProvisionsOptions{
Page: 1,
PerPage: 1000,
}
for {
result, _, err := c.Orgs.ListPendingUserProvisions(ctx, c.OrganizationID, opts)
if err != nil {
return err
}
if len(result) == 0 {
break
}
res <- result
opts.Page++
}
return nil
}