-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfilter.go
More file actions
73 lines (59 loc) · 1.73 KB
/
filter.go
File metadata and controls
73 lines (59 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package stackit
import (
"github.com/stackitcloud/stackit-sdk-go/services/iaas"
)
// TODO: Remove this once the IaaS API supports filtering by name, status, and volume ID.
//nolint:dupl // We don't feel like doing generics to undupe this.
func filterBackups(backups []iaas.Backup, filters map[string]string) []iaas.Backup {
filteredBackups := make([]iaas.Backup, 0)
if filters == nil {
return backups
}
for _, obj := range backups {
if val, ok := filters["Status"]; ok && val != obj.GetStatus() {
continue
}
if val, ok := filters["VolumeID"]; ok && val != obj.GetVolumeId() {
continue
}
if val, ok := filters["Name"]; ok && val != obj.GetName() {
continue
}
filteredBackups = append(filteredBackups, obj)
}
return filteredBackups
}
func filterVolumes(volumes []iaas.Volume, filters map[string]string) []iaas.Volume {
filteredVolumes := make([]iaas.Volume, 0)
if filters == nil {
return volumes
}
for i := range volumes {
volume := &volumes[i]
if val, ok := filters["Name"]; ok && val != volume.GetName() {
continue
}
filteredVolumes = append(filteredVolumes, *volume)
}
return filteredVolumes
}
//nolint:dupl // We don't feel like doing generics to undupe this.
func filterSnapshots(snapshots []iaas.Snapshot, filters map[string]string) []iaas.Snapshot {
filteredSnapshots := make([]iaas.Snapshot, 0)
if filters == nil {
return snapshots
}
for _, obj := range snapshots {
if val, ok := filters["Status"]; ok && val != obj.GetStatus() {
continue
}
if val, ok := filters["VolumeID"]; ok && val != obj.GetVolumeId() {
continue
}
if val, ok := filters["Name"]; ok && val != obj.GetName() {
continue
}
filteredSnapshots = append(filteredSnapshots, obj)
}
return filteredSnapshots
}