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 {
|
2020-12-23 11:00:00 -08:00
|
|
|
return "", errors.Wrap(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 {
|
2020-12-23 11:00:00 -08:00
|
|
|
return "", errors.Wrap(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 {
|
2020-12-23 11:00:00 -08:00
|
|
|
return "", errors.Wrap(err, "iam.newGroupId")
|
2020-06-11 16:36:47 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
2020-06-12 15:22:23 -04:00
|
|
|
|
2020-06-26 11:00:14 -04:00
|
|
|
func newScopeId(scopeType scope.Type) (string, error) {
|
2020-12-23 11:00:00 -08:00
|
|
|
const op = "iam.newScopeId"
|
2020-06-26 11:00:14 -04:00
|
|
|
if scopeType == scope.Unknown {
|
2020-12-23 11:00:00 -08:00
|
|
|
return "", errors.New(errors.InvalidParameter, op, "unknown scope is not supported")
|
2020-06-12 15:22:23 -04:00
|
|
|
}
|
|
|
|
|
id, err := db.NewPublicId(scopeType.Prefix())
|
|
|
|
|
if err != nil {
|
2020-12-23 11:00:00 -08:00
|
|
|
return "", errors.Wrap(err, op, errors.WithMsg(fmt.Sprintf("scope type: %s", scopeType.String())))
|
2020-06-12 15:22:23 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|