Files
threshold/internal/iam/ids.go
T
Louis Ruch 70a5899e99 ICU-739/iam domain error refactor (#841)
* Refactor iam errors

* Update db and host doTx error ops

* Changelog
2020-12-23 11:00:00 -08:00

53 lines
1.1 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.Wrap(err, "iam.newRoleId")
}
return id, nil
}
func newUserId() (string, error) {
id, err := db.NewPublicId(UserPrefix)
if err != nil {
return "", errors.Wrap(err, "iam.newUserId")
}
return id, nil
}
func newGroupId() (string, error) {
id, err := db.NewPublicId(GroupPrefix)
if err != nil {
return "", errors.Wrap(err, "iam.newGroupId")
}
return id, nil
}
func newScopeId(scopeType scope.Type) (string, error) {
const op = "iam.newScopeId"
if scopeType == scope.Unknown {
return "", errors.New(errors.InvalidParameter, op, "unknown scope is not supported")
}
id, err := db.NewPublicId(scopeType.Prefix())
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("scope type: %s", scopeType.String())))
}
return id, nil
}