mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-15 17:11:30 +00:00
refactor: move AWS filter utilities to foundation
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
package filterutil
|
||||
// Package filters provides AWS filter parsing, tag matching and wildcard
|
||||
// comparison primitives without owning any resource's filter semantics.
|
||||
package filters
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package filterutil
|
||||
package filters
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
@@ -28,7 +28,7 @@ var validCapacityReservationFilters = map[string]bool{
|
||||
}
|
||||
|
||||
// DescribeCapacityReservations fans out to every node, aggregates each daemon's
|
||||
// in-memory reservations, and applies the requested ids and filters. Account
|
||||
// in-memory reservations, and applies the requested ids and awsfilters. Account
|
||||
// scoping is enforced by the daemons (which key ListReservations on the caller's
|
||||
// account id from the request header).
|
||||
func DescribeCapacityReservations(ctx context.Context, input *ec2.DescribeCapacityReservationsInput, natsConn *nats.Conn, expectedNodes int, accountID string) (ec2.DescribeCapacityReservationsOutput, error) {
|
||||
@@ -37,7 +37,7 @@ func DescribeCapacityReservations(ctx context.Context, input *ec2.DescribeCapaci
|
||||
input = &ec2.DescribeCapacityReservationsInput{}
|
||||
}
|
||||
|
||||
filters, err := filterutil.ParseFilters(input.Filters, validCapacityReservationFilters)
|
||||
filters, err := awsfilters.ParseFilters(input.Filters, validCapacityReservationFilters)
|
||||
if err != nil {
|
||||
return output, errors.New(awserrors.ErrorInvalidParameterValue)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func reservationMatchesFilters(r *ec2.CapacityReservation, filters map[string][]
|
||||
default:
|
||||
return false
|
||||
}
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
gateway_ec2_zone "github.com/mulgadc/spinifex/spinifex/gateway/ec2/zone"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
@@ -42,7 +42,7 @@ func DescribeInstanceTypeOfferings(ctx context.Context, input *ec2.DescribeInsta
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeInstanceTypeOfferingsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeInstanceTypeOfferingsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeInstanceTypeOfferings: invalid filter", "err", err)
|
||||
return nil, errors.New(awserrors.ErrorInvalidParameterValue)
|
||||
@@ -60,11 +60,11 @@ func DescribeInstanceTypeOfferings(ctx context.Context, input *ec2.DescribeInsta
|
||||
if instanceType == nil || instanceType.InstanceType == nil {
|
||||
continue
|
||||
}
|
||||
if !filterutil.MatchesAny(parsedFilters["instance-type"], *instanceType.InstanceType) {
|
||||
if !awsfilters.MatchesAny(parsedFilters["instance-type"], *instanceType.InstanceType) {
|
||||
continue
|
||||
}
|
||||
for _, location := range locations {
|
||||
if !filterutil.MatchesAny(parsedFilters["location"], location) {
|
||||
if !awsfilters.MatchesAny(parsedFilters["location"], location) {
|
||||
continue
|
||||
}
|
||||
offerings = append(offerings, &ec2.InstanceTypeOffering{
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
@@ -160,7 +160,7 @@ func (s *EgressOnlyIGWServiceImpl) DescribeEgressOnlyInternetGateways(ctx contex
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeEIGWValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeEIGWValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeEgressOnlyInternetGateways: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -210,7 +210,7 @@ func (s *EgressOnlyIGWServiceImpl) DescribeEgressOnlyInternetGateways(ctx contex
|
||||
}, nil
|
||||
}
|
||||
|
||||
// eigwMatchesFilters checks whether an EgressOnlyIGWRecord satisfies all parsed filters.
|
||||
// eigwMatchesFilters checks whether an EgressOnlyIGWRecord satisfies all parsed awsfilters.
|
||||
func eigwMatchesFilters(record *EgressOnlyIGWRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -225,12 +225,12 @@ func eigwMatchesFilters(record *EgressOnlyIGWRecord, filters map[string][]string
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
func (s *EgressOnlyIGWServiceImpl) recordToEC2(record *EgressOnlyIGWRecord) *ec2.EgressOnlyInternetGateway {
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
@@ -541,7 +541,7 @@ func (s *EIPServiceImpl) DescribeAddresses(ctx context.Context, input *ec2.Descr
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeAddressesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeAddressesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeAddresses: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -610,7 +610,7 @@ func (s *EIPServiceImpl) DescribeAddresses(ctx context.Context, input *ec2.Descr
|
||||
}, nil
|
||||
}
|
||||
|
||||
// addressMatchesFilters checks whether an EIPRecord satisfies all parsed filters.
|
||||
// addressMatchesFilters checks whether an EIPRecord satisfies all parsed awsfilters.
|
||||
func addressMatchesFilters(record *EIPRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -633,12 +633,12 @@ func addressMatchesFilters(record *EIPRecord, filters map[string][]string) bool
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// DescribeAddressesAttribute returns per-EIP attributes. PtrRecord is always nil
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
@@ -200,7 +200,7 @@ func (s *IGWServiceImpl) DescribeInternetGateways(ctx context.Context, input *ec
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeIGWValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeIGWValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeInternetGateways: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -260,7 +260,7 @@ func (s *IGWServiceImpl) DescribeInternetGateways(ctx context.Context, input *ec
|
||||
}, nil
|
||||
}
|
||||
|
||||
// igwMatchesFilters checks whether an IGWRecord satisfies all parsed filters.
|
||||
// igwMatchesFilters checks whether an IGWRecord satisfies all parsed awsfilters.
|
||||
func igwMatchesFilters(record *IGWRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -285,12 +285,12 @@ func igwMatchesFilters(record *IGWRecord, filters map[string][]string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// AttachInternetGateway attaches an IGW to a VPC and publishes a NATS event
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsmetadata"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsprovider"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_snapshot "github.com/mulgadc/spinifex/spinifex/handlers/ec2/snapshot"
|
||||
"github.com/mulgadc/spinifex/spinifex/objectstore"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
@@ -129,7 +129,7 @@ func (s *ImageServiceImpl) DescribeImages(ctx context.Context, input *ec2.Descri
|
||||
|
||||
slog.InfoContext(ctx, "Describing images", "filters", input.Filters, "imageIds", input.ImageIds)
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeImagesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeImagesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeImages: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -337,7 +337,7 @@ func amiImageState(state string) string {
|
||||
return state
|
||||
}
|
||||
|
||||
// imageMatchesFilters checks whether an ec2.Image satisfies all parsed filters.
|
||||
// imageMatchesFilters checks whether an ec2.Image satisfies all parsed awsfilters.
|
||||
func imageMatchesFilters(image *ec2.Image, filters map[string][]string, tags map[string]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -390,12 +390,12 @@ func imageMatchesFilters(image *ec2.Image, filters map[string][]string, tags map
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, tags)
|
||||
return awsfilters.MatchesTags(filters, tags)
|
||||
}
|
||||
|
||||
// CreateImage is the generic interface method — on the daemon side, the handler
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/vm"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -195,7 +195,7 @@ func TestParseFilters_UnknownFilterName(t *testing.T) {
|
||||
filters := []*ec2.Filter{
|
||||
{Name: aws.String("bogus-filter"), Values: []*string{aws.String("val")}},
|
||||
}
|
||||
_, err := filterutil.ParseFilters(filters, DescribeInstancesValidFilters)
|
||||
_, err := awsfilters.ParseFilters(filters, DescribeInstancesValidFilters)
|
||||
require.Error(t, err)
|
||||
assert.Contains(t, err.Error(), "InvalidParameterValue")
|
||||
}
|
||||
@@ -205,11 +205,11 @@ func TestEC2TagsToMap(t *testing.T) {
|
||||
{Key: aws.String("a"), Value: aws.String("1")},
|
||||
{Key: aws.String("b"), Value: aws.String("2")},
|
||||
}
|
||||
m := filterutil.EC2TagsToMap(tags)
|
||||
m := awsfilters.EC2TagsToMap(tags)
|
||||
assert.Equal(t, "1", m["a"])
|
||||
assert.Equal(t, "2", m["b"])
|
||||
}
|
||||
|
||||
func TestEC2TagsToMap_Nil(t *testing.T) {
|
||||
assert.Nil(t, filterutil.EC2TagsToMap(nil))
|
||||
assert.Nil(t, awsfilters.EC2TagsToMap(nil))
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsmetadata"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsprovider"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_dns "github.com/mulgadc/spinifex/spinifex/handlers/dns"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/instancetypes"
|
||||
@@ -1975,11 +1975,11 @@ func IsInstanceVisibleToCaller(accountID string, v *vm.VM) bool {
|
||||
return v.ManagedBy == "" || accountID == utils.GlobalAccountID
|
||||
}
|
||||
|
||||
// instanceMatchesFilters checks whether a VM + its built ec2.Instance copy satisfy all parsed filters.
|
||||
// instanceMatchesFilters checks whether a VM + its built ec2.Instance copy satisfy all parsed awsfilters.
|
||||
func instanceMatchesFilters(inst *vm.VM, ic *ec2.Instance, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
// tag:Key filters are handled after all field filters.
|
||||
// tag:Key filters are handled after all field awsfilters.
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -2017,20 +2017,20 @@ func instanceMatchesFilters(inst *vm.VM, ic *ec2.Instance, filters map[string][]
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check tag:Key filters via the instance's Tag slice.
|
||||
tags := filterutil.EC2TagsToMap(ic.Tags)
|
||||
return filterutil.MatchesTags(filters, tags)
|
||||
tags := awsfilters.EC2TagsToMap(ic.Tags)
|
||||
return awsfilters.MatchesTags(filters, tags)
|
||||
}
|
||||
|
||||
// matchTagKey returns true if any tag key on the resource matches any of the filter values.
|
||||
func matchTagKey(tags []*ec2.Tag, values []string) bool {
|
||||
for _, t := range tags {
|
||||
if t.Key != nil && filterutil.MatchesAny(values, *t.Key) {
|
||||
if t.Key != nil && awsfilters.MatchesAny(values, *t.Key) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -2040,7 +2040,7 @@ func matchTagKey(tags []*ec2.Tag, values []string) bool {
|
||||
// matchTagValue returns true if any tag value on the resource matches any of the filter values.
|
||||
func matchTagValue(tags []*ec2.Tag, values []string) bool {
|
||||
for _, t := range tags {
|
||||
if t.Value != nil && filterutil.MatchesAny(values, *t.Value) {
|
||||
if t.Value != nil && awsfilters.MatchesAny(values, *t.Value) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -2056,7 +2056,7 @@ func (s *InstanceServiceImpl) DescribeInstances(ctx context.Context, input *ec2.
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, DescribeInstancesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, DescribeInstancesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeInstances: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -2184,7 +2184,7 @@ func (s *InstanceServiceImpl) describeInstancesFromKV(ctx context.Context, input
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parsedFilters, filterErr := filterutil.ParseFilters(input.Filters, DescribeInstancesValidFilters)
|
||||
parsedFilters, filterErr := awsfilters.ParseFilters(input.Filters, DescribeInstancesValidFilters)
|
||||
if filterErr != nil {
|
||||
slog.WarnContext(ctx, opName+": invalid filter", "err", filterErr)
|
||||
return nil, filterErr
|
||||
@@ -3546,16 +3546,16 @@ func instanceStatusMatchesFilters(v *vm.VM, is *ec2.InstanceStatus, filters map[
|
||||
default:
|
||||
return false
|
||||
}
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
if v.Instance != nil {
|
||||
tags := filterutil.EC2TagsToMap(v.Instance.Tags)
|
||||
return filterutil.MatchesTags(filters, tags)
|
||||
tags := awsfilters.EC2TagsToMap(v.Instance.Tags)
|
||||
return awsfilters.MatchesTags(filters, tags)
|
||||
}
|
||||
return filterutil.MatchesTags(filters, nil)
|
||||
return awsfilters.MatchesTags(filters, nil)
|
||||
}
|
||||
|
||||
// DescribeInstanceStatus returns per-VM status entries for VMs on this node
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/vm"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ func ParseStatusSelection(input *ec2.DescribeInstanceStatusInput, accountID stri
|
||||
return StatusSelection{}, err
|
||||
}
|
||||
|
||||
filters, err := filterutil.ParseFilters(input.Filters, DescribeInstanceStatusValidFilters)
|
||||
filters, err := awsfilters.ParseFilters(input.Filters, DescribeInstanceStatusValidFilters)
|
||||
if err != nil {
|
||||
slog.Warn("DescribeInstanceStatus: invalid filter", "err", err)
|
||||
return StatusSelection{}, err
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -30,7 +30,7 @@ func TestCreateKeyPair_TagSpecifications(t *testing.T) {
|
||||
}, testAccountID)
|
||||
require.NoError(t, err)
|
||||
|
||||
tags := filterutil.EC2TagsToMap(out.Tags)
|
||||
tags := awsfilters.EC2TagsToMap(out.Tags)
|
||||
assert.Equal(t, "build-key", tags["Name"])
|
||||
assert.Equal(t, "dev", tags["env"])
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestCreateKeyPair_TagSpecifications(t *testing.T) {
|
||||
}, testAccountID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, desc.KeyPairs, 1)
|
||||
descTags := filterutil.EC2TagsToMap(desc.KeyPairs[0].Tags)
|
||||
descTags := awsfilters.EC2TagsToMap(desc.KeyPairs[0].Tags)
|
||||
assert.Equal(t, "build-key", descTags["Name"])
|
||||
assert.Equal(t, "dev", descTags["env"])
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func TestImportKeyPair_TagSpecifications(t *testing.T) {
|
||||
}, testAccountID)
|
||||
require.NoError(t, err)
|
||||
|
||||
tags := filterutil.EC2TagsToMap(out.Tags)
|
||||
tags := awsfilters.EC2TagsToMap(out.Tags)
|
||||
assert.Equal(t, "build-key", tags["Name"])
|
||||
|
||||
// Tag filter matches the imported key.
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -20,7 +20,7 @@ func readKeyPairTags(t *testing.T, svc *KeyServiceImpl, accountID, keyPairID str
|
||||
t.Helper()
|
||||
var metadata ec2.CreateKeyPairOutput
|
||||
require.NoError(t, json.Unmarshal(readKeyPairRecord(t, svc, accountID, keyPairID), &metadata))
|
||||
return filterutil.EC2TagsToMap(metadata.Tags)
|
||||
return awsfilters.EC2TagsToMap(metadata.Tags)
|
||||
}
|
||||
|
||||
// readKeyPairRecord returns the stored metadata object verbatim.
|
||||
@@ -100,7 +100,7 @@ func TestKeyPairRecordTagsMirror_UpgradesLegacyRecord(t *testing.T) {
|
||||
require.Len(t, out.KeyPairs, 1)
|
||||
assert.Equal(t, "ed25519", *out.KeyPairs[0].KeyType)
|
||||
assert.Equal(t, testED25519Fingerprint, *out.KeyPairs[0].KeyFingerprint)
|
||||
assert.Equal(t, "prod", filterutil.EC2TagsToMap(out.KeyPairs[0].Tags)["env"])
|
||||
assert.Equal(t, "prod", awsfilters.EC2TagsToMap(out.KeyPairs[0].Tags)["env"])
|
||||
}
|
||||
|
||||
func TestKeyPairRecordTagsMirror_UnownedNoError(t *testing.T) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/s3"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/objectstore"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
"golang.org/x/crypto/ssh"
|
||||
@@ -611,7 +611,7 @@ func (s *KeyServiceImpl) DescribeKeyPairs(ctx context.Context, input *ec2.Descri
|
||||
|
||||
slog.InfoContext(ctx, "Describing key pairs", "filters", input.Filters)
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeKeyPairsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeKeyPairsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeKeyPairs: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -655,7 +655,7 @@ func (s *KeyServiceImpl) DescribeKeyPairs(ctx context.Context, input *ec2.Descri
|
||||
if len(keyPairIDFilterValues) > 0 {
|
||||
objKey := *obj.Key
|
||||
kpID := strings.TrimSuffix(strings.TrimPrefix(objKey, prefix), ".json")
|
||||
if !filterutil.MatchesAny(keyPairIDFilterValues, kpID) {
|
||||
if !awsfilters.MatchesAny(keyPairIDFilterValues, kpID) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
@@ -770,7 +770,7 @@ func (s *KeyServiceImpl) DescribeKeyPairs(ctx context.Context, input *ec2.Descri
|
||||
}, nil
|
||||
}
|
||||
|
||||
// keyPairMatchesFilters checks whether a KeyPairInfo satisfies all parsed filters.
|
||||
// keyPairMatchesFilters checks whether a KeyPairInfo satisfies all parsed awsfilters.
|
||||
func keyPairMatchesFilters(kp *ec2.KeyPairInfo, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -795,14 +795,14 @@ func keyPairMatchesFilters(kp *ec2.KeyPairInfo, filters map[string][]string) boo
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check tag:Key filters
|
||||
tags := filterutil.EC2TagsToMap(kp.Tags)
|
||||
return filterutil.MatchesTags(filters, tags)
|
||||
tags := awsfilters.EC2TagsToMap(kp.Tags)
|
||||
return awsfilters.MatchesTags(filters, tags)
|
||||
}
|
||||
|
||||
// ImportKeyPair imports an existing public key.
|
||||
@@ -981,7 +981,7 @@ func (s *KeyServiceImpl) mirrorKeyPairTags(ctx context.Context, resources []*str
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to unmarshal key pair metadata: %w", err)
|
||||
}
|
||||
tags := filterutil.EC2TagsToMap(metadata.Tags)
|
||||
tags := awsfilters.EC2TagsToMap(metadata.Tags)
|
||||
if tags == nil {
|
||||
tags = map[string]string{}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
@@ -573,7 +573,7 @@ var describeLaunchTemplatesValidFilters = map[string]bool{
|
||||
}
|
||||
|
||||
func (s *LaunchTemplateServiceImpl) DescribeLaunchTemplates(ctx context.Context, input *ec2.DescribeLaunchTemplatesInput, accountID string) (*ec2.DescribeLaunchTemplatesOutput, error) {
|
||||
filters, err := filterutil.ParseFilters(input.Filters, describeLaunchTemplatesValidFilters)
|
||||
filters, err := awsfilters.ParseFilters(input.Filters, describeLaunchTemplatesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeLaunchTemplates: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -651,21 +651,21 @@ func templateMatchesFilters(h *LaunchTemplateHeader, filters map[string][]string
|
||||
}
|
||||
switch name {
|
||||
case "launch-template-id":
|
||||
if !filterutil.MatchesAny(values, h.LaunchTemplateId) {
|
||||
if !awsfilters.MatchesAny(values, h.LaunchTemplateId) {
|
||||
return false
|
||||
}
|
||||
case "launch-template-name":
|
||||
if !filterutil.MatchesAny(values, h.LaunchTemplateName) {
|
||||
if !awsfilters.MatchesAny(values, h.LaunchTemplateName) {
|
||||
return false
|
||||
}
|
||||
case "create-time":
|
||||
if !filterutil.MatchesAny(values, h.CreateTime.Format(time.RFC3339)) {
|
||||
if !awsfilters.MatchesAny(values, h.CreateTime.Format(time.RFC3339)) {
|
||||
return false
|
||||
}
|
||||
case "tag-key":
|
||||
matched := false
|
||||
for k := range h.Tags {
|
||||
if filterutil.MatchesAny(values, k) {
|
||||
if awsfilters.MatchesAny(values, k) {
|
||||
matched = true
|
||||
break
|
||||
}
|
||||
@@ -677,7 +677,7 @@ func templateMatchesFilters(h *LaunchTemplateHeader, filters map[string][]string
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filterutil.MatchesTags(filters, h.Tags)
|
||||
return awsfilters.MatchesTags(filters, h.Tags)
|
||||
}
|
||||
|
||||
// --- DescribeLaunchTemplateVersions ---
|
||||
@@ -692,7 +692,7 @@ var describeLaunchTemplateVersionsValidFilters = map[string]bool{
|
||||
}
|
||||
|
||||
func (s *LaunchTemplateServiceImpl) DescribeLaunchTemplateVersions(ctx context.Context, input *ec2.DescribeLaunchTemplateVersionsInput, accountID string) (*ec2.DescribeLaunchTemplateVersionsOutput, error) {
|
||||
filters, err := filterutil.ParseFilters(input.Filters, describeLaunchTemplateVersionsValidFilters)
|
||||
filters, err := awsfilters.ParseFilters(input.Filters, describeLaunchTemplateVersionsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeLaunchTemplateVersions: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -788,27 +788,27 @@ func versionMatchesFilters(rec *LaunchTemplateVersionRec, isDefault bool, filter
|
||||
for name, values := range filters {
|
||||
switch name {
|
||||
case "is-default-version":
|
||||
if !filterutil.MatchesAny(values, strconv.FormatBool(isDefault)) {
|
||||
if !awsfilters.MatchesAny(values, strconv.FormatBool(isDefault)) {
|
||||
return false
|
||||
}
|
||||
case "image-id":
|
||||
if d == nil || !filterutil.MatchesAny(values, aws.StringValue(d.ImageId)) {
|
||||
if d == nil || !awsfilters.MatchesAny(values, aws.StringValue(d.ImageId)) {
|
||||
return false
|
||||
}
|
||||
case "instance-type":
|
||||
if d == nil || !filterutil.MatchesAny(values, aws.StringValue(d.InstanceType)) {
|
||||
if d == nil || !awsfilters.MatchesAny(values, aws.StringValue(d.InstanceType)) {
|
||||
return false
|
||||
}
|
||||
case "kernel-id":
|
||||
if d == nil || !filterutil.MatchesAny(values, aws.StringValue(d.KernelId)) {
|
||||
if d == nil || !awsfilters.MatchesAny(values, aws.StringValue(d.KernelId)) {
|
||||
return false
|
||||
}
|
||||
case "ram-disk-id":
|
||||
if d == nil || !filterutil.MatchesAny(values, aws.StringValue(d.RamDiskId)) {
|
||||
if d == nil || !awsfilters.MatchesAny(values, aws.StringValue(d.RamDiskId)) {
|
||||
return false
|
||||
}
|
||||
case "ebs-optimized":
|
||||
if d == nil || !filterutil.MatchesAny(values, strconv.FormatBool(aws.BoolValue(d.EbsOptimized))) {
|
||||
if d == nil || !awsfilters.MatchesAny(values, strconv.FormatBool(aws.BoolValue(d.EbsOptimized))) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_eip "github.com/mulgadc/spinifex/spinifex/handlers/ec2/eip"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
@@ -373,7 +373,7 @@ var describeNatGatewaysValidFilters = map[string]bool{
|
||||
|
||||
// DescribeNatGateways lists NAT Gateways, optionally filtered.
|
||||
func (s *NatGatewayServiceImpl) DescribeNatGateways(ctx context.Context, input *ec2.DescribeNatGatewaysInput, accountID string) (*ec2.DescribeNatGatewaysOutput, error) {
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filter, describeNatGatewaysValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filter, describeNatGatewaysValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeNatGateways: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -451,7 +451,7 @@ func (s *NatGatewayServiceImpl) DescribeNatGateways(ctx context.Context, input *
|
||||
}, nil
|
||||
}
|
||||
|
||||
// natgwMatchesFilters checks whether a NAT Gateway record matches all parsed filters.
|
||||
// natgwMatchesFilters checks whether a NAT Gateway record matches all parsed awsfilters.
|
||||
func natgwMatchesFilters(record *NatGatewayRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -459,26 +459,26 @@ func natgwMatchesFilters(record *NatGatewayRecord, filters map[string][]string)
|
||||
}
|
||||
switch name {
|
||||
case "nat-gateway-id":
|
||||
if !filterutil.MatchesAny(values, record.NatGatewayId) {
|
||||
if !awsfilters.MatchesAny(values, record.NatGatewayId) {
|
||||
return false
|
||||
}
|
||||
case "subnet-id":
|
||||
if !filterutil.MatchesAny(values, record.SubnetId) {
|
||||
if !awsfilters.MatchesAny(values, record.SubnetId) {
|
||||
return false
|
||||
}
|
||||
case "vpc-id":
|
||||
if !filterutil.MatchesAny(values, record.VpcId) {
|
||||
if !awsfilters.MatchesAny(values, record.VpcId) {
|
||||
return false
|
||||
}
|
||||
case "state":
|
||||
if !filterutil.MatchesAny(values, record.State) {
|
||||
if !awsfilters.MatchesAny(values, record.State) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// PublishAddEvent publishes a vpc.add-nat-gateway event for vpcd to create the SNAT rule.
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_eip "github.com/mulgadc/spinifex/spinifex/handlers/ec2/eip"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/testutil"
|
||||
@@ -133,7 +133,7 @@ func TestCreateNatGateway_PersistsTagsForTagFilterDiscovery(t *testing.T) {
|
||||
}, testAccountID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, out.NatGateways, 1, "tagged NAT GW must be discoverable by tag filter")
|
||||
tags := filterutil.EC2TagsToMap(out.NatGateways[0].Tags)
|
||||
tags := awsfilters.EC2TagsToMap(out.NatGateways[0].Tags)
|
||||
assert.Equal(t, "alpha", tags["spinifex:eks-cluster"])
|
||||
assert.Equal(t, "cp-natgw", tags["spinifex:eks-role"])
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
@@ -45,7 +45,7 @@ func TestCreatePlacementGroup_TagSpecifications(t *testing.T) {
|
||||
svc := setupTestService(t)
|
||||
pg := createTaggedGroup(t, svc, "tagged-group", map[string]string{"Name": "web", "env": "dev"})
|
||||
|
||||
tags := filterutil.EC2TagsToMap(pg.Tags)
|
||||
tags := awsfilters.EC2TagsToMap(pg.Tags)
|
||||
assert.Equal(t, "web", tags["Name"])
|
||||
assert.Equal(t, "dev", tags["env"])
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestCreatePlacementGroup_TagSpecifications(t *testing.T) {
|
||||
}, testAccountID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, out.PlacementGroups, 1)
|
||||
descTags := filterutil.EC2TagsToMap(out.PlacementGroups[0].Tags)
|
||||
descTags := awsfilters.EC2TagsToMap(out.PlacementGroups[0].Tags)
|
||||
assert.Equal(t, "web", descTags["Name"])
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
@@ -180,9 +180,9 @@ var describePlacementGroupsValidFilters = map[string]bool{
|
||||
"tag-value": true,
|
||||
}
|
||||
|
||||
// DescribePlacementGroups lists placement groups with optional filters.
|
||||
// DescribePlacementGroups lists placement groups with optional awsfilters.
|
||||
func (s *PlacementGroupServiceImpl) DescribePlacementGroups(ctx context.Context, input *ec2.DescribePlacementGroupsInput, accountID string) (*ec2.DescribePlacementGroupsOutput, error) {
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describePlacementGroupsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describePlacementGroupsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribePlacementGroups: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -266,7 +266,7 @@ func (s *PlacementGroupServiceImpl) DescribePlacementGroups(ctx context.Context,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// pgMatchesFilters checks whether a placement group record matches all parsed filters.
|
||||
// pgMatchesFilters checks whether a placement group record matches all parsed awsfilters.
|
||||
func pgMatchesFilters(record *PlacementGroupRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -274,23 +274,23 @@ func pgMatchesFilters(record *PlacementGroupRecord, filters map[string][]string)
|
||||
}
|
||||
switch name {
|
||||
case "group-id":
|
||||
if !filterutil.MatchesAny(values, record.GroupId) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupId) {
|
||||
return false
|
||||
}
|
||||
case "strategy":
|
||||
if !filterutil.MatchesAny(values, record.Strategy) {
|
||||
if !awsfilters.MatchesAny(values, record.Strategy) {
|
||||
return false
|
||||
}
|
||||
case "state":
|
||||
if !filterutil.MatchesAny(values, record.State) {
|
||||
if !awsfilters.MatchesAny(values, record.State) {
|
||||
return false
|
||||
}
|
||||
case "spread-level":
|
||||
if !filterutil.MatchesAny(values, record.SpreadLevel) {
|
||||
if !awsfilters.MatchesAny(values, record.SpreadLevel) {
|
||||
return false
|
||||
}
|
||||
case "group-name":
|
||||
if !filterutil.MatchesAny(values, record.GroupName) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupName) {
|
||||
return false
|
||||
}
|
||||
case "tag-key":
|
||||
@@ -305,14 +305,14 @@ func pgMatchesFilters(record *PlacementGroupRecord, filters map[string][]string)
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// pgMatchesAnyTag reports whether any tag's selected field (key or value)
|
||||
// matches any of the filter values.
|
||||
func pgMatchesAnyTag(tags map[string]string, values []string, field func(k, v string) string) bool {
|
||||
for k, v := range tags {
|
||||
if filterutil.MatchesAny(values, field(k, v)) {
|
||||
if awsfilters.MatchesAny(values, field(k, v)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_igw "github.com/mulgadc/spinifex/spinifex/handlers/ec2/igw"
|
||||
handlers_ec2_natgw "github.com/mulgadc/spinifex/spinifex/handlers/ec2/natgw"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
@@ -610,7 +610,7 @@ func (s *RouteTableServiceImpl) DescribeRouteTables(ctx context.Context, input *
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeRouteTablesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeRouteTablesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeRouteTables: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -1192,7 +1192,7 @@ func (s *RouteTableServiceImpl) ReplaceRouteTableAssociation(ctx context.Context
|
||||
return nil, errors.New(awserrors.ErrorInvalidAssociationIDNotFound)
|
||||
}
|
||||
|
||||
// rtbMatchesFilters checks if a route table record matches all parsed filters.
|
||||
// rtbMatchesFilters checks if a route table record matches all parsed awsfilters.
|
||||
func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -1200,11 +1200,11 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
}
|
||||
switch name {
|
||||
case "vpc-id":
|
||||
if !filterutil.MatchesAny(values, record.VpcId) {
|
||||
if !awsfilters.MatchesAny(values, record.VpcId) {
|
||||
return false
|
||||
}
|
||||
case "route-table-id":
|
||||
if !filterutil.MatchesAny(values, record.RouteTableId) {
|
||||
if !awsfilters.MatchesAny(values, record.RouteTableId) {
|
||||
return false
|
||||
}
|
||||
case "association.main":
|
||||
@@ -1215,14 +1215,14 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
break
|
||||
}
|
||||
}
|
||||
wantMain := filterutil.MatchesAny(values, "true")
|
||||
wantMain := awsfilters.MatchesAny(values, "true")
|
||||
if wantMain != hasMain {
|
||||
return false
|
||||
}
|
||||
case "association.route-table-association-id":
|
||||
found := false
|
||||
for _, a := range record.Associations {
|
||||
if filterutil.MatchesAny(values, a.AssociationId) {
|
||||
if awsfilters.MatchesAny(values, a.AssociationId) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1233,7 +1233,7 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
case "association.subnet-id":
|
||||
found := false
|
||||
for _, a := range record.Associations {
|
||||
if filterutil.MatchesAny(values, a.SubnetId) {
|
||||
if awsfilters.MatchesAny(values, a.SubnetId) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1244,7 +1244,7 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
case "route.destination-cidr-block":
|
||||
found := false
|
||||
for _, r := range record.Routes {
|
||||
if filterutil.MatchesAny(values, r.DestinationCidrBlock) {
|
||||
if awsfilters.MatchesAny(values, r.DestinationCidrBlock) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1255,7 +1255,7 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
case "route.gateway-id":
|
||||
found := false
|
||||
for _, r := range record.Routes {
|
||||
if filterutil.MatchesAny(values, r.GatewayId) {
|
||||
if awsfilters.MatchesAny(values, r.GatewayId) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1266,7 +1266,7 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
case "route.nat-gateway-id":
|
||||
found := false
|
||||
for _, r := range record.Routes {
|
||||
if filterutil.MatchesAny(values, r.NatGatewayId) {
|
||||
if awsfilters.MatchesAny(values, r.NatGatewayId) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1277,7 +1277,7 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
case "route.state":
|
||||
found := false
|
||||
for _, r := range record.Routes {
|
||||
if filterutil.MatchesAny(values, r.State) {
|
||||
if awsfilters.MatchesAny(values, r.State) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1288,7 +1288,7 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
case "route.origin":
|
||||
found := false
|
||||
for _, r := range record.Routes {
|
||||
if filterutil.MatchesAny(values, r.Origin) {
|
||||
if awsfilters.MatchesAny(values, r.Origin) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -1297,14 +1297,14 @@ func rtbMatchesFilters(record *RouteTableRecord, filters map[string][]string) bo
|
||||
return false
|
||||
}
|
||||
case "owner-id":
|
||||
if !filterutil.MatchesAny(values, record.AccountID) {
|
||||
if !awsfilters.MatchesAny(values, record.AccountID) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// publishNatGatewayEvents publishes vpc.add-nat-gateway for each associated subnet
|
||||
|
||||
@@ -20,7 +20,7 @@ import (
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsmetadata"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsprovider"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/handlers/ec2/volumestate"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvstore"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
@@ -451,7 +451,7 @@ func (s *SnapshotServiceImpl) describeSnapshots(ctx context.Context, input *ec2.
|
||||
|
||||
slog.InfoContext(ctx, "DescribeSnapshots request", "snapshotIds", input.SnapshotIds, "accountID", accountID)
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeSnapshotsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeSnapshotsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeSnapshots: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -628,7 +628,7 @@ func ownerIDsIncludeCaller(ownerIDs []*string, accountID string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// snapshotMatchesFilters checks whether a snapshot document satisfies all parsed filters.
|
||||
// snapshotMatchesFilters checks whether a snapshot document satisfies all parsed awsfilters.
|
||||
func snapshotMatchesFilters(cfg ebsmetadata.Snapshot, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -651,12 +651,12 @@ func snapshotMatchesFilters(cfg ebsmetadata.Snapshot, filters map[string][]strin
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, cfg.Tags)
|
||||
return awsfilters.MatchesTags(filters, cfg.Tags)
|
||||
}
|
||||
|
||||
// snapshotInUseByVolumes checks if any volume was created from the given
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
@@ -125,9 +125,9 @@ var describeSpotRequestsValidFilters = map[string]bool{
|
||||
"tag-key": true,
|
||||
}
|
||||
|
||||
// DescribeSpotInstanceRequests lists requests from both buckets, merges, and filters.
|
||||
// DescribeSpotInstanceRequests lists requests from both buckets, merges, and awsfilters.
|
||||
func (s *SpotInstanceServiceImpl) DescribeSpotInstanceRequests(ctx context.Context, input *ec2.DescribeSpotInstanceRequestsInput, accountID string) (*ec2.DescribeSpotInstanceRequestsOutput, error) {
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeSpotRequestsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeSpotRequestsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeSpotInstanceRequests: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -159,7 +159,7 @@ func (s *SpotInstanceServiceImpl) DescribeSpotInstanceRequests(ctx context.Conte
|
||||
if !sirMatchesFilters(req, parsedFilters) {
|
||||
continue
|
||||
}
|
||||
if !filterutil.MatchesTags(parsedFilters, filterutil.EC2TagsToMap(req.Tags)) {
|
||||
if !awsfilters.MatchesTags(parsedFilters, awsfilters.EC2TagsToMap(req.Tags)) {
|
||||
continue
|
||||
}
|
||||
found[sirID] = true
|
||||
@@ -321,41 +321,41 @@ func setSpotStatus(req *ec2.SpotInstanceRequest, code, message string) {
|
||||
}
|
||||
}
|
||||
|
||||
// sirMatchesFilters reports whether a request matches all non-tag filters.
|
||||
// tag:* filters are handled separately via filterutil.MatchesTags.
|
||||
// sirMatchesFilters reports whether a request matches all non-tag awsfilters.
|
||||
// tag:* filters are handled separately via awsfilters.MatchesTags.
|
||||
func sirMatchesFilters(req *ec2.SpotInstanceRequest, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
switch {
|
||||
case name == "spot-instance-request-id":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(req.SpotInstanceRequestId)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(req.SpotInstanceRequestId)) {
|
||||
return false
|
||||
}
|
||||
case name == "state":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(req.State)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(req.State)) {
|
||||
return false
|
||||
}
|
||||
case name == "instance-id":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(req.InstanceId)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(req.InstanceId)) {
|
||||
return false
|
||||
}
|
||||
case name == "type":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(req.Type)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(req.Type)) {
|
||||
return false
|
||||
}
|
||||
case name == "launched-availability-zone":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(req.LaunchedAvailabilityZone)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(req.LaunchedAvailabilityZone)) {
|
||||
return false
|
||||
}
|
||||
case name == "launch.image-id":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(launchSpec(req).ImageId)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(launchSpec(req).ImageId)) {
|
||||
return false
|
||||
}
|
||||
case name == "launch.instance-type":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(launchSpec(req).InstanceType)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(launchSpec(req).InstanceType)) {
|
||||
return false
|
||||
}
|
||||
case name == "launch.key-name":
|
||||
if !filterutil.MatchesAny(values, aws.StringValue(launchSpec(req).KeyName)) {
|
||||
if !awsfilters.MatchesAny(values, aws.StringValue(launchSpec(req).KeyName)) {
|
||||
return false
|
||||
}
|
||||
case name == "tag-key":
|
||||
@@ -363,7 +363,7 @@ func sirMatchesFilters(req *ec2.SpotInstanceRequest, filters map[string][]string
|
||||
return false
|
||||
}
|
||||
case strings.HasPrefix(name, "tag:"):
|
||||
// Handled by filterutil.MatchesTags.
|
||||
// Handled by awsfilters.MatchesTags.
|
||||
default:
|
||||
return false
|
||||
}
|
||||
@@ -373,7 +373,7 @@ func sirMatchesFilters(req *ec2.SpotInstanceRequest, filters map[string][]string
|
||||
|
||||
func sirMatchesTagKey(tags []*ec2.Tag, values []string) bool {
|
||||
for _, t := range tags {
|
||||
if t.Key != nil && filterutil.MatchesAny(values, *t.Key) {
|
||||
if t.Key != nil && awsfilters.MatchesAny(values, *t.Key) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/mulgadc/spinifex/spinifex/foundation/aws/arn"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_instance "github.com/mulgadc/spinifex/spinifex/handlers/ec2/instance"
|
||||
handlers_ec2_vpc "github.com/mulgadc/spinifex/spinifex/handlers/ec2/vpc"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
@@ -287,12 +287,12 @@ var describeTagsValidFilters = map[string]bool{
|
||||
"value": true,
|
||||
}
|
||||
|
||||
// DescribeTags returns tags matching the specified filters.
|
||||
// DescribeTags returns tags matching the specified awsfilters.
|
||||
func (s *TagsServiceImpl) DescribeTags(ctx context.Context, input *ec2.DescribeTagsInput, accountID string) (*ec2.DescribeTagsOutput, error) {
|
||||
var filters map[string][]string
|
||||
if input != nil {
|
||||
var err error
|
||||
filters, err = filterutil.ParseFilters(input.Filters, describeTagsValidFilters)
|
||||
filters, err = awsfilters.ParseFilters(input.Filters, describeTagsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeTags: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -312,10 +312,10 @@ func (s *TagsServiceImpl) DescribeTags(ctx context.Context, input *ec2.DescribeT
|
||||
for _, resourceID := range resourceIDs {
|
||||
resourceType := describeTagsResourceType(resourceID)
|
||||
|
||||
if !filterutil.MatchesAny(filters["resource-id"], resourceID) {
|
||||
if !awsfilters.MatchesAny(filters["resource-id"], resourceID) {
|
||||
continue
|
||||
}
|
||||
if !filterutil.MatchesAny(filters["resource-type"], resourceType) {
|
||||
if !awsfilters.MatchesAny(filters["resource-type"], resourceType) {
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -327,10 +327,10 @@ func (s *TagsServiceImpl) DescribeTags(ctx context.Context, input *ec2.DescribeT
|
||||
}
|
||||
|
||||
for key, value := range resourceTags {
|
||||
if !filterutil.MatchesAny(filters["key"], key) {
|
||||
if !awsfilters.MatchesAny(filters["key"], key) {
|
||||
continue
|
||||
}
|
||||
if !filterutil.MatchesAny(filters["value"], value) {
|
||||
if !awsfilters.MatchesAny(filters["value"], value) {
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsmetadata"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsprovider"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
handlers_ec2_instance "github.com/mulgadc/spinifex/spinifex/handlers/ec2/instance"
|
||||
"github.com/mulgadc/spinifex/spinifex/objectstore"
|
||||
"github.com/mulgadc/spinifex/spinifex/types"
|
||||
@@ -294,7 +294,7 @@ func (s *VolumeServiceImpl) DescribeVolumes(ctx context.Context, input *ec2.Desc
|
||||
|
||||
slog.InfoContext(ctx, "Describing volumes", "volumeIds", input.VolumeIds)
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeVolumesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeVolumesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeVolumes: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -337,7 +337,7 @@ func (s *VolumeServiceImpl) DescribeVolumes(ctx context.Context, input *ec2.Desc
|
||||
return &ec2.DescribeVolumesOutput{Volumes: volumes}, nil
|
||||
}
|
||||
|
||||
// volumeMatchesFilters checks whether an ec2.Volume satisfies all parsed filters.
|
||||
// volumeMatchesFilters checks whether an ec2.Volume satisfies all parsed awsfilters.
|
||||
func volumeMatchesFilters(vol *ec2.Volume, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -400,14 +400,14 @@ func volumeMatchesFilters(vol *ec2.Volume, filters map[string][]string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Check tag:Key filters
|
||||
tags := filterutil.EC2TagsToMap(vol.Tags)
|
||||
return filterutil.MatchesTags(filters, tags)
|
||||
tags := awsfilters.EC2TagsToMap(vol.Tags)
|
||||
return awsfilters.MatchesTags(filters, tags)
|
||||
}
|
||||
|
||||
// volumeAttachmentMatchesAny checks if any attachment's field matches any filter value.
|
||||
@@ -416,7 +416,7 @@ func volumeAttachmentMatchesAny(attachments []*ec2.VolumeAttachment, fieldFn fun
|
||||
return false
|
||||
}
|
||||
for _, a := range attachments {
|
||||
if filterutil.MatchesAny(values, fieldFn(a)) {
|
||||
if awsfilters.MatchesAny(values, fieldFn(a)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -438,7 +438,7 @@ func (s *VolumeServiceImpl) DescribeVolumeStatus(ctx context.Context, input *ec2
|
||||
|
||||
slog.InfoContext(ctx, "DescribeVolumeStatus", "volumeIds", input.VolumeIds)
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeVolumeStatusValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeVolumeStatusValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeVolumeStatus: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -447,7 +447,7 @@ func (s *VolumeServiceImpl) DescribeVolumeStatus(ctx context.Context, input *ec2
|
||||
return s.describeVolumeStatus(ctx, input, accountID, parsedFilters)
|
||||
}
|
||||
|
||||
// volumeStatusMatchesFilters checks whether a VolumeStatusItem satisfies all parsed filters.
|
||||
// volumeStatusMatchesFilters checks whether a VolumeStatusItem satisfies all parsed awsfilters.
|
||||
func volumeStatusMatchesFilters(item *ec2.VolumeStatusItem, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -473,7 +473,7 @@ func volumeStatusMatchesFilters(item *ec2.VolumeStatusItem, filters map[string][
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -589,7 +589,7 @@ func ebsModificationToEC2(volumeID string, m *ebsmetadata.VolumeModification) *e
|
||||
}
|
||||
|
||||
// volumeModificationMatchesFilters checks whether an ec2.VolumeModification
|
||||
// satisfies all parsed filters.
|
||||
// satisfies all parsed awsfilters.
|
||||
func volumeModificationMatchesFilters(m *ec2.VolumeModification, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -639,7 +639,7 @@ func volumeModificationMatchesFilters(m *ec2.VolumeModification, filters map[str
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -656,7 +656,7 @@ func (s *VolumeServiceImpl) DescribeVolumesModifications(ctx context.Context, in
|
||||
|
||||
slog.InfoContext(ctx, "DescribeVolumesModifications", "volumeIds", input.VolumeIds)
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeVolumesModificationsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeVolumesModificationsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeVolumesModifications: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -699,7 +699,7 @@ func (s *VolumeServiceImpl) DescribeVolumesModifications(ctx context.Context, in
|
||||
}
|
||||
|
||||
for _, meta := range metas {
|
||||
if len(volumeIDFilterValues) > 0 && !filterutil.MatchesAny(volumeIDFilterValues, meta.VolumeID) {
|
||||
if len(volumeIDFilterValues) > 0 && !awsfilters.MatchesAny(volumeIDFilterValues, meta.VolumeID) {
|
||||
continue
|
||||
}
|
||||
if meta.Modification == nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsmetadata"
|
||||
"github.com/mulgadc/spinifex/spinifex/ebsprovider"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/objectstore"
|
||||
"github.com/mulgadc/spinifex/spinifex/testutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/testutil/ebsfake"
|
||||
@@ -538,7 +538,7 @@ func TestVolumeLeakReaper_Provider(t *testing.T) {
|
||||
described, err := svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []*string{vol.VolumeId}}, testVolAccountID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, described.Volumes, 1)
|
||||
assert.NotEmpty(t, filterutil.EC2TagsToMap(described.Volumes[0].Tags)[orphanTagKey],
|
||||
assert.NotEmpty(t, awsfilters.EC2TagsToMap(described.Volumes[0].Tags)[orphanTagKey],
|
||||
"the orphan mark must be visible via DescribeVolumes, which reads ebsmetadata under the provider path")
|
||||
|
||||
// Idempotent: a second sweep re-marks nothing.
|
||||
@@ -567,7 +567,7 @@ func TestApplyRecordTags_Provider_VisibleViaDescribeVolumes(t *testing.T) {
|
||||
described, err := svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []*string{vol.VolumeId}}, testVolAccountID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, described.Volumes, 1)
|
||||
assert.Equal(t, "control-plane", filterutil.EC2TagsToMap(described.Volumes[0].Tags)["owner"],
|
||||
assert.Equal(t, "control-plane", awsfilters.EC2TagsToMap(described.Volumes[0].Tags)["owner"],
|
||||
"a tag applied post-create must be visible via DescribeVolumes under the provider path")
|
||||
|
||||
require.NoError(t, svc.RemoveRecordTags(&ec2.DeleteTagsInput{
|
||||
@@ -578,7 +578,7 @@ func TestApplyRecordTags_Provider_VisibleViaDescribeVolumes(t *testing.T) {
|
||||
described, err = svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []*string{vol.VolumeId}}, testVolAccountID)
|
||||
require.NoError(t, err)
|
||||
require.Len(t, described.Volumes, 1)
|
||||
_, hasOwnerTag := filterutil.EC2TagsToMap(described.Volumes[0].Tags)["owner"]
|
||||
_, hasOwnerTag := awsfilters.EC2TagsToMap(described.Volumes[0].Tags)["owner"]
|
||||
assert.False(t, hasOwnerTag, "RemoveRecordTags must remove the tag under the provider path too")
|
||||
|
||||
t.Run("wrong tenant is a no-op", func(t *testing.T) {
|
||||
@@ -588,7 +588,7 @@ func TestApplyRecordTags_Provider_VisibleViaDescribeVolumes(t *testing.T) {
|
||||
}, "000000000002"))
|
||||
described, err := svc.DescribeVolumes(ctx, &ec2.DescribeVolumesInput{VolumeIds: []*string{vol.VolumeId}}, testVolAccountID)
|
||||
require.NoError(t, err)
|
||||
_, hasOwnerTag := filterutil.EC2TagsToMap(described.Volumes[0].Tags)["owner"]
|
||||
_, hasOwnerTag := awsfilters.EC2TagsToMap(described.Volumes[0].Tags)["owner"]
|
||||
assert.False(t, hasOwnerTag, "a caller who does not own the volume must not be able to tag it")
|
||||
})
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/network/topology"
|
||||
"github.com/mulgadc/spinifex/spinifex/tags"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
@@ -488,9 +488,9 @@ var describeNetworkInterfacesValidFilters = map[string]bool{
|
||||
"attachment.status": true,
|
||||
}
|
||||
|
||||
// DescribeNetworkInterfaces lists ENIs with optional filters.
|
||||
// DescribeNetworkInterfaces lists ENIs with optional awsfilters.
|
||||
func (s *VPCServiceImpl) DescribeNetworkInterfaces(ctx context.Context, input *ec2.DescribeNetworkInterfacesInput, accountID string) (*ec2.DescribeNetworkInterfacesOutput, error) {
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeNetworkInterfacesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeNetworkInterfacesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeNetworkInterfaces: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -563,7 +563,7 @@ func (s *VPCServiceImpl) DescribeNetworkInterfaces(ctx context.Context, input *e
|
||||
}, nil
|
||||
}
|
||||
|
||||
// eniMatchesFilters checks whether an ENI record matches all parsed filters.
|
||||
// eniMatchesFilters checks whether an ENI record matches all parsed awsfilters.
|
||||
func eniMatchesFilters(record *ENIRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -571,33 +571,33 @@ func eniMatchesFilters(record *ENIRecord, filters map[string][]string) bool {
|
||||
}
|
||||
switch name {
|
||||
case "network-interface-id":
|
||||
if !filterutil.MatchesAny(values, record.NetworkInterfaceId) {
|
||||
if !awsfilters.MatchesAny(values, record.NetworkInterfaceId) {
|
||||
return false
|
||||
}
|
||||
case "subnet-id":
|
||||
if !filterutil.MatchesAny(values, record.SubnetId) {
|
||||
if !awsfilters.MatchesAny(values, record.SubnetId) {
|
||||
return false
|
||||
}
|
||||
case "vpc-id":
|
||||
if !filterutil.MatchesAny(values, record.VpcId) {
|
||||
if !awsfilters.MatchesAny(values, record.VpcId) {
|
||||
return false
|
||||
}
|
||||
case "status":
|
||||
if !filterutil.MatchesAny(values, record.Status) {
|
||||
if !awsfilters.MatchesAny(values, record.Status) {
|
||||
return false
|
||||
}
|
||||
case "private-ip-address":
|
||||
if !filterutil.MatchesAny(values, record.PrivateIpAddress) {
|
||||
if !awsfilters.MatchesAny(values, record.PrivateIpAddress) {
|
||||
return false
|
||||
}
|
||||
case "availability-zone":
|
||||
if !filterutil.MatchesAny(values, record.AvailabilityZone) {
|
||||
if !awsfilters.MatchesAny(values, record.AvailabilityZone) {
|
||||
return false
|
||||
}
|
||||
case "group-id":
|
||||
found := false
|
||||
for _, sgId := range record.SecurityGroupIds {
|
||||
if filterutil.MatchesAny(values, sgId) {
|
||||
if awsfilters.MatchesAny(values, sgId) {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
@@ -606,19 +606,19 @@ func eniMatchesFilters(record *ENIRecord, filters map[string][]string) bool {
|
||||
return false
|
||||
}
|
||||
case "mac-address":
|
||||
if !filterutil.MatchesAny(values, record.MacAddress) {
|
||||
if !awsfilters.MatchesAny(values, record.MacAddress) {
|
||||
return false
|
||||
}
|
||||
case "description":
|
||||
if !filterutil.MatchesAny(values, record.Description) {
|
||||
if !awsfilters.MatchesAny(values, record.Description) {
|
||||
return false
|
||||
}
|
||||
case "attachment.attachment-id":
|
||||
if !filterutil.MatchesAny(values, record.AttachmentId) {
|
||||
if !awsfilters.MatchesAny(values, record.AttachmentId) {
|
||||
return false
|
||||
}
|
||||
case "attachment.instance-id":
|
||||
if !filterutil.MatchesAny(values, record.InstanceId) {
|
||||
if !awsfilters.MatchesAny(values, record.InstanceId) {
|
||||
return false
|
||||
}
|
||||
case "attachment.status":
|
||||
@@ -626,14 +626,14 @@ func eniMatchesFilters(record *ENIRecord, filters map[string][]string) bool {
|
||||
if record.InstanceId != "" {
|
||||
status = "attached"
|
||||
}
|
||||
if !filterutil.MatchesAny(values, status) {
|
||||
if !awsfilters.MatchesAny(values, status) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// AttachENI marks an ENI as attached to an instance (internal use by RunInstances).
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
"github.com/nats-io/nats.go/jetstream"
|
||||
)
|
||||
@@ -441,7 +441,7 @@ var describeSecurityGroupsValidFilters = map[string]bool{
|
||||
"ip-permission.cidr": true,
|
||||
}
|
||||
|
||||
// DescribeSecurityGroups lists security groups with optional filters.
|
||||
// DescribeSecurityGroups lists security groups with optional awsfilters.
|
||||
func (s *VPCServiceImpl) DescribeSecurityGroups(ctx context.Context, input *ec2.DescribeSecurityGroupsInput, accountID string) (*ec2.DescribeSecurityGroupsOutput, error) {
|
||||
groups := []*ec2.SecurityGroup{}
|
||||
|
||||
@@ -452,7 +452,7 @@ func (s *VPCServiceImpl) DescribeSecurityGroups(ctx context.Context, input *ec2.
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeSecurityGroupsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeSecurityGroupsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeSecurityGroups: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -517,7 +517,7 @@ func (s *VPCServiceImpl) DescribeSecurityGroups(ctx context.Context, input *ec2.
|
||||
}, nil
|
||||
}
|
||||
|
||||
// sgMatchesFilters checks whether a SecurityGroupRecord satisfies all parsed filters.
|
||||
// sgMatchesFilters checks whether a SecurityGroupRecord satisfies all parsed awsfilters.
|
||||
func sgMatchesFilters(record *SecurityGroupRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -526,19 +526,19 @@ func sgMatchesFilters(record *SecurityGroupRecord, filters map[string][]string)
|
||||
|
||||
switch name {
|
||||
case "group-id":
|
||||
if !filterutil.MatchesAny(values, record.GroupId) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupId) {
|
||||
return false
|
||||
}
|
||||
case "group-name":
|
||||
if !filterutil.MatchesAny(values, record.GroupName) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupName) {
|
||||
return false
|
||||
}
|
||||
case "vpc-id":
|
||||
if !filterutil.MatchesAny(values, record.VpcId) {
|
||||
if !awsfilters.MatchesAny(values, record.VpcId) {
|
||||
return false
|
||||
}
|
||||
case "description":
|
||||
if !filterutil.MatchesAny(values, record.Description) {
|
||||
if !awsfilters.MatchesAny(values, record.Description) {
|
||||
return false
|
||||
}
|
||||
case "ip-permission.cidr":
|
||||
@@ -550,13 +550,13 @@ func sgMatchesFilters(record *SecurityGroupRecord, filters map[string][]string)
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// sgIngressCIDRMatchesAny checks if any ingress rule's CIDR matches any of the filter values.
|
||||
func sgIngressCIDRMatchesAny(rules []SGRule, values []string) bool {
|
||||
for _, rule := range rules {
|
||||
if rule.CidrIp != "" && filterutil.MatchesAny(values, rule.CidrIp) {
|
||||
if rule.CidrIp != "" && awsfilters.MatchesAny(values, rule.CidrIp) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -596,7 +596,7 @@ func (s *VPCServiceImpl) GetSecurityGroupsForVpc(ctx context.Context, input *ec2
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, getSecurityGroupsForVpcValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, getSecurityGroupsForVpcValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "GetSecurityGroupsForVpc: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -673,23 +673,23 @@ func sgForVpcMatchesFilters(record *SecurityGroupRecord, accountID string, filte
|
||||
|
||||
switch name {
|
||||
case "group-id":
|
||||
if !filterutil.MatchesAny(values, record.GroupId) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupId) {
|
||||
return false
|
||||
}
|
||||
case "group-name":
|
||||
if !filterutil.MatchesAny(values, record.GroupName) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupName) {
|
||||
return false
|
||||
}
|
||||
case "description":
|
||||
if !filterutil.MatchesAny(values, record.Description) {
|
||||
if !awsfilters.MatchesAny(values, record.Description) {
|
||||
return false
|
||||
}
|
||||
case "owner-id":
|
||||
if !filterutil.MatchesAny(values, accountID) {
|
||||
if !awsfilters.MatchesAny(values, accountID) {
|
||||
return false
|
||||
}
|
||||
case "primary-vpc-id":
|
||||
if !filterutil.MatchesAny(values, record.VpcId) {
|
||||
if !awsfilters.MatchesAny(values, record.VpcId) {
|
||||
return false
|
||||
}
|
||||
default:
|
||||
@@ -697,7 +697,7 @@ func sgForVpcMatchesFilters(record *SecurityGroupRecord, accountID string, filte
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// pageSecurityGroupsForVpc slices one page out of a sorted group set, using an
|
||||
@@ -736,7 +736,7 @@ var describeSecurityGroupRulesValidFilters = map[string]bool{
|
||||
|
||||
// DescribeSecurityGroupRules returns a flat list of SecurityGroupRule objects
|
||||
// for the caller's account, optionally narrowed by SecurityGroupRuleIds or
|
||||
// filters. MaxResults and NextToken are accepted but ignored.
|
||||
// awsfilters. MaxResults and NextToken are accepted but ignored.
|
||||
func (s *VPCServiceImpl) DescribeSecurityGroupRules(ctx context.Context, input *ec2.DescribeSecurityGroupRulesInput, accountID string) (*ec2.DescribeSecurityGroupRulesOutput, error) {
|
||||
requested := make(map[string]bool)
|
||||
if input != nil {
|
||||
@@ -752,7 +752,7 @@ func (s *VPCServiceImpl) DescribeSecurityGroupRules(ctx context.Context, input *
|
||||
if input != nil {
|
||||
filters = input.Filters
|
||||
}
|
||||
parsedFilters, err := filterutil.ParseFilters(filters, describeSecurityGroupRulesValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(filters, describeSecurityGroupRulesValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeSecurityGroupRules: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -828,11 +828,11 @@ func sgRuleMatchesFilters(record *SecurityGroupRecord, rule SGRule, filters map[
|
||||
}
|
||||
switch name {
|
||||
case "group-id":
|
||||
if !filterutil.MatchesAny(values, record.GroupId) {
|
||||
if !awsfilters.MatchesAny(values, record.GroupId) {
|
||||
return false
|
||||
}
|
||||
case "security-group-rule-id":
|
||||
if !filterutil.MatchesAny(values, rule.RuleId) {
|
||||
if !awsfilters.MatchesAny(values, rule.RuleId) {
|
||||
return false
|
||||
}
|
||||
case "tag-key":
|
||||
@@ -846,7 +846,7 @@ func sgRuleMatchesFilters(record *SecurityGroupRecord, rule SGRule, filters map[
|
||||
return false
|
||||
}
|
||||
}
|
||||
return filterutil.MatchesTags(filters, rule.Tags)
|
||||
return awsfilters.MatchesTags(filters, rule.Tags)
|
||||
}
|
||||
|
||||
// updateSGRuleTags applies mut to the tags of the rule named by ruleID, which
|
||||
@@ -921,7 +921,7 @@ func findSGRuleByID(rules []SGRule, ruleID string) *SGRule {
|
||||
// keys, whatever their values.
|
||||
func sgRuleMatchesTagKey(tags map[string]string, keys []string) bool {
|
||||
for key := range tags {
|
||||
if filterutil.MatchesAny(keys, key) {
|
||||
if awsfilters.MatchesAny(keys, key) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
@@ -211,7 +211,7 @@ func TestModifySecurityGroupRules_PreservesTags(t *testing.T) {
|
||||
require.NoError(t, modifyRules(svc, sgID, ruleUpdate(ruleID, tcpCIDRRequest(81, "10.0.0.0/24"))))
|
||||
|
||||
want := map[string]string{"Name": "web"}
|
||||
assert.Equal(t, want, filterutil.EC2TagsToMap(sgRuleByID(t, svc, testAccountID, ruleID).Tags))
|
||||
assert.Equal(t, want, awsfilters.EC2TagsToMap(sgRuleByID(t, svc, testAccountID, ruleID).Tags))
|
||||
assert.Equal(t, want, writer.Calls[ruleID], "the central tag store must still hold the rule's tags")
|
||||
assert.NotContains(t, writer.Deleted, ruleID, "a modify must not clear the rule's central tags")
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/testutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
"github.com/nats-io/nats.go"
|
||||
@@ -2387,7 +2387,7 @@ func TestAuthorizeSecurityGroupIngress_StoresRuleTags(t *testing.T) {
|
||||
require.Len(t, out.SecurityGroupRules, 1)
|
||||
ruleID := aws.StringValue(out.SecurityGroupRules[0].SecurityGroupRuleId)
|
||||
assert.Equal(t, map[string]string{"terraform-aws-modules": "alb"},
|
||||
filterutil.EC2TagsToMap(out.SecurityGroupRules[0].Tags), "authorize must echo the tags it stored")
|
||||
awsfilters.EC2TagsToMap(out.SecurityGroupRules[0].Tags), "authorize must echo the tags it stored")
|
||||
|
||||
desc, err := svc.DescribeSecurityGroupRules(context.Background(), &ec2.DescribeSecurityGroupRulesInput{
|
||||
SecurityGroupRuleIds: []*string{aws.String(ruleID)},
|
||||
@@ -2395,7 +2395,7 @@ func TestAuthorizeSecurityGroupIngress_StoresRuleTags(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, desc.SecurityGroupRules, 1)
|
||||
assert.Equal(t, map[string]string{"terraform-aws-modules": "alb"},
|
||||
filterutil.EC2TagsToMap(desc.SecurityGroupRules[0].Tags))
|
||||
awsfilters.EC2TagsToMap(desc.SecurityGroupRules[0].Tags))
|
||||
}
|
||||
|
||||
func TestDescribeSecurityGroupRules_FiltersByTag(t *testing.T) {
|
||||
@@ -2488,7 +2488,7 @@ func TestApplyRecordTags_ReachesASecurityGroupRule(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Len(t, desc.SecurityGroupRules, 1)
|
||||
assert.Equal(t, map[string]string{"Name": "ssh"},
|
||||
filterutil.EC2TagsToMap(desc.SecurityGroupRules[0].Tags))
|
||||
awsfilters.EC2TagsToMap(desc.SecurityGroupRules[0].Tags))
|
||||
|
||||
require.NoError(t, svc.RemoveRecordTags(&ec2.DeleteTagsInput{
|
||||
Resources: []*string{aws.String(ruleID)},
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/mulgadc/spinifex/spinifex/awserrors"
|
||||
"github.com/mulgadc/spinifex/spinifex/config"
|
||||
"github.com/mulgadc/spinifex/spinifex/filterutil"
|
||||
awsfilters "github.com/mulgadc/spinifex/spinifex/foundation/aws/filters"
|
||||
"github.com/mulgadc/spinifex/spinifex/kvutil"
|
||||
"github.com/mulgadc/spinifex/spinifex/migrate"
|
||||
"github.com/mulgadc/spinifex/spinifex/utils"
|
||||
@@ -590,7 +590,7 @@ func (s *VPCServiceImpl) DescribeVpcs(ctx context.Context, input *ec2.DescribeVp
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeVpcsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeVpcsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeVpcs: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -962,7 +962,7 @@ func (s *VPCServiceImpl) DescribeSubnets(ctx context.Context, input *ec2.Describ
|
||||
}
|
||||
}
|
||||
|
||||
parsedFilters, err := filterutil.ParseFilters(input.Filters, describeSubnetsValidFilters)
|
||||
parsedFilters, err := awsfilters.ParseFilters(input.Filters, describeSubnetsValidFilters)
|
||||
if err != nil {
|
||||
slog.WarnContext(ctx, "DescribeSubnets: invalid filter", "err", err)
|
||||
return nil, err
|
||||
@@ -1146,7 +1146,7 @@ func (s *VPCServiceImpl) updateRecordTags(ctx context.Context, accountID, resour
|
||||
return nil
|
||||
}
|
||||
|
||||
// vpcMatchesFilters checks whether a VPCRecord satisfies all parsed filters.
|
||||
// vpcMatchesFilters checks whether a VPCRecord satisfies all parsed awsfilters.
|
||||
func vpcMatchesFilters(record *VPCRecord, accountID string, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -1173,12 +1173,12 @@ func vpcMatchesFilters(record *VPCRecord, accountID string, filters map[string][
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
// describeSubnetsValidFilters defines the set of filter names accepted by DescribeSubnets.
|
||||
@@ -1191,7 +1191,7 @@ var describeSubnetsValidFilters = map[string]bool{
|
||||
"default-for-az": true,
|
||||
}
|
||||
|
||||
// subnetMatchesFilters checks whether a SubnetRecord satisfies all parsed filters.
|
||||
// subnetMatchesFilters checks whether a SubnetRecord satisfies all parsed awsfilters.
|
||||
func subnetMatchesFilters(record *SubnetRecord, filters map[string][]string) bool {
|
||||
for name, values := range filters {
|
||||
if strings.HasPrefix(name, "tag:") {
|
||||
@@ -1216,12 +1216,12 @@ func subnetMatchesFilters(record *SubnetRecord, filters map[string][]string) boo
|
||||
return false
|
||||
}
|
||||
|
||||
if !filterutil.MatchesAny(values, field) {
|
||||
if !awsfilters.MatchesAny(values, field) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return filterutil.MatchesTags(filters, record.Tags)
|
||||
return awsfilters.MatchesTags(filters, record.Tags)
|
||||
}
|
||||
|
||||
func (s *VPCServiceImpl) vpcRecordToEC2(record *VPCRecord, accountID string) *ec2.Vpc {
|
||||
|
||||
Reference in New Issue
Block a user