2020-08-10 17:15:02 -04:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-02-02 17:15:17 -08:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
|
|
2020-06-11 16:36:47 -04:00
|
|
|
package iam
|
|
|
|
|
|
|
|
|
|
import (
|
2023-06-06 17:09:08 -04:00
|
|
|
"context"
|
2020-06-11 16:36:47 -04:00
|
|
|
"fmt"
|
|
|
|
|
|
2023-03-10 15:06:39 -05:00
|
|
|
"github.com/hashicorp/boundary/globals"
|
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 (
|
2023-03-10 15:06:39 -05:00
|
|
|
// RoleGrantPrefix is the prefix for role grants
|
2020-07-10 15:46:26 -04:00
|
|
|
RoleGrantPrefix = "rg"
|
2020-06-11 16:36:47 -04:00
|
|
|
)
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newRoleId(ctx context.Context) (string, error) {
|
|
|
|
|
id, err := db.NewPublicId(ctx, globals.RolePrefix)
|
2020-06-15 12:42:08 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "iam.newRoleId")
|
2020-06-15 12:42:08 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newUserId(ctx context.Context) (string, error) {
|
|
|
|
|
id, err := db.NewPublicId(ctx, globals.UserPrefix)
|
2020-06-11 16:36:47 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "iam.newUserId")
|
2020-06-11 16:36:47 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newGroupId(ctx context.Context) (string, error) {
|
|
|
|
|
id, err := db.NewPublicId(ctx, globals.GroupPrefix)
|
2020-06-11 16:36:47 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, "iam.newGroupId")
|
2020-06-11 16:36:47 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|
2020-06-12 15:22:23 -04:00
|
|
|
|
2023-06-06 17:09:08 -04:00
|
|
|
func newScopeId(ctx context.Context, 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 {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.New(ctx, errors.InvalidParameter, op, "unknown scope is not supported")
|
2020-06-12 15:22:23 -04:00
|
|
|
}
|
2023-06-06 17:09:08 -04:00
|
|
|
id, err := db.NewPublicId(ctx, scopeType.Prefix())
|
2020-06-12 15:22:23 -04:00
|
|
|
if err != nil {
|
2023-06-06 17:09:08 -04:00
|
|
|
return "", errors.Wrap(ctx, err, op, errors.WithMsg(fmt.Sprintf("scope type: %s", scopeType.String())))
|
2020-06-12 15:22:23 -04:00
|
|
|
}
|
|
|
|
|
return id, nil
|
|
|
|
|
}
|