-
Notifications
You must be signed in to change notification settings - Fork 0
/
distributions_fetch.go
63 lines (58 loc) · 1.79 KB
/
distributions_fetch.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
package lightsail
import (
"context"
"github.com/OpsHelmInc/cloudquery/client"
"github.com/OpsHelmInc/cloudquery/resources/services/lightsail/models"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/lightsail"
"github.com/aws/aws-sdk-go-v2/service/lightsail/types"
"github.com/cloudquery/plugin-sdk/schema"
"golang.org/x/sync/errgroup"
)
func fetchLightsailDistributions(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
var input lightsail.GetDistributionsInput
c := meta.(*client.Client)
svc := c.Services().Lightsail
for {
response, err := svc.GetDistributions(ctx, &input, func(options *lightsail.Options) {
// Set region to default global region
options.Region = "us-east-1"
})
if err != nil {
return err
}
errs, ctx := errgroup.WithContext(ctx)
errs.SetLimit(MaxGoroutines)
for _, d := range response.Distributions {
func(d types.LightsailDistribution) {
errs.Go(func() error {
return fetchCacheReset(ctx, res, c, d)
})
}(d)
}
err = errs.Wait()
if err != nil {
return err
}
if aws.ToString(response.NextPageToken) == "" {
break
}
input.PageToken = response.NextPageToken
}
return nil
}
func fetchCacheReset(ctx context.Context, res chan<- any, c *client.Client, d types.LightsailDistribution) error {
svc := c.Services().Lightsail
resetInput := lightsail.GetDistributionLatestCacheResetInput{
DistributionName: d.Name,
}
resetResp, err := svc.GetDistributionLatestCacheReset(ctx, &resetInput, func(options *lightsail.Options) {
// Set region to default global region
options.Region = "us-east-1"
})
if err != nil && !c.IsNotFoundError(err) {
return err
}
res <- models.DistributionWrapper{LightsailDistribution: &d, LatestCacheReset: resetResp}
return nil
}