You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
boundary/internal/db/id.go

30 lines
708 B

package db
import (
"fmt"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/vault/sdk/helper/base62"
)
func NewPrivateId(prefix string) (string, error) {
return newId(prefix)
}
// NewPublicId creates a new public id with the prefix
func NewPublicId(prefix string) (string, error) {
return newId(prefix)
}
func newId(prefix string) (string, error) {
const op = "db.newId"
if prefix == "" {
return "", errors.New(errors.InvalidParameter, op, "missing prefix")
}
publicId, err := base62.Random(10)
if err != nil {
return "", errors.Wrap(err, op, errors.WithMsg("unable to generate id"), errors.WithCode(errors.Io))
}
return fmt.Sprintf("%s_%s", prefix, publicId), nil
}