func()

in internal/inventory/awsfetcher/fetcher_iam_user.go [50:93]


func (i *iamUserFetcher) Fetch(ctx context.Context, assetChannel chan<- inventory.AssetEvent) {
	i.logger.Info("Fetching IAM Users")
	defer i.logger.Info("Fetching IAM Users - Finished")

	users, err := i.provider.GetUsers(ctx)
	if err != nil {
		i.logger.Errorf("Could not list users: %v", err)
		if len(users) == 0 {
			return
		}
	}

	for _, resource := range users {
		if resource == nil {
			continue
		}

		user, ok := resource.(iam.User)
		if !ok {
			i.logger.Errorf("Could not get info about user: %s", resource.GetResourceArn())
			continue
		}

		assetChannel <- inventory.NewAssetEvent(
			inventory.AssetClassificationAwsIamUser,
			user.GetResourceArn(),
			user.GetResourceName(),

			inventory.WithRelatedAssetIds([]string{user.UserId}),
			inventory.WithRawAsset(user),
			inventory.WithCloud(inventory.Cloud{
				Provider:    inventory.AwsCloudProvider,
				Region:      user.GetRegion(),
				AccountID:   i.AccountId,
				AccountName: i.AccountName,
				ServiceName: "AWS IAM",
			}),
			inventory.WithUser(inventory.User{
				ID:   user.GetResourceArn(),
				Name: user.GetResourceName(),
			}),
		)
	}
}