Skip to content

Commit

Permalink
add modify-increment extension support detailed in RFC4525 (#227)
Browse files Browse the repository at this point in the history
* add modify-increment extension support detailed in RFC4525

This extension is detailed in [RFC4525](https://tools.ietf.org/html/rfc4525).
To summarize, it allows for auto-incrementing a specific attribute by a
specific amount. It can be used in conjunction with pre-read, post-read,
and assert control types

* update v3
  • Loading branch information
jamesgoodhouse authored and johnweldon committed Dec 10, 2019
1 parent 2517798 commit 5c8e362
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
12 changes: 9 additions & 3 deletions modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (

// Change operation choices
const (
AddAttribute = 0
DeleteAttribute = 1
ReplaceAttribute = 2
AddAttribute = 0
DeleteAttribute = 1
ReplaceAttribute = 2
IncrementAttribute = 3 // (https://tools.ietf.org/html/rfc4525)
)

// PartialAttribute for a ModifyRequest as defined in https://tools.ietf.org/html/rfc4511
Expand Down Expand Up @@ -97,6 +98,11 @@ func (req *ModifyRequest) Replace(attrType string, attrVals []string) {
req.appendChange(ReplaceAttribute, attrType, attrVals)
}

// Increment appends the given attribute to the list of changes to be made
func (req *ModifyRequest) Increment(attrType string, attrVal string) {
req.appendChange(IncrementAttribute, attrType, []string{attrVal})
}

func (req *ModifyRequest) appendChange(operation uint, attrType string, attrVals []string) {
req.Changes = append(req.Changes, Change{operation, PartialAttribute{Type: attrType, Vals: attrVals}})
}
Expand Down
12 changes: 9 additions & 3 deletions v3/modify.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ import (

// Change operation choices
const (
AddAttribute = 0
DeleteAttribute = 1
ReplaceAttribute = 2
AddAttribute = 0
DeleteAttribute = 1
ReplaceAttribute = 2
IncrementAttribute = 3 // (https://tools.ietf.org/html/rfc4525)
)

// PartialAttribute for a ModifyRequest as defined in https://tools.ietf.org/html/rfc4511
Expand Down Expand Up @@ -97,6 +98,11 @@ func (req *ModifyRequest) Replace(attrType string, attrVals []string) {
req.appendChange(ReplaceAttribute, attrType, attrVals)
}

// Increment appends the given attribute to the list of changes to be made
func (req *ModifyRequest) Increment(attrType string, attrVal string) {
req.appendChange(IncrementAttribute, attrType, []string{attrVal})
}

func (req *ModifyRequest) appendChange(operation uint, attrType string, attrVals []string) {
req.Changes = append(req.Changes, Change{operation, PartialAttribute{Type: attrType, Vals: attrVals}})
}
Expand Down

0 comments on commit 5c8e362

Please sign in to comment.