-
Notifications
You must be signed in to change notification settings - Fork 23
/
ns_groups.go
53 lines (41 loc) · 1.03 KB
/
ns_groups.go
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
package groupingobjects
import (
"context"
"fmt"
"strings"
"github.com/genevieve/leftovers/common"
)
type NSGroups struct {
client groupingObjectsAPI
ctx context.Context
logger logger
}
func NewNSGroups(client groupingObjectsAPI, ctx context.Context, logger logger) NSGroups {
return NSGroups{
client: client,
ctx: ctx,
logger: logger,
}
}
func (n NSGroups) List(filter string) ([]common.Deletable, error) {
result, _, err := n.client.ListNSGroups(n.ctx, map[string]interface{}{})
if err != nil {
return []common.Deletable{}, fmt.Errorf("List NS Groups: %s", err)
}
var resources []common.Deletable
for _, nsGroup := range result.Results {
resource := NewNSGroup(n.client, n.ctx, nsGroup.DisplayName, nsGroup.Id)
if !strings.Contains(nsGroup.DisplayName, filter) {
continue
}
proceed := n.logger.PromptWithDetails(resource.Type(), resource.Name())
if !proceed {
continue
}
resources = append(resources, resource)
}
return resources, nil
}
func (i NSGroups) Type() string {
return "NS Group"
}