in internal/resources/fetching/preset/aws_org_preset.go [70:139]
func newCisAwsOrganizationFetchers(
ctx context.Context,
log *clog.Logger,
rootCh chan fetching.ResourceInfo,
accounts []AwsAccount,
cache map[string]registry.FetchersMap,
factory awsFactory,
) map[string]registry.FetchersMap {
seen := make(map[string]bool)
for key := range cache {
seen[key] = false
}
m := make(map[string]registry.FetchersMap)
for _, account := range accounts {
if existing := cache[account.Account]; existing != nil {
m[account.Account] = existing
seen[account.Account] = true
continue
}
ch := make(chan fetching.ResourceInfo)
go func(identity cloud.Identity) {
for {
select {
case <-ctx.Done():
return
case resourceInfo, ok := <-ch:
if !ok {
return
}
wrappedResourceInfo := fetching.ResourceInfo{
Resource: &wrapResource{
wrapped: resourceInfo.Resource,
identity: identity,
},
CycleMetadata: resourceInfo.CycleMetadata,
}
select {
case <-ctx.Done():
return
case rootCh <- wrappedResourceInfo:
}
}
}
}(account.Identity)
f := factory(
ctx,
log.Named("aws").WithOptions(zap.Fields(zap.String("cloud.account.id", account.Identity.Account))),
account.Config,
ch,
&account.Identity,
)
m[account.Account] = f
if cache != nil {
cache[account.Account] = f
}
}
for key, v := range seen {
if !v {
delete(cache, key)
}
}
return m
}