ekristen / libnuke

Common Golang Packages for use by the Various Cloud Nuke Tools
MIT License
22 stars 3 forks source link

feat: properties from struct #45

Closed ekristen closed 4 months ago

ekristen commented 5 months ago

Overview

This is laying the groundwork for allowing the aws-nuke and azure-nuke tool to update their Resource definitions to have exported variables that are then used to build the properties automatically vs having to define them manually.

There are two benefits to this, the first being that we can make the code cleaner and more simple by removing a bunch of for loops for tags, but we can also now programmatically generate documentation by inspecting the resource structs to document what properties are available.

This might make the resource structs get a little more verbose, but in the end, it'll make the use of the tool better.

Type Support

Note: all pointers are dereferenced during evaluation

Features

Example

type ResourceGroup struct {
  client *client
  Name string
  Region *string
  Tags map[string]string
}

types.NewPropertiesFromStruct(&ResourceGroup{
  Name: "example"
  Region: ptr.String("eastus")
  Tags: map[string]string{"key": "value"}
})

This automatically will create properties for Name, Region and Tags.

[Name: "example", Region: "eastus", tag:key: "value"]

Benchmark

goos: darwin
goarch: amd64
pkg: github.com/ekristen/libnuke/pkg/types
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkNewProperties
BenchmarkNewProperties-16                        2815178           412.1 ns/op
BenchmarkNewPropertiesFromStruct_Simple
BenchmarkNewPropertiesFromStruct_Simple-16       1786765           680.6 ns/op
BenchmarkNewPropertiesFromStruct_Complex
BenchmarkNewPropertiesFromStruct_Complex-16       679848          1702 ns/op
PASS
ok      github.com/ekristen/libnuke/pkg/types   4.869s
codecov[bot] commented 5 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 95.62%. Comparing base (9c84ff2) to head (711dac1).

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #45 +/- ## ========================================== + Coverage 95.09% 95.62% +0.53% ========================================== Files 15 16 +1 Lines 897 1006 +109 ========================================== + Hits 853 962 +109 Misses 26 26 Partials 18 18 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

ekristen commented 4 months ago

:tada: This pull request is included in version 0.14.0 :tada:

The release is available on GitHub release :rocket: