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

21 lines
453 B

package db
import (
"errors"
"fmt"
"github.com/hashicorp/vault/sdk/helper/base62"
)
// NewPublicId creates a new public id with the prefix
func NewPublicId(prefix string) (string, error) {
if prefix == "" {
return "", errors.New("error no prefix for new public id")
}
publicId, err := base62.Random(10)
if err != nil {
return "", fmt.Errorf("unable to generate public id: %w", err)
}
return fmt.Sprintf("%s_%s", prefix, publicId), nil
}