forked from forgejo/forgejo
Vendor Update Go Libs (#13166)
* update github.com/alecthomas/chroma v0.8.0 -> v0.8.1 * github.com/blevesearch/bleve v1.0.10 -> v1.0.12 * editorconfig-core-go v2.1.1 -> v2.3.7 * github.com/gliderlabs/ssh v0.2.2 -> v0.3.1 * migrate editorconfig.ParseBytes to Parse * github.com/shurcooL/vfsgen to 0d455de96546 * github.com/go-git/go-git/v5 v5.1.0 -> v5.2.0 * github.com/google/uuid v1.1.1 -> v1.1.2 * github.com/huandu/xstrings v1.3.0 -> v1.3.2 * github.com/klauspost/compress v1.10.11 -> v1.11.1 * github.com/markbates/goth v1.61.2 -> v1.65.0 * github.com/mattn/go-sqlite3 v1.14.0 -> v1.14.4 * github.com/mholt/archiver v3.3.0 -> v3.3.2 * github.com/microcosm-cc/bluemonday 4f7140c49acb -> v1.0.4 * github.com/minio/minio-go v7.0.4 -> v7.0.5 * github.com/olivere/elastic v7.0.9 -> v7.0.20 * github.com/urfave/cli v1.20.0 -> v1.22.4 * github.com/prometheus/client_golang v1.1.0 -> v1.8.0 * github.com/xanzy/go-gitlab v0.37.0 -> v0.38.1 * mvdan.cc/xurls v2.1.0 -> v2.2.0 Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
parent
91f2afdb54
commit
12a1f914f4
656 changed files with 52967 additions and 25229 deletions
216
vendor/github.com/minio/minio-go/v7/pkg/replication/replication.go
generated
vendored
216
vendor/github.com/minio/minio-go/v7/pkg/replication/replication.go
generated
vendored
|
@ -53,7 +53,10 @@ type Options struct {
|
|||
Priority string
|
||||
TagString string
|
||||
StorageClass string
|
||||
Arn string
|
||||
RoleArn string
|
||||
DestBucket string
|
||||
IsTagSet bool
|
||||
IsSCSet bool
|
||||
}
|
||||
|
||||
// Tags returns a slice of tags for a rule
|
||||
|
@ -89,6 +92,24 @@ func (c *Config) Empty() bool {
|
|||
// AddRule adds a new rule to existing replication config. If a rule exists with the
|
||||
// same ID, then the rule is replaced.
|
||||
func (c *Config) AddRule(opts Options) error {
|
||||
priority, err := strconv.Atoi(opts.Priority)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if opts.RoleArn != c.Role && c.Role != "" {
|
||||
return fmt.Errorf("Role ARN does not match existing configuration")
|
||||
}
|
||||
var status Status
|
||||
// toggle rule status for edit option
|
||||
switch opts.RuleStatus {
|
||||
case "enable":
|
||||
status = Enabled
|
||||
case "disable":
|
||||
status = Disabled
|
||||
default:
|
||||
return fmt.Errorf("Rule state should be either [enable|disable]")
|
||||
}
|
||||
|
||||
tags := opts.Tags()
|
||||
andVal := And{
|
||||
Tags: opts.Tags(),
|
||||
|
@ -103,32 +124,33 @@ func (c *Config) AddRule(opts Options) error {
|
|||
filter.And = andVal
|
||||
filter.And.Prefix = opts.Prefix
|
||||
filter.Prefix = ""
|
||||
filter.Tag = Tag{}
|
||||
}
|
||||
if opts.ID == "" {
|
||||
opts.ID = xid.New().String()
|
||||
}
|
||||
var status Status
|
||||
// toggle rule status for edit option
|
||||
switch opts.RuleStatus {
|
||||
case "enable":
|
||||
status = Enabled
|
||||
case "disable":
|
||||
status = Disabled
|
||||
}
|
||||
arnStr := opts.Arn
|
||||
if opts.Arn == "" {
|
||||
arnStr := opts.RoleArn
|
||||
if opts.RoleArn == "" {
|
||||
arnStr = c.Role
|
||||
}
|
||||
if arnStr == "" {
|
||||
return fmt.Errorf("Role ARN required")
|
||||
}
|
||||
tokens := strings.Split(arnStr, ":")
|
||||
if len(tokens) != 6 {
|
||||
return fmt.Errorf("invalid format for replication Arn")
|
||||
}
|
||||
if c.Role == "" { // for new configurations
|
||||
c.Role = opts.Arn
|
||||
if c.Role == "" {
|
||||
c.Role = arnStr
|
||||
}
|
||||
priority, err := strconv.Atoi(opts.Priority)
|
||||
if err != nil {
|
||||
return err
|
||||
destBucket := opts.DestBucket
|
||||
// ref https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-arn-format.html
|
||||
if btokens := strings.Split(destBucket, ":"); len(btokens) != 6 {
|
||||
if len(btokens) == 1 {
|
||||
destBucket = fmt.Sprintf("arn:aws:s3:::%s", destBucket)
|
||||
} else {
|
||||
return fmt.Errorf("destination bucket needs to be in Arn format")
|
||||
}
|
||||
}
|
||||
newRule := Rule{
|
||||
ID: opts.ID,
|
||||
|
@ -136,56 +158,147 @@ func (c *Config) AddRule(opts Options) error {
|
|||
Status: status,
|
||||
Filter: filter,
|
||||
Destination: Destination{
|
||||
Bucket: fmt.Sprintf("arn:aws:s3:::%s", tokens[5]),
|
||||
Bucket: destBucket,
|
||||
StorageClass: opts.StorageClass,
|
||||
},
|
||||
DeleteMarkerReplication: DeleteMarkerReplication{Status: Disabled},
|
||||
}
|
||||
|
||||
ruleFound := false
|
||||
for i, rule := range c.Rules {
|
||||
if rule.Priority == newRule.Priority && rule.ID != newRule.ID {
|
||||
// validate rule after overlaying priority for pre-existing rule being disabled.
|
||||
if err := newRule.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, rule := range c.Rules {
|
||||
if rule.Priority == newRule.Priority {
|
||||
return fmt.Errorf("Priority must be unique. Replication configuration already has a rule with this priority")
|
||||
}
|
||||
if rule.Destination.Bucket != newRule.Destination.Bucket {
|
||||
return fmt.Errorf("The destination bucket must be same for all rules")
|
||||
}
|
||||
if rule.ID != newRule.ID {
|
||||
continue
|
||||
if rule.ID == newRule.ID {
|
||||
return fmt.Errorf("A rule exists with this ID")
|
||||
}
|
||||
if opts.Priority == "" && rule.ID == newRule.ID {
|
||||
// inherit priority from existing rule, required field on server
|
||||
newRule.Priority = rule.Priority
|
||||
}
|
||||
if opts.RuleStatus == "" {
|
||||
newRule.Status = rule.Status
|
||||
}
|
||||
c.Rules[i] = newRule
|
||||
ruleFound = true
|
||||
break
|
||||
}
|
||||
// validate rule after overlaying priority for pre-existing rule being disabled.
|
||||
|
||||
c.Rules = append(c.Rules, newRule)
|
||||
return nil
|
||||
}
|
||||
|
||||
// EditRule modifies an existing rule in replication config
|
||||
func (c *Config) EditRule(opts Options) error {
|
||||
if opts.ID == "" {
|
||||
return fmt.Errorf("Rule ID missing")
|
||||
}
|
||||
rIdx := -1
|
||||
var newRule Rule
|
||||
for i, rule := range c.Rules {
|
||||
if rule.ID == opts.ID {
|
||||
rIdx = i
|
||||
newRule = rule
|
||||
break
|
||||
}
|
||||
}
|
||||
if rIdx < 0 {
|
||||
return fmt.Errorf("Rule with ID %s not found in replication configuration", opts.ID)
|
||||
}
|
||||
prefixChg := opts.Prefix != newRule.Prefix()
|
||||
if opts.IsTagSet || prefixChg {
|
||||
prefix := newRule.Prefix()
|
||||
if prefix != opts.Prefix {
|
||||
prefix = opts.Prefix
|
||||
}
|
||||
tags := []Tag{newRule.Filter.Tag}
|
||||
if len(newRule.Filter.And.Tags) != 0 {
|
||||
tags = newRule.Filter.And.Tags
|
||||
}
|
||||
if opts.IsTagSet {
|
||||
tags = opts.Tags()
|
||||
}
|
||||
andVal := And{
|
||||
Tags: tags,
|
||||
}
|
||||
|
||||
filter := Filter{Prefix: prefix}
|
||||
// only a single tag is set.
|
||||
if prefix == "" && len(tags) == 1 {
|
||||
filter.Tag = tags[0]
|
||||
}
|
||||
// both prefix and tag are present
|
||||
if len(andVal.Tags) > 1 || prefix != "" {
|
||||
filter.And = andVal
|
||||
filter.And.Prefix = prefix
|
||||
filter.Prefix = ""
|
||||
filter.Tag = Tag{}
|
||||
}
|
||||
newRule.Filter = filter
|
||||
}
|
||||
|
||||
// toggle rule status for edit option
|
||||
if opts.RuleStatus != "" {
|
||||
switch opts.RuleStatus {
|
||||
case "enable":
|
||||
newRule.Status = Enabled
|
||||
case "disable":
|
||||
newRule.Status = Disabled
|
||||
default:
|
||||
return fmt.Errorf("Rule state should be either [enable|disable]")
|
||||
}
|
||||
}
|
||||
|
||||
if opts.IsSCSet {
|
||||
newRule.Destination.StorageClass = opts.StorageClass
|
||||
}
|
||||
if opts.Priority != "" {
|
||||
priority, err := strconv.Atoi(opts.Priority)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
newRule.Priority = priority
|
||||
}
|
||||
if opts.DestBucket != "" {
|
||||
destBucket := opts.DestBucket
|
||||
// ref https://docs.aws.amazon.com/AmazonS3/latest/dev/s3-arn-format.html
|
||||
if btokens := strings.Split(opts.DestBucket, ":"); len(btokens) != 6 {
|
||||
if len(btokens) == 1 {
|
||||
destBucket = fmt.Sprintf("arn:aws:s3:::%s", destBucket)
|
||||
} else {
|
||||
return fmt.Errorf("destination bucket needs to be in Arn format")
|
||||
}
|
||||
}
|
||||
newRule.Destination.Bucket = destBucket
|
||||
}
|
||||
// validate rule
|
||||
if err := newRule.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
if !ruleFound && opts.Op == SetOption {
|
||||
return fmt.Errorf("Rule with ID %s not found in replication configuration", opts.ID)
|
||||
}
|
||||
if !ruleFound {
|
||||
c.Rules = append(c.Rules, newRule)
|
||||
// ensure priority and destination bucket restrictions are not violated
|
||||
for idx, rule := range c.Rules {
|
||||
if rule.Priority == newRule.Priority && rIdx != idx {
|
||||
return fmt.Errorf("Priority must be unique. Replication configuration already has a rule with this priority")
|
||||
}
|
||||
if rule.Destination.Bucket != newRule.Destination.Bucket {
|
||||
return fmt.Errorf("The destination bucket must be same for all rules")
|
||||
}
|
||||
}
|
||||
|
||||
c.Rules[rIdx] = newRule
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemoveRule removes a rule from replication config.
|
||||
func (c *Config) RemoveRule(opts Options) error {
|
||||
var newRules []Rule
|
||||
ruleFound := false
|
||||
for _, rule := range c.Rules {
|
||||
if rule.ID != opts.ID {
|
||||
newRules = append(newRules, rule)
|
||||
continue
|
||||
}
|
||||
ruleFound = true
|
||||
}
|
||||
if !ruleFound {
|
||||
return fmt.Errorf("Rule with ID %s not found", opts.ID)
|
||||
}
|
||||
|
||||
if len(newRules) == 0 {
|
||||
return fmt.Errorf("Replication configuration should have at least one rule")
|
||||
}
|
||||
|
@ -268,17 +381,19 @@ func (r Rule) Prefix() string {
|
|||
// <filter><and></and></filter>. This method returns all the tags from the
|
||||
// rule in the format tag1=value1&tag2=value2
|
||||
func (r Rule) Tags() string {
|
||||
ts := []Tag{r.Filter.Tag}
|
||||
if len(r.Filter.And.Tags) != 0 {
|
||||
var buf bytes.Buffer
|
||||
for _, t := range r.Filter.And.Tags {
|
||||
if buf.Len() > 0 {
|
||||
buf.WriteString("&")
|
||||
}
|
||||
buf.WriteString(t.String())
|
||||
}
|
||||
return buf.String()
|
||||
ts = r.Filter.And.Tags
|
||||
}
|
||||
return ""
|
||||
|
||||
var buf bytes.Buffer
|
||||
for _, t := range ts {
|
||||
if buf.Len() > 0 {
|
||||
buf.WriteString("&")
|
||||
}
|
||||
buf.WriteString(t.String())
|
||||
}
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// Filter - a filter for a replication configuration Rule.
|
||||
|
@ -321,6 +436,9 @@ type Tag struct {
|
|||
}
|
||||
|
||||
func (tag Tag) String() string {
|
||||
if tag.IsEmpty() {
|
||||
return ""
|
||||
}
|
||||
return tag.Key + "=" + tag.Value
|
||||
}
|
||||
|
||||
|
@ -352,7 +470,7 @@ type Destination struct {
|
|||
type And struct {
|
||||
XMLName xml.Name `xml:"And,omitempty" json:"-"`
|
||||
Prefix string `xml:"Prefix,omitempty" json:"Prefix,omitempty"`
|
||||
Tags []Tag `xml:"Tag,omitempty" json:"Tags,omitempty"`
|
||||
Tags []Tag `xml:"Tags,omitempty" json:"Tags,omitempty"`
|
||||
}
|
||||
|
||||
// isEmpty returns true if Tags field is null
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue