Skip to content

Commit

Permalink
feat: allow renaming of tag prefix to label to match gcp nomenclature
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jun 5, 2024
1 parent f3db7d9 commit 250253f
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 29 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.22

require (
cloud.google.com/go/compute v1.26.0
github.com/ekristen/libnuke v0.14.3-0.20240516175134-d8cbc29baf7e
github.com/ekristen/libnuke v0.14.3-0.20240604222203-e5306c7eb43c
github.com/fatih/color v1.17.0
github.com/gotidy/ptr v1.4.0
github.com/sirupsen/logrus v1.9.3
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ github.com/ekristen/libnuke v0.14.3-0.20240514022239-6fae2a990fdf h1:iPlsTjfmQmh
github.com/ekristen/libnuke v0.14.3-0.20240514022239-6fae2a990fdf/go.mod h1:riI1tjCf6r+et/9oUBd1vQeFmn2Sn6UeFUR0nWkMeYw=
github.com/ekristen/libnuke v0.14.3-0.20240516175134-d8cbc29baf7e h1:KM3VOQ/ZsMdlug3I2dvLvqkguC0KZwejm2cJKzWDhHE=
github.com/ekristen/libnuke v0.14.3-0.20240516175134-d8cbc29baf7e/go.mod h1:riI1tjCf6r+et/9oUBd1vQeFmn2Sn6UeFUR0nWkMeYw=
github.com/ekristen/libnuke v0.14.3-0.20240604221149-91349c827795 h1:LBUgoQ7Ua1M+d8qTDpP+4+AZwjtfEaTfrARq2mo5q94=
github.com/ekristen/libnuke v0.14.3-0.20240604221149-91349c827795/go.mod h1:riI1tjCf6r+et/9oUBd1vQeFmn2Sn6UeFUR0nWkMeYw=
github.com/ekristen/libnuke v0.14.3-0.20240604222203-e5306c7eb43c h1:yuxVGeAzX5O4IlESpT585doZmIKzwiHDsgse2E3jx0s=
github.com/ekristen/libnuke v0.14.3-0.20240604222203-e5306c7eb43c/go.mod h1:riI1tjCf6r+et/9oUBd1vQeFmn2Sn6UeFUR0nWkMeYw=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
Expand Down
13 changes: 7 additions & 6 deletions pkg/commands/run/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ func execute(c *cli.Context) error {
logrus.Trace("preparing to run nuke")

params := &libnuke.Parameters{
Force: c.Bool("no-prompt"),
ForceSleep: c.Int("prompt-delay"),
Quiet: c.Bool("quiet"),
NoDryRun: c.Bool("no-dry-run"),
Includes: c.StringSlice("include"),
Excludes: c.StringSlice("exclude"),
Force: c.Bool("no-prompt"),
ForceSleep: c.Int("prompt-delay"),
Quiet: c.Bool("quiet"),
NoDryRun: c.Bool("no-dry-run"),
Includes: c.StringSlice("include"),
Excludes: c.StringSlice("exclude"),
WaitOnDependencies: true,
}

parsedConfig, err := libconfig.New(libconfig.Options{
Expand Down
19 changes: 9 additions & 10 deletions resources/cloud-function.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ func (l *CloudFunctionLister) List(ctx context.Context, o interface{}) ([]resour
return nil, err
}

// TODO: determine locations, cache and skip locations not supported
it := l.svc.ListLocations(ctx, &location.ListLocationsRequest{
Name: fmt.Sprintf("projects/%s", *opts.Project),
})
Expand Down Expand Up @@ -102,10 +101,10 @@ func (l *CloudFunctionLister) List(ctx context.Context, o interface{}) ([]resour

resources = append(resources, &CloudFunction{
svc: l.svc,
FullName: ptr.String(resp.Name),
project: opts.Project,
region: opts.Region,
fullName: ptr.String(resp.Name),
Name: ptr.String(name),
Project: opts.Project,
Region: opts.Region,
Labels: resp.Labels,
Status: ptr.String(resp.Status.String()),
})
Expand All @@ -117,17 +116,17 @@ func (l *CloudFunctionLister) List(ctx context.Context, o interface{}) ([]resour
type CloudFunction struct {
svc *functions.CloudFunctionsClient
removeOp *functions.DeleteFunctionOperation
Project *string
Region *string
FullName *string `property:"-"`
Name *string `property:"Name"`
project *string
region *string
fullName *string
Name *string
Status *string
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
}

func (r *CloudFunction) Remove(ctx context.Context) (err error) {
r.removeOp, err = r.svc.DeleteFunction(ctx, &functionspb.DeleteFunctionRequest{
Name: *r.FullName,
Name: *r.fullName,
})
if err != nil && strings.Contains(err.Error(), "proto") && strings.Contains(err.Error(), "missing") {
err = nil
Expand Down
6 changes: 3 additions & 3 deletions resources/cloud-function2.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ type CloudFunction2 struct {
removeOp *functions.DeleteFunctionOperation
Project *string
Region *string
FullName *string `property:"-"`
Name *string `property:"Name"`
Labels map[string]string
FullName *string `property:"-"`
Name *string `property:"Name"`
Labels map[string]string `property:"tagPrefix=label"`
State *string
}

Expand Down
2 changes: 1 addition & 1 deletion resources/cloud-run.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type CloudRun struct {
Region *string
FullName *string
Name *string
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
}

func (r *CloudRun) Filter() error {
Expand Down
2 changes: 1 addition & 1 deletion resources/cloud-sql-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type CloudSQLInstance struct {
region *string
Name *string
State *string
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
CreationDate *string
DatabaseVersion *string

Expand Down
2 changes: 1 addition & 1 deletion resources/compute-common-instance-metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ type ComputeCommonInstanceMetadata struct {
removeOp *compute.Operation
project *string
Fingerprint *string
Items []*computepb.Items
Items []*computepb.Items `property:"tagPrefix=item"`
}

func (r *ComputeCommonInstanceMetadata) Filter() error {
Expand Down
2 changes: 1 addition & 1 deletion resources/compute-disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ type ComputeDisk struct {
Arch *string
Size *int64
Type *string
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
}

func (r *ComputeDisk) Remove(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion resources/compute-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ type ComputeInstance struct {
Name *string
Zone *string
CreationTimestamp *string
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
}

func (r *ComputeInstance) Remove(ctx context.Context) error {
Expand Down
5 changes: 3 additions & 2 deletions resources/iam-policy-binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,9 @@ func (r *IAMPolicyBinding) Remove(ctx context.Context) error {
for _, binding := range policy.Bindings {
if binding.Role == r.Role {
for i, member := range binding.Members {
if member == r.Member {
// remove current index from slice
// if the member matches specifically, or if the member is a deleted member
// was set to be removed initially, then we are going to remove it now.
if member == r.Member || member == fmt.Sprintf("deleted:%s", r.Member) {
binding.Members = append(binding.Members[:i], binding.Members[i+1:]...)
}
}
Expand Down
4 changes: 4 additions & 0 deletions resources/iam-service-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func init() {
Settings: []string{
"DeleteDefaultServiceAccounts",
},
DependsOn: []string{
IAMServiceAccountKeyResource,
IAMPolicyBindingResource,
},
})
}

Expand Down
2 changes: 1 addition & 1 deletion resources/secretmanager-secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type SecretManagerSecret struct {
fullName *string
Name *string
CreateTime time.Time
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
}

func (r *SecretManagerSecret) Remove(ctx context.Context) error {
Expand Down
2 changes: 1 addition & 1 deletion resources/storage-bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ type StorageBucket struct {
project *string
region *string
Name *string
Labels map[string]string
Labels map[string]string `property:"tagPrefix=label"`
MultiRegion *bool
}

Expand Down

0 comments on commit 250253f

Please sign in to comment.