storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/pkg/bucket/replication/tag.go (about)

     1  /*
     2   * MinIO Cloud Storage, (C) 2020 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package replication
    18  
    19  import (
    20  	"encoding/xml"
    21  	"unicode/utf8"
    22  )
    23  
    24  // Tag - a tag for a replication configuration Rule filter.
    25  type Tag struct {
    26  	XMLName xml.Name `xml:"Tag" json:"Tag"`
    27  	Key     string   `xml:"Key,omitempty" json:"Key,omitempty"`
    28  	Value   string   `xml:"Value,omitempty" json:"Value,omitempty"`
    29  }
    30  
    31  var (
    32  	errInvalidTagKey   = Errorf("The TagKey you have provided is invalid")
    33  	errInvalidTagValue = Errorf("The TagValue you have provided is invalid")
    34  )
    35  
    36  func (tag Tag) String() string {
    37  	return tag.Key + "=" + tag.Value
    38  }
    39  
    40  // IsEmpty returns whether this tag is empty or not.
    41  func (tag Tag) IsEmpty() bool {
    42  	return tag.Key == ""
    43  }
    44  
    45  // Validate checks this tag.
    46  func (tag Tag) Validate() error {
    47  	if len(tag.Key) == 0 || utf8.RuneCountInString(tag.Key) > 128 {
    48  		return errInvalidTagKey
    49  	}
    50  
    51  	if utf8.RuneCountInString(tag.Value) > 256 {
    52  		return errInvalidTagValue
    53  	}
    54  
    55  	return nil
    56  }