aboutsummaryrefslogtreecommitdiff
path: root/util.go
diff options
context:
space:
mode:
Diffstat (limited to 'util.go')
-rw-r--r--util.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/util.go b/util.go
index 014805c..d7c42d7 100644
--- a/util.go
+++ b/util.go
@@ -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()
+}