/
attacks_fetch.go
50 lines (43 loc) · 1.21 KB
/
attacks_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
package shield
import (
"context"
"time"
"github.com/OpsHelmInc/cloudquery/client"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/shield"
"github.com/aws/aws-sdk-go-v2/service/shield/types"
"github.com/cloudquery/plugin-sdk/schema"
)
func fetchShieldAttacks(ctx context.Context, meta schema.ClientMeta, parent *schema.Resource, res chan<- any) error {
c := meta.(*client.Client)
svc := c.Services().Shield
end := time.Now()
start := end.Add(-time.Hour * 24)
config := shield.ListAttacksInput{
EndTime: &types.TimeRange{ToExclusive: &end},
StartTime: &types.TimeRange{FromInclusive: &start},
}
for {
output, err := svc.ListAttacks(ctx, &config)
if err != nil {
return err
}
res <- output.AttackSummaries
if aws.ToString(output.NextToken) == "" {
break
}
config.NextToken = output.NextToken
}
return nil
}
func getAttack(ctx context.Context, meta schema.ClientMeta, resource *schema.Resource) error {
c := meta.(*client.Client)
svc := c.Services().Shield
a := resource.Item.(types.AttackSummary)
attack, err := svc.DescribeAttack(ctx, &shield.DescribeAttackInput{AttackId: a.AttackId})
if err != nil {
return err
}
resource.Item = attack.Attack
return nil
}