-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathresource.go
54 lines (43 loc) · 1.33 KB
/
resource.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
54
package nuke
import (
"fmt"
liberror "github.com/ekristen/libnuke/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/api/option"
"slices"
"github.com/ekristen/libnuke/pkg/registry"
)
type Geography string
const (
Workspace registry.Scope = "workspace"
Organization registry.Scope = "organization"
Project registry.Scope = "project"
Global Geography = "global"
Regional Geography = "regional"
Zonal Geography = "zonal"
)
type ListerOpts struct {
Project *string
Region *string
Zones []string
EnabledAPIs []string
ClientOptions []option.ClientOption
}
func (o *ListerOpts) BeforeList(geo Geography, service string) error {
log := logrus.WithField("geo", geo).
WithField("service", service).
WithField("hooke", "true")
if geo == Global && *o.Region != "global" {
log.Trace("before-list: skipping resource, global")
return liberror.ErrSkipRequest("resource is global")
} else if geo == Regional && *o.Region == "global" {
log.Trace("before-list: skipping resource, regional")
return liberror.ErrSkipRequest("resource is regional")
}
if !slices.Contains(o.EnabledAPIs, service) {
log.Trace("before-list: skipping resource, api not enabled")
return liberror.ErrSkipRequest(fmt.Sprintf("api '%s' not enabled", service))
}
log.Trace("before-list: called")
return nil
}