-
Notifications
You must be signed in to change notification settings - Fork 289
/
Copy pathids.go
52 lines (45 loc) · 1.18 KB
/
ids.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package iam
import (
"fmt"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/types/scope"
)
const (
UserPrefix = "u"
GroupPrefix = "g"
RolePrefix = "r"
RoleGrantPrefix = "rg"
)
func newRoleId() (string, error) {
id, err := db.NewPublicId(RolePrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newRoleId")
}
return id, nil
}
func newUserId() (string, error) {
id, err := db.NewPublicId(UserPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newUserId")
}
return id, nil
}
func newGroupId() (string, error) {
id, err := db.NewPublicId(GroupPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newGroupId")
}
return id, nil
}
func newScopeId(scopeType scope.Type) (string, error) {
const op = "iam.newScopeId"
if scopeType == scope.Unknown {
return "", errors.NewDeprecated(errors.InvalidParameter, op, "unknown scope is not supported")
}
id, err := db.NewPublicId(scopeType.Prefix())
if err != nil {
return "", errors.WrapDeprecated(err, op, errors.WithMsg(fmt.Sprintf("scope type: %s", scopeType.String())))
}
return id, nil
}