Files
threshold/internal/iam/ids.go
T
s-christoffandJim 6b78108ecf Update primary error functions to take a context, deprecate old functions (#1358)
* add new error funcs which take a ctx and deprecate existing funcs

* use context where available when writing error events

* remove circular internal/errors pkg dep

* suppress some chatty errors using errors.WithoutEvent()

* convert auth oidc funcs to take context where needed to write events

Co-authored-by: Jim <jlambert@hashicorp.com>
2021-07-29 20:52:56 -04:00

53 lines
1.2 KiB
Go

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
}