Files
threshold/internal/db/id.go
T

29 lines
680 B
Go
Raw Normal View History

package db
import (
"fmt"
2020-11-05 16:54:03 -05:00
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/vault/sdk/helper/base62"
)
2020-06-29 08:18:57 -04:00
func NewPrivateId(prefix string) (string, error) {
return newId(prefix)
}
// NewPublicId creates a new public id with the prefix
func NewPublicId(prefix string) (string, error) {
2020-06-29 08:18:57 -04:00
return newId(prefix)
}
func newId(prefix string) (string, error) {
2020-12-09 10:11:38 -08:00
const op = "db.newId"
if prefix == "" {
2020-12-09 10:11:38 -08:00
return "", errors.New(errors.InvalidParameter, op, "missing prefix")
}
publicId, err := base62.Random(10)
if err != nil {
2020-12-09 10:11:38 -08:00
return "", errors.Wrap(err, op, errors.WithMsg("unable to generate id"))
}
return fmt.Sprintf("%s_%s", prefix, publicId), nil
}