diff options
Diffstat (limited to 'util.go')
-rw-r--r-- | util.go | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -3,8 +3,11 @@ package main import ( "encoding/json" "fmt" + "log" "strings" + "time" + uuid "github.com/google/uuid" consul "github.com/hashicorp/consul/api" ) @@ -101,3 +104,37 @@ func parseDN(dn string) ([]DNComponent, error) { } return ret, nil } + +func checkRestrictedAttr(attr string) error { + RESTRICTED_ATTRS := []string{ + ATTR_MEMBEROF, + ATTR_ENTRYUUID, + ATTR_CREATORSNAME, + ATTR_CREATETIMESTAMP, + ATTR_MODIFIERSNAME, + ATTR_MODIFYTIMESTAMP, + } + + if strings.EqualFold(attr, ATTR_MEMBEROF) { + return fmt.Errorf("memberOf cannot be defined directly, membership must be specified in the group itself") + } + + for _, s := range RESTRICTED_ATTRS { + if strings.EqualFold(attr, s) { + return fmt.Errorf("Attribute %s is restricted and may only be set by the system", s) + } + } + return nil +} + +func genTimestamp() string { + return time.Now().Format("20060102150405Z") +} + +func genUuid() string { + uuid, err := uuid.NewRandom() + if err != nil { + log.Panicf("UUID generation error: %s", err) + } + return uuid.String() +} |