Files
threshold/internal/iam/ids.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.4 KiB
Go
Raw Normal View History

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