Skip to content

Commit

Permalink
Merge pull request #4400 from hashicorp/backport/louis-policies-api/n…
Browse files Browse the repository at this point in the history
…eatly-stirred-woodcock

This pull request was automerged via backport-assistant
  • Loading branch information
hc-github-team-secure-boundary authored Feb 13, 2024
2 parents c2873ad + 5f89417 commit fde8302
Show file tree
Hide file tree
Showing 9 changed files with 288 additions and 144 deletions.
201 changes: 201 additions & 0 deletions api/policies/custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
package policies

const (
attributesField = "attributes"
deleteAfterField = "delete_after"
retainForField = "retain_for"
daysField = "days"
overridableField = "overridable"
)

func WithStoragePolicyDeleteAfter(inDeleteAfter map[string]any) Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val[deleteAfterField] = inDeleteAfter
o.postMap[attributesField] = val
}
}

func DefaultStoragePolicyDeleteAfter() Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val[deleteAfterField] = nil
o.postMap[attributesField] = val
}
}

func WithStoragePolicyDeleteAfterDays(inDays int32) Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[deleteAfterField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[daysField] = inDays
val[deleteAfterField] = deleteAfter
o.postMap[attributesField] = val
}
}

func DefaultStoragePolicyDeleteAfterDays() Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[deleteAfterField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[daysField] = 0
val[deleteAfterField] = deleteAfter
o.postMap[attributesField] = val
}
}

func WithStoragePolicyDeleteAfterOverridable(inOverridable bool) Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[deleteAfterField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[overridableField] = inOverridable
val[deleteAfterField] = deleteAfter
o.postMap[attributesField] = val
}
}

func DefaultStoragePolicyDeleteAfterOverridable() Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[deleteAfterField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[overridableField] = false
val[deleteAfterField] = deleteAfter
o.postMap[attributesField] = val
}
}

func WithStoragePolicyRetainFor(inDeleteAfter map[string]any) Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val[retainForField] = inDeleteAfter
o.postMap[attributesField] = val
}
}

func DefaultStoragePolicyRetainFor() Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val[retainForField] = nil
o.postMap[attributesField] = val
}
}

func WithStoragePolicyRetainForDays(inDays int32) Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[retainForField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[daysField] = inDays
val[retainForField] = deleteAfter
o.postMap[attributesField] = val
}
}

func DefaultStoragePolicyRetainForDays() Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[retainForField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[daysField] = 0
val[retainForField] = deleteAfter
o.postMap[attributesField] = val
}
}

func WithStoragePolicyRetainForOverridable(inOverridable bool) Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[retainForField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[overridableField] = inOverridable
val[retainForField] = deleteAfter
o.postMap[attributesField] = val
}
}

func DefaultStoragePolicyRetainForOverridable() Option {
return func(o *options) {
raw, ok := o.postMap[attributesField]
if !ok {
raw = interface{}(map[string]any{})
}
val := raw.(map[string]any)
rawDeleteAfter, ok := val[retainForField]
if !ok {
rawDeleteAfter = interface{}(map[string]any{})
}
deleteAfter := rawDeleteAfter.(map[string]any)
deleteAfter[overridableField] = false
val[retainForField] = deleteAfter
o.postMap[attributesField] = val
}
}
48 changes: 0 additions & 48 deletions api/policies/option.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions api/policies/storage_policy_attributes.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions api/policies/storage_policy_delete_after.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions api/policies/storage_policy_retain_for.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 9 additions & 13 deletions internal/api/genapi/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,25 +759,21 @@ var inputStructs = []*structInfo{
},

// Policy-related resources.
{
inProto: &policies.StoragePolicyDeleteAfter{},
outFile: "policies/storage_policy_delete_after.gen.go",
},
{
inProto: &policies.StoragePolicyRetainFor{},
outFile: "policies/storage_policy_retain_for.gen.go",
},
{
inProto: &policies.StoragePolicyAttributes{},
outFile: "policies/storage_policy_attributes.gen.go",
parentTypeName: "Policy",
subtypeName: "StoragePolicy",
subtype: "storage",
fieldOverrides: []fieldInfo{
{
Name: "RetainFor",
ProtoName: "retain_for",
FieldType: "map[string]any",
},
{
Name: "DeleteAfter",
ProtoName: "delete_after",
FieldType: "map[string]any",
},
},
templates: []*template.Template{mapstructureConversionTemplate},
templates: []*template.Template{mapstructureConversionTemplate},
},
{
inProto: &policies.Policy{},
Expand Down
Loading

0 comments on commit fde8302

Please sign in to comment.