// Filter is part of the filter.Filterable interface func (a *AutoScalingGroup) Filter(filter filters.Filter) bool { matched := false // map function names to function calls switch filter.Function { case "SizeGreaterThan": if i, err := filter.Int64Value(0); err == nil && a.sizeGreaterThan(i) { matched = true } case "SizeLessThan": if i, err := filter.Int64Value(0); err == nil && a.sizeLessThan(i) { matched = true } case "SizeEqualTo": if i, err := filter.Int64Value(0); err == nil && a.sizeEqualTo(i) { matched = true } case "SizeLessThanOrEqualTo": if i, err := filter.Int64Value(0); err == nil && a.sizeLessThanOrEqualTo(i) { matched = true } case "SizeGreaterThanOrEqualTo": if i, err := filter.Int64Value(0); err == nil && a.sizeGreaterThanOrEqualTo(i) { matched = true } case "CreatedTimeInTheLast": d, err := time.ParseDuration(filter.Arguments[0]) if err == nil && a.CreatedTime != nil && time.Since(*a.CreatedTime) < d { matched = true } case "CreatedTimeNotInTheLast": d, err := time.ParseDuration(filter.Arguments[0]) if err == nil && a.CreatedTime != nil && time.Since(*a.CreatedTime) > d { matched = true } case "InCloudformation": if b, err := filter.BoolValue(0); err == nil && a.IsInCloudformation == b { matched = true } case "Region": for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { matched = true } } case "NotRegion": // was this resource's region one of those in the NOT list regionSpecified := false for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { regionSpecified = true } } if !regionSpecified { matched = true } case "Tagged": if a.Tagged(filter.Arguments[0]) { matched = true } case "NotTagged": if !a.Tagged(filter.Arguments[0]) { matched = true } case "TagNotEqual": if a.Tag(filter.Arguments[0]) != filter.Arguments[1] { matched = true } case "ReaperState": if a.reaperState.State.String() == filter.Arguments[0] { matched = true } case "NotReaperState": if a.reaperState.State.String() != filter.Arguments[0] { matched = true } case "Named": if a.Name == filter.Arguments[0] { matched = true } case "NotNamed": if a.Name != filter.Arguments[0] { matched = true } case "IsDependency": if b, err := filter.BoolValue(0); err == nil && a.Dependency == b { matched = true } case "NameContains": if strings.Contains(a.Name, filter.Arguments[0]) { matched = true } case "NotNameContains": if !strings.Contains(a.Name, filter.Arguments[0]) { matched = true } default: log.Error(fmt.Sprintf("No function %s could be found for filtering AutoScalingGroups.", filter.Function)) } return matched }
// Filter is part of the filter.Filterable interface func (a *Cloudformation) Filter(filter filters.Filter) bool { matched := false // map function names to function calls switch filter.Function { case "Status": if a.StackStatus != nil && *a.StackStatus == filter.Arguments[0] { // one of: // CREATE_COMPLETE // CREATE_IN_PROGRESS // CREATE_FAILED // DELETE_COMPLETE // DELETE_FAILED // DELETE_IN_PROGRESS // ROLLBACK_COMPLETE // ROLLBACK_FAILED // ROLLBACK_IN_PROGRESS // UPDATE_COMPLETE // UPDATE_COMPLETE_CLEANUP_IN_PROGRESS // UPDATE_IN_PROGRESS // UPDATE_ROLLBACK_COMPLETE // UPDATE_ROLLBACK_COMPLETE_CLEANUP_IN_PROGRESS // UPDATE_ROLLBACK_FAILED // UPDATE_ROLLBACK_IN_PROGRESS matched = true } case "NotStatus": if a.StackStatus != nil && *a.StackStatus != filter.Arguments[0] { matched = true } case "CreatedTimeInTheLast": d, err := time.ParseDuration(filter.Arguments[0]) if err == nil && a.CreationTime != nil && time.Since(*a.CreationTime) < d { matched = true } case "CreatedTimeNotInTheLast": d, err := time.ParseDuration(filter.Arguments[0]) if err == nil && a.CreationTime != nil && time.Since(*a.CreationTime) > d { matched = true } case "Region": for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { matched = true } } case "NotRegion": // was this resource's region one of those in the NOT list regionSpecified := false for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { regionSpecified = true } } if !regionSpecified { matched = true } case "Tagged": if a.Tagged(filter.Arguments[0]) { matched = true } case "NotTagged": if !a.Tagged(filter.Arguments[0]) { matched = true } case "TagNotEqual": if a.Tag(filter.Arguments[0]) != filter.Arguments[1] { matched = true } case "ReaperState": if a.reaperState.State.String() == filter.Arguments[0] { matched = true } case "NotReaperState": if a.reaperState.State.String() != filter.Arguments[0] { matched = true } case "Named": if a.Name == filter.Arguments[0] { matched = true } case "NotNamed": if a.Name != filter.Arguments[0] { matched = true } case "IsDependency": if b, err := filter.BoolValue(0); err == nil && a.Dependency == b { matched = true } case "NameContains": if strings.Contains(a.Name, filter.Arguments[0]) { matched = true } case "NotNameContains": if !strings.Contains(a.Name, filter.Arguments[0]) { matched = true } default: log.Error(fmt.Sprintf("No function %s could be found for filtering Cloudformations.", filter.Function)) } return matched }
// Filter is part of the filter.Filterable interface func (a *SecurityGroup) Filter(filter filters.Filter) bool { matched := false // map function names to function calls switch filter.Function { case "InCloudformation": if b, err := filter.BoolValue(0); err == nil && a.IsInCloudformation == b { matched = true } case "Region": for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { matched = true } } case "NotRegion": // was this resource's region one of those in the NOT list regionSpecified := false for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { regionSpecified = true } } if !regionSpecified { matched = true } case "Tagged": if a.Tagged(filter.Arguments[0]) { matched = true } case "NotTagged": if !a.Tagged(filter.Arguments[0]) { matched = true } case "TagNotEqual": if a.Tag(filter.Arguments[0]) != filter.Arguments[1] { matched = true } case "ReaperState": if a.reaperState.State.String() == filter.Arguments[0] { matched = true } case "NotReaperState": if a.reaperState.State.String() != filter.Arguments[0] { matched = true } case "Named": if a.Name == filter.Arguments[0] { matched = true } case "NotNamed": if a.Name != filter.Arguments[0] { matched = true } case "IsDependency": if b, err := filter.BoolValue(0); err == nil && a.Dependency == b { matched = true } case "NameContains": if strings.Contains(a.Name, filter.Arguments[0]) { matched = true } case "NotNameContains": if !strings.Contains(a.Name, filter.Arguments[0]) { matched = true } default: log.Error(fmt.Sprintf("No function %s could be found for filtering SecurityGroups.", filter.Function)) } return matched }
func (a *Instance) Filter(filter filters.Filter) bool { matched := false // map function names to function calls switch filter.Function { case "State": if a.State != nil && *a.State.Name == filter.Arguments[0] { matched = true } case "InstanceType": if a.InstanceType != nil && *a.InstanceType == filter.Arguments[0] { matched = true } case "HasPublicIpAddress": if b, err := filter.BoolValue(0); err == nil && b == (a.PublicIpAddress != nil) { matched = true } case "PublicIpAddress": if a.PublicIpAddress != nil && *a.PublicIpAddress == filter.Arguments[0] { matched = true } case "InCloudformation": if b, err := filter.BoolValue(0); err == nil && a.IsInCloudformation == b { matched = true } case "AutoScaled": if b, err := filter.BoolValue(0); err == nil && a.AutoScaled == b { matched = true } // uses RFC3339 format // https://www.ietf.org/rfc/rfc3339.txt case "LaunchTimeBefore": t, err := time.Parse(time.RFC3339, filter.Arguments[0]) if err == nil && a.LaunchTime != nil && t.After(*a.LaunchTime) { matched = true } case "LaunchTimeAfter": t, err := time.Parse(time.RFC3339, filter.Arguments[0]) if err == nil && a.LaunchTime != nil && t.Before(*a.LaunchTime) { matched = true } case "LaunchTimeInTheLast": d, err := time.ParseDuration(filter.Arguments[0]) if err == nil && a.LaunchTime != nil && time.Since(*a.LaunchTime) < d { matched = true } case "LaunchTimeNotInTheLast": d, err := time.ParseDuration(filter.Arguments[0]) if err == nil && a.LaunchTime != nil && time.Since(*a.LaunchTime) > d { matched = true } case "Region": for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { matched = true } } case "NotRegion": // was this resource's region one of those in the NOT list regionSpecified := false for _, region := range filter.Arguments { if a.Region() == reapable.Region(region) { regionSpecified = true } } if !regionSpecified { matched = true } case "Tagged": if a.Tagged(filter.Arguments[0]) { matched = true } case "NotTagged": if !a.Tagged(filter.Arguments[0]) { matched = true } case "TagNotEqual": if a.Tag(filter.Arguments[0]) != filter.Arguments[1] { matched = true } case "ReaperState": if a.reaperState.State.String() == filter.Arguments[0] { matched = true } case "NotReaperState": if a.reaperState.State.String() != filter.Arguments[0] { matched = true } case "Named": if a.Name == filter.Arguments[0] { matched = true } case "NotNamed": if a.Name != filter.Arguments[0] { matched = true } case "IsDependency": if b, err := filter.BoolValue(0); err == nil && a.Dependency == b { matched = true } case "NameContains": if strings.Contains(a.Name, filter.Arguments[0]) { matched = true } case "NotNameContains": if !strings.Contains(a.Name, filter.Arguments[0]) { matched = true } default: log.Error(fmt.Sprintf("No function %s could be found for filtering Instances.", filter.Function)) } return matched }