Skip to content

Commit

Permalink
Add SetOption to edit replication rule (#1362)
Browse files Browse the repository at this point in the history
Also adding a field to manage rule state
  • Loading branch information
poornas authored Aug 7, 2020
1 parent 210edc6 commit f0460bf
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pkg/replication/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ type OptionType string
const (
// AddOption specifies addition of rule to config
AddOption OptionType = "Add"
// SetOption specifies modification of existing rule to config
SetOption OptionType = "Set"

// RemoveOption specifies rule options are for removing a rule
RemoveOption OptionType = "Remove"
// ImportOption is for getting current config
Expand All @@ -46,7 +49,7 @@ type Options struct {
Op OptionType
ID string
Prefix string
Disable bool
RuleStatus string
Priority string
TagString string
StorageClass string
Expand Down Expand Up @@ -104,8 +107,12 @@ func (c *Config) AddRule(opts Options) error {
if opts.ID == "" {
opts.ID = xid.New().String()
}
status := Enabled
if opts.Disable {
var status Status
// toggle rule status for edit option
switch opts.RuleStatus {
case "enable":
status = Enabled
case "disable":
status = Disabled
}
arnStr := opts.Arn
Expand Down Expand Up @@ -150,6 +157,9 @@ func (c *Config) AddRule(opts Options) error {
// 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
Expand All @@ -158,7 +168,9 @@ func (c *Config) AddRule(opts Options) error {
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)
}
Expand Down

0 comments on commit f0460bf

Please sign in to comment.