Files
threshold/internal/iam/ids.go
T

52 lines
1.2 KiB
Go
Raw Normal View History

2020-06-11 16:36:47 -04:00
package iam
import (
"fmt"
2020-08-10 17:15:02 -04:00
"github.com/hashicorp/boundary/internal/db"
2020-11-05 16:54:03 -05:00
"github.com/hashicorp/boundary/internal/errors"
2020-08-10 17:15:02 -04:00
"github.com/hashicorp/boundary/internal/types/scope"
2020-06-11 16:36:47 -04:00
)
const (
2020-07-10 15:46:26 -04:00
UserPrefix = "u"
GroupPrefix = "g"
RolePrefix = "r"
RoleGrantPrefix = "rg"
2020-06-11 16:36:47 -04:00
)
2020-06-15 12:42:08 -04:00
func newRoleId() (string, error) {
id, err := db.NewPublicId(RolePrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newRoleId")
2020-06-15 12:42:08 -04:00
}
return id, nil
}
2020-06-11 16:36:47 -04:00
func newUserId() (string, error) {
id, err := db.NewPublicId(UserPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newUserId")
2020-06-11 16:36:47 -04:00
}
return id, nil
}
func newGroupId() (string, error) {
id, err := db.NewPublicId(GroupPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newGroupId")
2020-06-11 16:36:47 -04:00
}
return id, nil
}
func newScopeId(scopeType scope.Type) (string, error) {
2020-12-23 11:00:00 -08:00
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
}