refactor to use db.NewPublicId()

pull/11/head
Jim Lambert 6 years ago
parent 1bdc525c9b
commit e6300a1675

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/hashicorp/watchtower/internal/db"
"github.com/hashicorp/watchtower/internal/iam/store"
"google.golang.org/protobuf/proto"
@ -50,7 +49,7 @@ func NewAuthMethod(organizationId string, authType AuthType, opt ...Option) (*Au
if organizationId == "" {
return nil, errors.New("error organization id is unset for new auth method")
}
publicId, err := base62.Random(20)
publicId, err := db.NewPublicId("authm")
if err != nil {
return nil, fmt.Errorf("error generating public id %w for new auth method", err)
}

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/hashicorp/watchtower/internal/db"
"github.com/hashicorp/watchtower/internal/iam/store"
"google.golang.org/protobuf/proto"
@ -31,7 +30,7 @@ func NewGroup(scopeId string, opt ...Option) (*Group, error) {
if scopeId == "" {
return nil, errors.New("error the group scope id is unset")
}
publicId, err := base62.Random(20)
publicId, err := db.NewPublicId("g")
if err != nil {
return nil, fmt.Errorf("error generating public id %w for new group", err)
}

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/hashicorp/watchtower/internal/db"
"github.com/hashicorp/watchtower/internal/iam/store"
"google.golang.org/protobuf/proto"
@ -31,7 +30,7 @@ func NewRole(scopeId string, opt ...Option) (*Role, error) {
if scopeId == "" {
return nil, errors.New("error the role scope id is unset")
}
publicId, err := base62.Random(20)
publicId, err := db.NewPublicId("r")
if err != nil {
return nil, fmt.Errorf("error generating public id %w for new role", err)
}

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/hashicorp/watchtower/internal/db"
"github.com/hashicorp/watchtower/internal/iam/store"
"google.golang.org/protobuf/proto"
@ -30,7 +29,7 @@ func NewRoleGrant(role *Role, grant string, opt ...Option) (*RoleGrant, error) {
if role.PublicId == "" {
return nil, errors.New("error role id is unset")
}
publicId, err := base62.Random(20)
publicId, err := db.NewPublicId("rg")
if err != nil {
return nil, fmt.Errorf("error generating public id %w for new role grant", err)
}

@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"github.com/hashicorp/vault/sdk/helper/base62"
"github.com/hashicorp/watchtower/internal/db"
"github.com/hashicorp/watchtower/internal/iam/store"
"google.golang.org/protobuf/proto"
@ -27,7 +26,7 @@ var _ db.VetForWriter = (*User)(nil)
func NewUser(organizationPublicId string, opt ...Option) (*User, error) {
opts := getOpts(opt...)
withName := opts.withName
publicId, err := base62.Random(20)
publicId, err := db.NewPublicId("u")
if err != nil {
return nil, fmt.Errorf("error generating public ID %w for new user", err)
}

Loading…
Cancel
Save