MCPcopy
hub / github.com/minio/minio-go / newObjectLockConfig

Function newObjectLockConfig

api-object-lock.go:102–139  ·  view source on GitHub ↗
(mode *RetentionMode, validity *uint, unit *ValidityUnit)

Source from the content-addressed store, hash-verified

100}
101
102func newObjectLockConfig(mode *RetentionMode, validity *uint, unit *ValidityUnit) (*objectLockConfig, error) {
103 config := &objectLockConfig{
104 ObjectLockEnabled: "Enabled",
105 }
106
107 if mode != nil && validity != nil && unit != nil {
108 if !mode.IsValid() {
109 return nil, fmt.Errorf("invalid retention mode `%v`", mode)
110 }
111
112 if !unit.isValid() {
113 return nil, fmt.Errorf("invalid validity unit `%v`", unit)
114 }
115
116 config.Rule = &struct {
117 DefaultRetention struct {
118 Mode RetentionMode `xml:"Mode"`
119 Days *uint `xml:"Days"`
120 Years *uint `xml:"Years"`
121 } `xml:"DefaultRetention"`
122 }{}
123
124 config.Rule.DefaultRetention.Mode = *mode
125 if *unit == Days {
126 config.Rule.DefaultRetention.Days = validity
127 } else {
128 config.Rule.DefaultRetention.Years = validity
129 }
130
131 return config, nil
132 }
133
134 if mode == nil && validity == nil && unit == nil {
135 return config, nil
136 }
137
138 return nil, fmt.Errorf("all of retention mode, validity and validity unit must be passed")
139}
140
141// SetBucketObjectLockConfig sets object lock configuration in given bucket. mode, validity and unit are either all set or all nil.
142func (c *Client) SetBucketObjectLockConfig(ctx context.Context, bucketName string, mode *RetentionMode, validity *uint, unit *ValidityUnit) error {

Callers 1

Calls 2

isValidMethod · 0.80
IsValidMethod · 0.45

Tested by

no test coverage detected