Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport of feat(policies): Update SDK/API to support setting/clearing attributes into release/0.15.x #4400

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading