mirror of
https://github.com/minio/minio.git
synced 2025-11-07 12:52:58 -05:00
Add support for Object Tagging in LifeCycle configuration (#8880)
Fixes #8870 Co-Authored-By: Krishnan Parthasarathi <krisis@users.noreply.github.com>
This commit is contained in:
@@ -18,14 +18,15 @@ package tagging
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Tag - single tag
|
||||
type Tag struct {
|
||||
XMLName xml.Name `xml:"Tag"`
|
||||
Key string `xml:"Key"`
|
||||
Value string `xml:"Value"`
|
||||
Key string `xml:"Key,omitempty"`
|
||||
Value string `xml:"Value,omitempty"`
|
||||
}
|
||||
|
||||
// Validate - validates the tag element
|
||||
@@ -49,6 +50,10 @@ func (t Tag) validateKey() error {
|
||||
if len(t.Key) == 0 {
|
||||
return ErrInvalidTagKey
|
||||
}
|
||||
// Tag key shouldn't have "&"
|
||||
if strings.Contains(t.Key, "&") {
|
||||
return ErrInvalidTagKey
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -58,5 +63,20 @@ func (t Tag) validateValue() error {
|
||||
if utf8.RuneCountInString(t.Value) > maxTagValueLength {
|
||||
return ErrInvalidTagValue
|
||||
}
|
||||
// Tag value shouldn't have "&"
|
||||
if strings.Contains(t.Value, "&") {
|
||||
return ErrInvalidTagValue
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// IsEmpty - checks if tag is empty or not
|
||||
func (t Tag) IsEmpty() bool {
|
||||
return t.Key == "" && t.Value == ""
|
||||
}
|
||||
|
||||
// String - returns a string in format "tag1=value1" for the
|
||||
// current Tag
|
||||
func (t Tag) String() string {
|
||||
return t.Key + "=" + t.Value
|
||||
}
|
||||
|
||||
@@ -51,11 +51,11 @@ func (t Tagging) Validate() error {
|
||||
if len(t.TagSet.Tags) > maxTags {
|
||||
return ErrTooManyTags
|
||||
}
|
||||
if t.TagSet.ContainsDuplicateTag() {
|
||||
return ErrInvalidTag
|
||||
}
|
||||
// Validate all the rules in the tagging config
|
||||
for _, ts := range t.TagSet.Tags {
|
||||
if t.TagSet.ContainsDuplicate(ts.Key) {
|
||||
return ErrInvalidTag
|
||||
}
|
||||
if err := ts.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -71,8 +71,7 @@ func (t Tagging) String() string {
|
||||
if buf.Len() > 0 {
|
||||
buf.WriteString("&")
|
||||
}
|
||||
buf.WriteString(tag.Key + "=")
|
||||
buf.WriteString(tag.Value)
|
||||
buf.WriteString(tag.String())
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
@@ -26,16 +26,16 @@ type TagSet struct {
|
||||
Tags []Tag `xml:"Tag"`
|
||||
}
|
||||
|
||||
// ContainsDuplicate - returns true if duplicate keys are present in TagSet
|
||||
func (t TagSet) ContainsDuplicate(key string) bool {
|
||||
var found bool
|
||||
for _, tag := range t.Tags {
|
||||
if tag.Key == key {
|
||||
if found {
|
||||
return true
|
||||
}
|
||||
found = true
|
||||
// ContainsDuplicateTag - returns true if duplicate keys are present in TagSet
|
||||
func (t TagSet) ContainsDuplicateTag() bool {
|
||||
x := make(map[string]struct{}, len(t.Tags))
|
||||
|
||||
for _, t := range t.Tags {
|
||||
if _, has := x[t.Key]; has {
|
||||
return true
|
||||
}
|
||||
x[t.Key] = struct{}{}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user