Move prefixes for many packages into the globals package (#3069)

This is a prerequisite for some enhancements to grant validation
This commit is contained in:
Jeff Mitchell authored and GitHub committed 2023-03-10 15:06:39 -05:00
1 parent 6adc0c86b5
commit b76b24a4ad
115 files changed
+796 -729

No files matched your search

-1
View File
@@ -8,7 +8,6 @@ import "time"
const (
TcpProxyV1 = "boundary-tcp-proxy-v1"
ServiceTokenV1 = "s1"
SessionPrefix = "s_"
AnyAuthenticatedUserId = "u_auth"
AnonymousUserId = "u_anon"
+100
View File
@@ -0,0 +1,100 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package globals
// This set of consts is intended to be a place to collect commonly-used
// prefixes. This can avoid some cross-package dependency issues. Unlike the
// top-level globals package, these are not currently meant to be available to
// clients or test writers.
const (
// AuthTokenPrefix is the prefix for auth tokens
AuthTokenPrefix = "at"
// PasswordAuthMethodPrefix is the prefix for the password auth method
PasswordAuthMethodPrefix = "ampw"
// PasswordAccountPreviousPrefix is the previously-used account prefix
PasswordAccountPreviousPrefix = "apw"
// PasswordAccountPrefix is the new account prefix
PasswordAccountPrefix = "acctpw"
// OidcAuthMethodPrefix defines the prefix for OIDC AuthMethod public ids
OidcAuthMethodPrefix = "amoidc"
// OidcAccountPrefix defines the prefix for OIDC Account public ids
OidcAccountPrefix = "acctoidc"
// OidcManagedGroupPrefix defines the prefix for OIDC ManagedGroup public
// ids
OidcManagedGroupPrefix = "mgoidc"
// ProjectPrefix is the prefix for project scopes
ProjectPrefix = "p"
// OrgPrefix is the prefix for org scopes
OrgPrefix = "o"
// GlobalPrefix is the prefix for the global scope
GlobalPrefix = "global"
// UserPrefix is the prefix for users
UserPrefix = "u"
// GroupPrefix is the prefix for non-managed groups
GroupPrefix = "g"
// RolePrefix is the prefix for roles
RolePrefix = "r"
// StaticCredentialStorePrefix is the prefix for static credential stores
StaticCredentialStorePrefix = "csst"
// StaticPreviousCredentialStorePrefix is the previous prefix for static
// credential stores
StaticCredentialStorePreviousPrefix = "cs"
// VaultCredentialStorePrefix is the prefix for Vault credential stores
VaultCredentialStorePrefix = "csvlt"
// VaultCredentialLibraryPrefix is the prefix for Vault credential libraries
VaultCredentialLibraryPrefix = "clvlt"
// VaultSshCertificateCredentialLibraryPrefix is the prefix for Vault SSH
// certificate credential libraries
VaultSshCertificateCredentialLibraryPrefix = "clvsclt"
// UsernamePasswordCredentialPrefix is the prefix for username/password
// creds
UsernamePasswordCredentialPrefix = "credup"
// UsernamePasswordCredentialPreviousPrefix is the previous prefix for
// username/password creds
UsernamePasswordCredentialPreviousPrefix = "cred"
// SshPrivateKeyCredentialPrefix is the prefix for SSH private key creds
SshPrivateKeyCredentialPrefix = "credspk"
// JsonCredentialPrefix is the prefix for generic JSON creds
JsonCredentialPrefix = "credjson"
// StaticHostCatalogPrefix is the prefix for static host catalogs
StaticHostCatalogPrefix = "hcst"
// StaticHostSetPrefix is the prefix for static host sets
StaticHostSetPrefix = "hsst"
// StaticHostPrefix is the prefix for static hosts
StaticHostPrefix = "hst"
// PluginHostCatalogPrefix is the prefix for plugin host catalogs
PluginHostCatalogPrefix = "hcplg"
// PluginHostCatalogPreviousPrefix is the previous prefix for plugin host
// catalogs
PluginHostCatalogPreviousPrefix = "hc"
// PluginHostSetPrefix is the prefix for plugin host sets
PluginHostSetPrefix = "hsplg"
// PluginHostSetPreviousPrefix is the previous prefix for plugin host sets
PluginHostSetPreviousPrefix = "hs"
// PluginHostPrefix is the prefix for plugin hosts
PluginHostPrefix = "hplg"
// PluginHostPreviousPrefix is the previous prefix for plugin hosts
PluginHostPreviousPrefix = "h"
// SessionPrefix is the prefix for sessions
SessionPrefix = "s"
// TcpTargetPrefix is the prefix for TCP targets
TcpTargetPrefix = "ttcp"
// SshTargetPrefix is the prefix for TCP targets
SshTargetPrefix = "tssh"
// WorkerPrefix is the prefix for workers
WorkerPrefix = "w"
)
+5 -10
View File
@@ -6,31 +6,26 @@ package oidc
import (
"context"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/types/subtypes"
)
func init() {
if err := subtypes.Register(auth.Domain, Subtype, AuthMethodPrefix, AccountPrefix, intglobals.OidcManagedGroupPrefix); err != nil {
if err := subtypes.Register(auth.Domain, Subtype, globals.OidcAuthMethodPrefix, globals.OidcAccountPrefix, globals.OidcManagedGroupPrefix); err != nil {
panic(err)
}
}
const (
// AuthMethodPrefix defines the prefix for AuthMethod public ids.
AuthMethodPrefix = "amoidc"
// AccountPrefix defines the prefix for Account public ids.
AccountPrefix = "acctoidc"
Subtype = subtypes.Subtype("oidc")
)
func newAuthMethodId(ctx context.Context) (string, error) {
const op = "oidc.newAuthMethodId"
id, err := db.NewPublicId(AuthMethodPrefix)
id, err := db.NewPublicId(globals.OidcAuthMethodPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, op)
}
@@ -48,7 +43,7 @@ func newAccountId(ctx context.Context, authMethodId, issuer, sub string) (string
if sub == "" {
return "", errors.New(ctx, errors.InvalidParameter, op, "missing subject")
}
id, err := db.NewPublicId(AccountPrefix, db.WithPrngValues([]string{authMethodId, issuer, sub}))
id, err := db.NewPublicId(globals.OidcAccountPrefix, db.WithPrngValues([]string{authMethodId, issuer, sub}))
if err != nil {
return "", errors.Wrap(ctx, err, op)
}
@@ -57,7 +52,7 @@ func newAccountId(ctx context.Context, authMethodId, issuer, sub string) (string
func newManagedGroupId(ctx context.Context) (string, error) {
const op = "oidc.newManagedGroupId"
id, err := db.NewPublicId(intglobals.OidcManagedGroupPrefix)
id, err := db.NewPublicId(globals.OidcManagedGroupPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, op)
}
+5 -4
View File
@@ -8,6 +8,7 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -15,14 +16,14 @@ import (
func Test_Ids(t *testing.T) {
t.Parallel()
ctx := context.TODO()
t.Run(AuthMethodPrefix, func(t *testing.T) {
t.Run(globals.OidcAuthMethodPrefix, func(t *testing.T) {
id, err := newAuthMethodId(ctx)
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, AuthMethodPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.OidcAuthMethodPrefix+"_"))
})
t.Run(AccountPrefix, func(t *testing.T) {
t.Run(globals.OidcAccountPrefix, func(t *testing.T) {
id, err := newAccountId(ctx, "public-id", "test-issuer", "test-subject")
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, AccountPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.OidcAccountPrefix+"_"))
})
}
+2 -1
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -75,7 +76,7 @@ func (r *Repository) CreateAccount(ctx context.Context, scopeId string, a *Accou
opts := getOpts(opt...)
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, AccountPrefix+"_") {
if !strings.HasPrefix(opts.withPublicId, globals.OidcAccountPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidParameter, op, "chosen account id does not have a valid prefix")
}
a.PublicId = opts.withPublicId
+11 -10
View File
@@ -11,6 +11,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc/store"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
@@ -214,7 +215,7 @@ func TestRepository_CreateAccount(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -265,7 +266,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -312,7 +313,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -322,7 +323,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got2, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in2)
assert.NoError(err)
require.NotNil(got2)
assertPublicId(t, AccountPrefix, got2.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -357,7 +358,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -403,7 +404,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -415,7 +416,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got2, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in2)
assert.NoError(err)
require.NotNil(got2)
assertPublicId(t, AccountPrefix, got2.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -452,7 +453,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -467,7 +468,7 @@ func TestRepository_CreateAccount_DuplicateFields(t *testing.T) {
got2, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in2)
assert.NoError(err)
require.NotNil(got2)
assertPublicId(t, AccountPrefix, got2.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -1159,7 +1160,7 @@ func TestRepository_UpdateAccount(t *testing.T) {
return
}
require.NotNil(got)
assertPublicId(t, AccountPrefix, got.PublicId)
assertPublicId(t, globals.OidcAccountPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.AuthMethodId, got.AuthMethodId)
@@ -7,6 +7,7 @@ import (
"context"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -45,7 +46,7 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, am *AuthMethod, opt .
}
am.PublicId = id
} else {
if !strings.HasPrefix(am.PublicId, AuthMethodPrefix+"_") {
if !strings.HasPrefix(am.PublicId, globals.OidcAuthMethodPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidParameter, op, "wrong auth method id prefix")
}
}
@@ -11,12 +11,12 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc/store"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/stretchr/testify/assert"
@@ -202,7 +202,7 @@ func TestRepository_CreateManagedGroup(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, intglobals.OidcManagedGroupPrefix, got.PublicId)
assertPublicId(t, globals.OidcManagedGroupPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -951,7 +951,7 @@ func TestRepository_UpdateManagedGroup(t *testing.T) {
return
}
require.NotNil(got)
assertPublicId(t, intglobals.OidcManagedGroupPrefix, got.PublicId)
assertPublicId(t, globals.OidcManagedGroupPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.AuthMethodId, got.AuthMethodId)
+4 -6
View File
@@ -4,29 +4,27 @@
package password
import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/types/subtypes"
)
func init() {
if err := subtypes.Register(auth.Domain, Subtype, AuthMethodPrefix, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix); err != nil {
if err := subtypes.Register(auth.Domain, Subtype, globals.PasswordAuthMethodPrefix, globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the password package.
const (
AuthMethodPrefix = "ampw"
Subtype = subtypes.Subtype("password")
)
func newAuthMethodId() (string, error) {
const op = "password.newAuthMethodId"
id, err := db.NewPublicId(AuthMethodPrefix)
id, err := db.NewPublicId(globals.PasswordAuthMethodPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, op)
}
@@ -35,7 +33,7 @@ func newAuthMethodId() (string, error) {
func newAccountId() (string, error) {
const op = "password.newAccountId"
id, err := db.NewPublicId(intglobals.NewPasswordAccountPrefix)
id, err := db.NewPublicId(globals.PasswordAccountPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, op)
}
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/globals"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -16,11 +16,11 @@ func Test_PublicIds(t *testing.T) {
t.Run("authMethod", func(t *testing.T) {
id, err := newAuthMethodId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, AuthMethodPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.PasswordAuthMethodPrefix+"_"))
})
t.Run("account", func(t *testing.T) {
id, err := newAccountId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, intglobals.NewPasswordAccountPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.PasswordAccountPrefix+"_"))
})
}
+2 -2
View File
@@ -9,9 +9,9 @@ import (
"regexp"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/go-dbw"
@@ -64,7 +64,7 @@ func (r *Repository) CreateAccount(ctx context.Context, scopeId string, a *Accou
a = a.clone()
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, intglobals.NewPasswordAccountPrefix+"_") {
if !strings.HasPrefix(opts.withPublicId, globals.PasswordAccountPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidParameter, op, "chosen account id does not have a valid prefix")
}
a.PublicId = opts.withPublicId
@@ -8,12 +8,12 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/password/store"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/stretchr/testify/assert"
@@ -246,7 +246,7 @@ func TestRepository_CreateAccount(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -293,7 +293,7 @@ func TestRepository_CreateAccount_DuplicateNames(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -325,7 +325,7 @@ func TestRepository_CreateAccount_DuplicateNames(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -335,7 +335,7 @@ func TestRepository_CreateAccount_DuplicateNames(t *testing.T) {
got2, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in2)
assert.NoError(err)
require.NotNil(got2)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got2.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -949,7 +949,7 @@ func TestRepository_UpdateAccount(t *testing.T) {
return
}
require.NotNil(got)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.AuthMethodId, got.AuthMethodId)
@@ -1036,7 +1036,7 @@ func TestRepository_UpdateAccount_DupeNames(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -1113,7 +1113,7 @@ func TestRepository_UpdateAccount_DupeNames(t *testing.T) {
got, err := repo.CreateAccount(context.Background(), org.GetPublicId(), in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, intglobals.NewPasswordAccountPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAccountPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.LoginName, got.LoginName)
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -44,8 +45,8 @@ func (r *Repository) CreateAuthMethod(ctx context.Context, m *AuthMethod, opt ..
opts := GetOpts(opt...)
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, AuthMethodPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidPublicId, op, fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, AuthMethodPrefix))
if !strings.HasPrefix(opts.withPublicId, globals.PasswordAuthMethodPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidPublicId, op, fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, globals.PasswordAuthMethodPrefix))
}
m.PublicId = opts.withPublicId
} else {
@@ -10,6 +10,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/password/store"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
@@ -156,7 +157,7 @@ func TestRepository_CreateAuthMethod(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, AuthMethodPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAuthMethodPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -189,7 +190,7 @@ func TestRepository_CreateAuthMethod_DupeNames(t *testing.T) {
got, err := repo.CreateAuthMethod(context.Background(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AuthMethodPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAuthMethodPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -218,7 +219,7 @@ func TestRepository_CreateAuthMethod_DupeNames(t *testing.T) {
got, err := repo.CreateAuthMethod(context.Background(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, AuthMethodPrefix, got.PublicId)
assertPublicId(t, globals.PasswordAuthMethodPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -229,7 +230,7 @@ func TestRepository_CreateAuthMethod_DupeNames(t *testing.T) {
got2, err := repo.CreateAuthMethod(context.Background(), in2)
require.NoError(err)
require.NotNil(got2)
assertPublicId(t, AuthMethodPrefix, got2.PublicId)
assertPublicId(t, globals.PasswordAuthMethodPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
+1 -2
View File
@@ -98,7 +98,6 @@ func (at *AuthToken) decrypt(ctx context.Context, cipher wrapping.Wrapper) error
}
const (
AuthTokenPrefix = "at"
// The version prefix is used to differentiate token versions just for future proofing.
TokenValueVersionPrefix = "0"
tokenLength = 24
@@ -107,7 +106,7 @@ const (
// NewAuthTokenId creates a new id for an auth token.
func NewAuthTokenId() (string, error) {
const op = "authtoken.newAuthTokenId"
id, err := db.NewPublicId(AuthTokenPrefix)
id, err := db.NewPublicId(globals.AuthTokenPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, op)
}
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"github.com/golang/protobuf/ptypes"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/kms"
@@ -276,7 +277,7 @@ func TestRepository_CreateAuthToken(t *testing.T) {
}
require.NoError(err, "Got error for CreateAuthToken(ctx, %v, %v)", tt.iamUser, tt.authAcctId)
assert.NotNil(got)
db.AssertPublicId(t, AuthTokenPrefix, got.PublicId)
db.AssertPublicId(t, globals.AuthTokenPrefix, got.PublicId)
assert.Equal(tt.authAcctId, got.GetAuthAccountId())
assert.Equal(got.CreateTime, got.UpdateTime)
assert.Equal(got.CreateTime, got.ApproximateLastAccessTime)
+3 -2
View File
@@ -12,6 +12,7 @@ import (
"runtime"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/cmd/base/internal/docker"
"github.com/hashicorp/boundary/internal/db"
@@ -194,7 +195,7 @@ func (b *Server) CreateDevOidcAuthMethod(ctx context.Context) error {
var err error
if b.DevOidcAuthMethodId == "" {
b.DevOidcAuthMethodId, err = db.NewPublicId(oidc.AuthMethodPrefix)
b.DevOidcAuthMethodId, err = db.NewPublicId(globals.OidcAuthMethodPrefix)
if err != nil {
return fmt.Errorf("error generating initial oidc auth method id: %w", err)
}
@@ -371,7 +372,7 @@ func (b *Server) createInitialOidcAuthMethod(ctx context.Context) (*oidc.AuthMet
return nil, fmt.Errorf("error creating new in memory oidc auth method: %w", err)
}
if b.DevOidcAuthMethodId == "" {
b.DevOidcAuthMethodId, err = db.NewPublicId(oidc.AuthMethodPrefix)
b.DevOidcAuthMethodId, err = db.NewPublicId(globals.OidcAuthMethodPrefix)
if err != nil {
return nil, fmt.Errorf("error generating initial oidc auth method id: %w", err)
}
+7 -7
View File
@@ -94,7 +94,7 @@ func (b *Server) CreateInitialPasswordAuthMethod(ctx context.Context) (*password
return nil, nil, fmt.Errorf("error creating new in memory auth method: %w", err)
}
if b.DevPasswordAuthMethodId == "" {
b.DevPasswordAuthMethodId, err = db.NewPublicId(password.AuthMethodPrefix)
b.DevPasswordAuthMethodId, err = db.NewPublicId(globals.PasswordAuthMethodPrefix)
if err != nil {
return nil, nil, fmt.Errorf("error generating initial auth method id: %w", err)
}
@@ -239,7 +239,7 @@ func (b *Server) CreateInitialPasswordAuthMethod(ctx context.Context) (*password
}
}
if b.DevUserId == "" {
b.DevUserId, err = db.NewPublicId(iam.UserPrefix)
b.DevUserId, err = db.NewPublicId(globals.UserPrefix)
if err != nil {
return nil, nil, fmt.Errorf("error generating initial user id: %w", err)
}
@@ -342,7 +342,7 @@ func (b *Server) CreateInitialHostResources(ctx context.Context) (*static.HostCa
// Host Catalog
if b.DevHostCatalogId == "" {
b.DevHostCatalogId, err = db.NewPublicId(static.HostCatalogPrefix)
b.DevHostCatalogId, err = db.NewPublicId(globals.StaticHostCatalogPrefix)
if err != nil {
return nil, nil, nil, fmt.Errorf("error generating initial host catalog id: %w", err)
}
@@ -364,7 +364,7 @@ func (b *Server) CreateInitialHostResources(ctx context.Context) (*static.HostCa
// Host
if b.DevHostId == "" {
b.DevHostId, err = db.NewPublicId(static.HostPrefix)
b.DevHostId, err = db.NewPublicId(globals.StaticHostPrefix)
if err != nil {
return nil, nil, nil, fmt.Errorf("error generating initial host id: %w", err)
}
@@ -390,7 +390,7 @@ func (b *Server) CreateInitialHostResources(ctx context.Context) (*static.HostCa
// Host Set
if b.DevHostSetId == "" {
b.DevHostSetId, err = db.NewPublicId(static.HostSetPrefix)
b.DevHostSetId, err = db.NewPublicId(globals.StaticHostSetPrefix)
if err != nil {
return nil, nil, nil, fmt.Errorf("error generating initial host set id: %w", err)
}
@@ -437,7 +437,7 @@ func (b *Server) CreateInitialTargetWithAddress(ctx context.Context) (target.Tar
// When this function is not called as part of boundary dev (eg: as part of
// boundary database init or tests), generate random target ids.
if len(b.DevTargetId) == 0 {
b.DevTargetId, err = db.NewPublicId(tcp.TargetPrefix)
b.DevTargetId, err = db.NewPublicId(globals.TcpTargetPrefix)
if err != nil {
return nil, fmt.Errorf("failed to generate initial target id: %w", err)
}
@@ -504,7 +504,7 @@ func (b *Server) CreateInitialTargetWithHostSources(ctx context.Context) (target
// When this function is not called as part of boundary dev (eg: as part of
// boundary database init or tests), generate random target ids.
if len(b.DevSecondaryTargetId) == 0 {
b.DevSecondaryTargetId, err = db.NewPublicId(tcp.TargetPrefix)
b.DevSecondaryTargetId, err = db.NewPublicId(globals.TcpTargetPrefix)
if err != nil {
return nil, fmt.Errorf("failed to generate initial secondary target id: %w", err)
}
@@ -9,8 +9,7 @@ import (
"strings"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -100,11 +99,11 @@ func (c *Command) Run(args []string) int {
c.FlagAuthMethodId = pri
switch {
case strings.HasPrefix(c.FlagAuthMethodId, password.AuthMethodPrefix):
case strings.HasPrefix(c.FlagAuthMethodId, globals.PasswordAuthMethodPrefix):
cmd := PasswordCommand{Command: c.Command, Opts: []common.Option{common.WithSkipScopeIdFlag(true)}}
cmd.Run([]string{})
case strings.HasPrefix(c.FlagAuthMethodId, oidc.AuthMethodPrefix):
case strings.HasPrefix(c.FlagAuthMethodId, globals.OidcAuthMethodPrefix):
cmd := OidcCommand{Command: c.Command, Opts: []common.Option{common.WithSkipScopeIdFlag(true)}}
cmd.Run([]string{})
@@ -11,6 +11,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
"github.com/hashicorp/go-secure-stdlib/parseutil"
@@ -138,7 +139,7 @@ func (c *PasswordCommand) Run(args []string) int {
c.FlagScopeId = "global"
}
pri, err := getPrimaryAuthMethodId(c.Context, aClient, c.FlagScopeId, "ampw")
pri, err := getPrimaryAuthMethodId(c.Context, aClient, c.FlagScopeId, globals.PasswordAuthMethodPrefix)
if err != nil {
c.PrintCliError(err)
return base.CommandUserError
+12 -18
View File
@@ -17,21 +17,15 @@ import (
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/config"
"github.com/hashicorp/boundary/internal/cmd/ops"
"github.com/hashicorp/boundary/internal/daemon/controller"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/daemon/worker"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/server"
"github.com/hashicorp/boundary/internal/server/store"
"github.com/hashicorp/boundary/internal/target/tcp"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/hashicorp/go-secure-stdlib/parseutil"
"github.com/hashicorp/go-secure-stdlib/strutil"
@@ -449,20 +443,20 @@ func (c *Command) Run(args []string) int {
c.UI.Error("Invalid ID suffix, must be in the set A-Za-z0-9")
return base.CommandUserError
}
c.DevPasswordAuthMethodId = fmt.Sprintf("%s_%s", password.AuthMethodPrefix, c.flagIdSuffix)
c.DevOidcAuthMethodId = fmt.Sprintf("%s_%s", oidc.AuthMethodPrefix, c.flagIdSuffix)
c.DevUserId = fmt.Sprintf("%s_%s", iam.UserPrefix, c.flagIdSuffix)
c.DevPasswordAccountId = fmt.Sprintf("%s_%s", intglobals.NewPasswordAccountPrefix, c.flagIdSuffix)
c.DevOidcAccountId = fmt.Sprintf("%s_%s", oidc.AccountPrefix, c.flagIdSuffix)
c.DevPasswordAuthMethodId = fmt.Sprintf("%s_%s", globals.PasswordAuthMethodPrefix, c.flagIdSuffix)
c.DevOidcAuthMethodId = fmt.Sprintf("%s_%s", globals.OidcAuthMethodPrefix, c.flagIdSuffix)
c.DevUserId = fmt.Sprintf("%s_%s", globals.UserPrefix, c.flagIdSuffix)
c.DevPasswordAccountId = fmt.Sprintf("%s_%s", globals.PasswordAccountPrefix, c.flagIdSuffix)
c.DevOidcAccountId = fmt.Sprintf("%s_%s", globals.OidcAccountPrefix, c.flagIdSuffix)
c.DevUnprivilegedUserId = "u_" + strutil.Reverse(strings.TrimPrefix(c.DevUserId, "u_"))
c.DevUnprivilegedPasswordAccountId = fmt.Sprintf("%s_", intglobals.NewPasswordAccountPrefix) + strutil.Reverse(strings.TrimPrefix(c.DevPasswordAccountId, fmt.Sprintf("%s_", intglobals.NewPasswordAccountPrefix)))
c.DevUnprivilegedOidcAccountId = fmt.Sprintf("%s_", oidc.AccountPrefix) + strutil.Reverse(strings.TrimPrefix(c.DevOidcAccountId, fmt.Sprintf("%s_", oidc.AccountPrefix)))
c.DevUnprivilegedPasswordAccountId = fmt.Sprintf("%s_", globals.PasswordAccountPrefix) + strutil.Reverse(strings.TrimPrefix(c.DevPasswordAccountId, fmt.Sprintf("%s_", globals.PasswordAccountPrefix)))
c.DevUnprivilegedOidcAccountId = fmt.Sprintf("%s_", globals.OidcAccountPrefix) + strutil.Reverse(strings.TrimPrefix(c.DevOidcAccountId, fmt.Sprintf("%s_", globals.OidcAccountPrefix)))
c.DevOrgId = fmt.Sprintf("%s_%s", scope.Org.Prefix(), c.flagIdSuffix)
c.DevProjectId = fmt.Sprintf("%s_%s", scope.Project.Prefix(), c.flagIdSuffix)
c.DevHostCatalogId = fmt.Sprintf("%s_%s", static.HostCatalogPrefix, c.flagIdSuffix)
c.DevHostSetId = fmt.Sprintf("%s_%s", static.HostSetPrefix, c.flagIdSuffix)
c.DevHostId = fmt.Sprintf("%s_%s", static.HostPrefix, c.flagIdSuffix)
c.DevTargetId = fmt.Sprintf("%s_%s", tcp.TargetPrefix, c.flagIdSuffix)
c.DevHostCatalogId = fmt.Sprintf("%s_%s", globals.StaticHostCatalogPrefix, c.flagIdSuffix)
c.DevHostSetId = fmt.Sprintf("%s_%s", globals.StaticHostSetPrefix, c.flagIdSuffix)
c.DevHostId = fmt.Sprintf("%s_%s", globals.StaticHostPrefix, c.flagIdSuffix)
c.DevTargetId = fmt.Sprintf("%s_%s", globals.TcpTargetPrefix, c.flagIdSuffix)
}
if c.flagSecondaryIdSuffix != "" {
if len(c.flagSecondaryIdSuffix) != 10 {
@@ -473,7 +467,7 @@ func (c *Command) Run(args []string) int {
c.UI.Error("Invalid secondary ID suffix, must be in the set A-Za-z0-9")
return base.CommandUserError
}
c.DevSecondaryTargetId = fmt.Sprintf("%s_%s", tcp.TargetPrefix, c.flagSecondaryIdSuffix)
c.DevSecondaryTargetId = fmt.Sprintf("%s_%s", globals.TcpTargetPrefix, c.flagSecondaryIdSuffix)
}
if c.flagIdSuffix != "" && c.flagSecondaryIdSuffix != "" &&
+10 -13
View File
@@ -6,37 +6,34 @@ package credential
import (
"context"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/types/subtypes"
)
func init() {
if err := subtypes.Register(Domain, UsernamePasswordSubtype, UsernamePasswordCredentialPrefix, PreviousUsernamePasswordCredentialPrefix); err != nil {
if err := subtypes.Register(Domain, UsernamePasswordSubtype, globals.UsernamePasswordCredentialPrefix, globals.UsernamePasswordCredentialPreviousPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(Domain, SshPrivateKeySubtype, SshPrivateKeyCredentialPrefix); err != nil {
if err := subtypes.Register(Domain, SshPrivateKeySubtype, globals.SshPrivateKeyCredentialPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(Domain, JsonSubtype, JsonCredentialPrefix); err != nil {
if err := subtypes.Register(Domain, JsonSubtype, globals.JsonCredentialPrefix); err != nil {
panic(err)
}
}
const (
UsernamePasswordCredentialPrefix = "credup"
PreviousUsernamePasswordCredentialPrefix = "cred"
UsernamePasswordSubtype = subtypes.Subtype("username_password")
UsernamePasswordSubtype = subtypes.Subtype("username_password")
SshPrivateKeyCredentialPrefix = "credspk"
SshPrivateKeySubtype = subtypes.Subtype("ssh_private_key")
SshPrivateKeySubtype = subtypes.Subtype("ssh_private_key")
JsonCredentialPrefix = "credjson"
JsonSubtype = subtypes.Subtype("json")
JsonSubtype = subtypes.Subtype("json")
)
func NewUsernamePasswordCredentialId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(UsernamePasswordCredentialPrefix)
id, err := db.NewPublicId(globals.UsernamePasswordCredentialPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "credential.NewUsernamePasswordCredentialId")
}
@@ -44,7 +41,7 @@ func NewUsernamePasswordCredentialId(ctx context.Context) (string, error) {
}
func NewSshPrivateKeyCredentialId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(SshPrivateKeyCredentialPrefix)
id, err := db.NewPublicId(globals.SshPrivateKeyCredentialPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "credential.NewSshPrivateKeyCredentialId")
}
@@ -52,7 +49,7 @@ func NewSshPrivateKeyCredentialId(ctx context.Context) (string, error) {
}
func NewJsonCredentialId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(JsonCredentialPrefix)
id, err := db.NewPublicId(globals.JsonCredentialPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "credential.NewJsonCredentialId")
}
+3 -5
View File
@@ -6,6 +6,7 @@ package static
import (
"context"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
@@ -13,21 +14,18 @@ import (
)
func init() {
if err := subtypes.Register(credential.Domain, Subtype, CredentialStorePrefix, PreviousCredentialStorePrefix); err != nil {
if err := subtypes.Register(credential.Domain, Subtype, globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the static package.
const (
CredentialStorePrefix = "csst"
PreviousCredentialStorePrefix = "cs"
Subtype = subtypes.Subtype("static")
)
func newCredentialStoreId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(CredentialStorePrefix)
id, err := db.NewPublicId(globals.StaticCredentialStorePrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "static.newCredentialStoreId")
}
@@ -9,6 +9,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential/static/store"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
@@ -117,7 +118,7 @@ func TestRepository_CreateCredentialStore(t *testing.T) {
require.NoError(err)
assert.Empty(tt.store.PublicId)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.StaticCredentialStorePrefix, got.PublicId)
assert.NotSame(tt.store, got)
assert.Equal(got.CreateTime, got.UpdateTime)
assert.NoError(db.TestVerifyOplog(t, rw, got.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_CREATE), db.WithCreateNotBefore(10*time.Second)))
@@ -506,7 +507,7 @@ func TestRepository_UpdateCredentialStore(t *testing.T) {
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.StaticCredentialStorePrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.ProjectId, got.ProjectId)
@@ -582,7 +583,7 @@ func TestRepository_UpdateCredentialStore(t *testing.T) {
got, err := repo.CreateCredentialStore(ctx, in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.StaticCredentialStorePrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -9,6 +9,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/static/store"
"github.com/hashicorp/boundary/internal/db"
@@ -128,7 +129,7 @@ func TestRepository_CreateUsernamePasswordCredential(t *testing.T) {
return
}
require.NoError(err)
assertPublicId(t, credential.UsernamePasswordCredentialPrefix, got.PublicId)
assertPublicId(t, globals.UsernamePasswordCredentialPrefix, got.PublicId)
assert.Equal(tt.cred.Username, got.Username)
assert.Nil(got.Password)
assert.Nil(got.CtPassword)
@@ -323,7 +324,7 @@ func TestRepository_CreateSshPrivateKeyCredential(t *testing.T) {
return
}
require.NoError(err)
assertPublicId(t, credential.SshPrivateKeyCredentialPrefix, got.PublicId)
assertPublicId(t, globals.SshPrivateKeyCredentialPrefix, got.PublicId)
assert.Equal(tt.cred.Username, got.Username)
assert.Nil(got.PrivateKey)
assert.Nil(got.PrivateKeyEncrypted)
@@ -494,7 +495,7 @@ func TestRepository_CreateJsonCredential(t *testing.T) {
return
}
require.NoError(err)
assertPublicId(t, credential.JsonCredentialPrefix, got.PublicId)
assertPublicId(t, globals.JsonCredentialPrefix, got.PublicId)
assert.Nil(got.Object)
assert.Nil(got.ObjectEncrypted)
@@ -1303,7 +1304,7 @@ func TestRepository_UpdateUsernamePasswordCredential(t *testing.T) {
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, credential.UsernamePasswordCredentialPrefix, got.PublicId)
assertPublicId(t, globals.UsernamePasswordCredentialPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.StoreId, got.StoreId)
@@ -1894,7 +1895,7 @@ Hdtbe1Kk0rHxN0yIKqXNAAAACWplZmZAYXJjaAECAwQ=
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, credential.SshPrivateKeyCredentialPrefix, got.PublicId)
assertPublicId(t, globals.SshPrivateKeyCredentialPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.StoreId, got.StoreId)
@@ -2406,7 +2407,7 @@ func TestRepository_UpdateJsonCredential(t *testing.T) {
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, credential.JsonCredentialPrefix, got.PublicId)
assertPublicId(t, globals.JsonCredentialPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.StoreId, got.StoreId)
+9 -10
View File
@@ -4,6 +4,7 @@
package vault
import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
@@ -11,23 +12,21 @@ import (
)
func init() {
if err := subtypes.Register(credential.Domain, Subtype, CredentialStorePrefix, DynamicCredentialPrefix); err != nil {
if err := subtypes.Register(credential.Domain, Subtype, globals.VaultCredentialStorePrefix, DynamicCredentialPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(credential.Domain, GenericLibrarySubtype, CredentialLibraryPrefix); err != nil {
if err := subtypes.Register(credential.Domain, GenericLibrarySubtype, globals.VaultCredentialLibraryPrefix); err != nil {
panic(err)
}
if err := subtypes.Register(credential.Domain, SSHCertificateLibrarySubtype, SSHCertificateCredentialLibraryPrefix); err != nil {
if err := subtypes.Register(credential.Domain, SSHCertificateLibrarySubtype, globals.VaultSshCertificateCredentialLibraryPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the vault package.
const (
CredentialStorePrefix = "csvlt"
CredentialLibraryPrefix = "clvlt"
DynamicCredentialPrefix = "cdvlt"
SSHCertificateCredentialLibraryPrefix = "clvsclt"
// DynamicCredentialPrefix is the prefix for Vault dynamic credentials
DynamicCredentialPrefix = "cdvlt"
Subtype = subtypes.Subtype("vault")
GenericLibrarySubtype = subtypes.Subtype("vault-generic")
@@ -35,7 +34,7 @@ const (
)
func newCredentialStoreId() (string, error) {
id, err := db.NewPublicId(CredentialStorePrefix)
id, err := db.NewPublicId(globals.VaultCredentialStorePrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "vault.newCredentialStoreId")
}
@@ -51,7 +50,7 @@ func newCredentialId() (string, error) {
}
func newCredentialLibraryId() (string, error) {
id, err := db.NewPublicId(CredentialLibraryPrefix)
id, err := db.NewPublicId(globals.VaultCredentialLibraryPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "vault.newCredentialLibraryId")
}
@@ -59,7 +58,7 @@ func newCredentialLibraryId() (string, error) {
}
func newSSHCertificateCredentialLibraryId() (string, error) {
id, err := db.NewPublicId(SSHCertificateCredentialLibraryPrefix)
id, err := db.NewPublicId(globals.VaultSshCertificateCredentialLibraryPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "vault.newSSHCertificateCredentialLibraryPrefix")
}
@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault/store"
"github.com/hashicorp/boundary/internal/db"
@@ -458,7 +459,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, CredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -521,7 +522,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
got, err := repo.CreateCredentialLibrary(ctx, prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, CredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -559,7 +560,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
got, err := repo.CreateCredentialLibrary(ctx, prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, CredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -569,7 +570,7 @@ func TestRepository_CreateCredentialLibrary(t *testing.T) {
got2, err := repo.CreateCredentialLibrary(ctx, prj.GetPublicId(), in2)
require.NoError(err)
require.NotNil(got2)
assertPublicId(t, CredentialLibraryPrefix, got2.GetPublicId())
assertPublicId(t, globals.VaultCredentialLibraryPrefix, got2.GetPublicId())
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -1496,7 +1497,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
require.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, CredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultCredentialLibraryPrefix, got.GetPublicId())
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.StoreId, got.StoreId)
@@ -1603,7 +1604,7 @@ func TestRepository_UpdateCredentialLibrary(t *testing.T) {
got, err := repo.CreateCredentialLibrary(ctx, prj.GetPublicId(), in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, CredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -13,6 +13,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential/vault/store"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
@@ -57,7 +58,7 @@ func TestRepository_CreateCredentialStoreResource(t *testing.T) {
require.NoError(err)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.VaultCredentialStorePrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
@@ -91,7 +92,7 @@ func TestRepository_CreateCredentialStoreResource(t *testing.T) {
got1, err := repo.CreateCredentialStore(ctx, in1)
require.NoError(err)
require.NotNil(got1)
assertPublicId(t, CredentialStorePrefix, got1.PublicId)
assertPublicId(t, globals.VaultCredentialStorePrefix, got1.PublicId)
assert.NotSame(in1, got1)
assert.Equal(in1.Name, got1.Name)
assert.Equal(in1.Description, got1.Description)
@@ -106,7 +107,7 @@ func TestRepository_CreateCredentialStoreResource(t *testing.T) {
got2, err := repo.CreateCredentialStore(ctx, in2)
require.NoError(err)
require.NotNil(got2)
assertPublicId(t, CredentialStorePrefix, got2.PublicId)
assertPublicId(t, globals.VaultCredentialStorePrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -214,7 +215,7 @@ func TestRepository_CreateCredentialStoreNonResource(t *testing.T) {
require.NoError(err)
assert.Empty(credStoreIn.PublicId)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.VaultCredentialStorePrefix, got.PublicId)
assert.NotSame(credStoreIn, got)
assert.Equal(got.CreateTime, got.UpdateTime)
assert.NoError(db.TestVerifyOplog(t, rw, got.PublicId, db.WithOperation(oplog.OpType_OP_TYPE_CREATE), db.WithCreateNotBefore(10*time.Second)))
@@ -777,7 +778,7 @@ func TestRepository_UpdateCredentialStore_Attributes(t *testing.T) {
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.VaultCredentialStorePrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.ProjectId, got.ProjectId)
@@ -981,7 +982,7 @@ func TestRepository_UpdateCredentialStore_Attributes(t *testing.T) {
got, err := repo.CreateCredentialStore(ctx, in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, CredentialStorePrefix, got.PublicId)
assertPublicId(t, globals.VaultCredentialStorePrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault/store"
"github.com/hashicorp/boundary/internal/db"
@@ -598,7 +599,7 @@ func TestRepository_CreateSSHCertificateCredentialLibrary(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -638,7 +639,7 @@ func TestRepository_CreateSSHCertificateCredentialLibrary(t *testing.T) {
got, err := repo.CreateSSHCertificateCredentialLibrary(ctx, prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -677,7 +678,7 @@ func TestRepository_CreateSSHCertificateCredentialLibrary(t *testing.T) {
got, err := repo.CreateSSHCertificateCredentialLibrary(ctx, prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -687,7 +688,7 @@ func TestRepository_CreateSSHCertificateCredentialLibrary(t *testing.T) {
got2, err := repo.CreateSSHCertificateCredentialLibrary(ctx, prj.GetPublicId(), in2)
require.NoError(err)
require.NotNil(got2)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got2.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got2.GetPublicId())
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -1591,7 +1592,7 @@ func TestRepository_UpdateSSHCertificateCredentialLibrary(t *testing.T) {
require.NoError(err)
assert.Empty(ttOrig.PublicId)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(ttOrig, got)
assert.Equal(ttOrig.StoreId, got.StoreId)
@@ -1729,7 +1730,7 @@ func TestRepository_UpdateSSHCertificateCredentialLibrary(t *testing.T) {
got, err := repo.CreateSSHCertificateCredentialLibrary(ctx, prj.GetPublicId(), in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -1855,7 +1856,7 @@ func TestRepository_UpdateSSHCertificateCredentialLibrary(t *testing.T) {
require.NoError(err)
assert.Empty(in.PublicId)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.Equal(1, gotCount, "row count")
assert.NotSame(orig, got)
assert.Equal(orig.StoreId, got.StoreId)
@@ -1866,7 +1867,7 @@ func TestRepository_UpdateSSHCertificateCredentialLibrary(t *testing.T) {
got, gotCount, err = repo.UpdateSSHCertificateCredentialLibrary(ctx, prj.GetPublicId(), orig, 2, []string{keyTypeField, keyBitsField})
require.NoError(err)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.Equal(1, gotCount, "row count")
assert.NotSame(orig, got)
assert.Equal(orig.StoreId, got.StoreId)
@@ -1876,7 +1877,7 @@ func TestRepository_UpdateSSHCertificateCredentialLibrary(t *testing.T) {
got, gotCount, err = repo.UpdateSSHCertificateCredentialLibrary(ctx, prj.GetPublicId(), orig, 3, []string{keyTypeField})
require.NoError(err)
require.NotNil(got)
assertPublicId(t, SSHCertificateCredentialLibraryPrefix, got.GetPublicId())
assertPublicId(t, globals.VaultSshCertificateCredentialLibraryPrefix, got.GetPublicId())
assert.Equal(1, gotCount, "row count")
assert.NotSame(orig, got)
assert.Equal(orig.StoreId, got.StoreId)
@@ -21,7 +21,6 @@ import (
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/errors"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/types/action"
@@ -947,7 +946,7 @@ func validateGetRequest(req *pbs.GetAccountRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix, globals.OidcAccountPrefix)
}
func validateCreateRequest(req *pbs.CreateAccountRequest) error {
@@ -1039,7 +1038,7 @@ func validateUpdateRequest(req *pbs.UpdateAccountRequest) error {
}
}
return badFields
}, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
}, globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix, globals.OidcAccountPrefix)
}
func validateDeleteRequest(req *pbs.DeleteAccountRequest) error {
@@ -1047,7 +1046,7 @@ func validateDeleteRequest(req *pbs.DeleteAccountRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix, oidc.AccountPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix, globals.OidcAccountPrefix)
}
func validateListRequest(req *pbs.ListAccountsRequest) error {
@@ -1056,7 +1055,7 @@ func validateListRequest(req *pbs.ListAccountsRequest) error {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), password.AuthMethodPrefix, oidc.AuthMethodPrefix) {
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), globals.PasswordAuthMethodPrefix, globals.OidcAuthMethodPrefix) {
badFields[authMethodIdField] = "Invalid formatted identifier."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -1074,7 +1073,7 @@ func validateChangePasswordRequest(req *pbs.ChangePasswordRequest) error {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix) {
badFields[idField] = "Improperly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1098,7 +1097,7 @@ func validateSetPasswordRequest(req *pbs.SetPasswordRequest) error {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), intglobals.OldPasswordAccountPrefix, intglobals.NewPasswordAccountPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.PasswordAccountPreviousPrefix, globals.PasswordAccountPrefix) {
badFields[idField] = "Improperly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -15,7 +15,6 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
requestauth "github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -23,7 +22,6 @@ import (
"github.com/hashicorp/boundary/internal/db"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -196,19 +194,19 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existing old password account",
req: &pbs.GetAccountRequest{Id: intglobals.OldPasswordAccountPrefix + "_DoesntExis"},
req: &pbs.GetAccountRequest{Id: globals.PasswordAccountPreviousPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
name: "Get a non existing new password account",
req: &pbs.GetAccountRequest{Id: intglobals.NewPasswordAccountPrefix + "_DoesntExis"},
req: &pbs.GetAccountRequest{Id: globals.PasswordAccountPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
name: "Get a non existing oidc account",
req: &pbs.GetAccountRequest{Id: oidc.AccountPrefix + "_DoesntExis"},
req: &pbs.GetAccountRequest{Id: globals.OidcAccountPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -220,7 +218,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetAccountRequest{Id: authtoken.AuthTokenPrefix + "_1 23456789"},
req: &pbs.GetAccountRequest{Id: globals.AuthTokenPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -330,7 +328,7 @@ func TestListPassword(t *testing.T) {
},
{
name: "Unfound Auth Method",
req: &pbs.ListAccountsRequest{AuthMethodId: password.AuthMethodPrefix + "_DoesntExis"},
req: &pbs.ListAccountsRequest{AuthMethodId: globals.PasswordAuthMethodPrefix + "_DoesntExis"},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
@@ -484,7 +482,7 @@ func TestListOidc(t *testing.T) {
},
{
name: "Unfound Auth Method",
req: &pbs.ListAccountsRequest{AuthMethodId: oidc.AuthMethodPrefix + "_DoesntExis"},
req: &pbs.ListAccountsRequest{AuthMethodId: globals.OidcAuthMethodPrefix + "_DoesntExis"},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
@@ -603,21 +601,21 @@ func TestDelete(t *testing.T) {
{
name: "Delete bad old pw account id",
req: &pbs.DeleteAccountRequest{
Id: intglobals.OldPasswordAccountPrefix + "_doesntexis",
Id: globals.PasswordAccountPreviousPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
name: "Delete bad new pw account id",
req: &pbs.DeleteAccountRequest{
Id: intglobals.NewPasswordAccountPrefix + "_doesntexis",
Id: globals.PasswordAccountPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
name: "Delete bad oidc account id",
req: &pbs.DeleteAccountRequest{
Id: oidc.AccountPrefix + "_doesntexis",
Id: globals.OidcAccountPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -723,7 +721,7 @@ func TestCreatePassword(t *testing.T) {
},
},
res: &pbs.CreateAccountResponse{
Uri: fmt.Sprintf("accounts/%s_", intglobals.NewPasswordAccountPrefix),
Uri: fmt.Sprintf("accounts/%s_", globals.PasswordAccountPrefix),
Item: &pb.Account{
AuthMethodId: defaultAccount.GetAuthMethodId(),
Name: &wrapperspb.StringValue{Value: "name"},
@@ -755,7 +753,7 @@ func TestCreatePassword(t *testing.T) {
},
},
res: &pbs.CreateAccountResponse{
Uri: fmt.Sprintf("accounts/%s_", intglobals.NewPasswordAccountPrefix),
Uri: fmt.Sprintf("accounts/%s_", globals.PasswordAccountPrefix),
Item: &pb.Account{
AuthMethodId: defaultAccount.GetAuthMethodId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -787,7 +785,7 @@ func TestCreatePassword(t *testing.T) {
},
},
res: &pbs.CreateAccountResponse{
Uri: fmt.Sprintf("accounts/%s_", intglobals.NewPasswordAccountPrefix),
Uri: fmt.Sprintf("accounts/%s_", globals.PasswordAccountPrefix),
Item: &pb.Account{
AuthMethodId: defaultAccount.GetAuthMethodId(),
Name: &wrapperspb.StringValue{Value: "name_with_password"},
@@ -827,7 +825,7 @@ func TestCreatePassword(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: defaultAccount.GetAuthMethodId(),
Id: intglobals.NewPasswordAccountPrefix + "_notallowed",
Id: globals.PasswordAccountPrefix + "_notallowed",
Type: "password",
Attrs: &pb.Account_PasswordAccountAttributes{
&pb.PasswordAccountAttributes{
@@ -900,7 +898,7 @@ func TestCreatePassword(t *testing.T) {
}
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), intglobals.NewPasswordAccountPrefix+"_"))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.PasswordAccountPrefix+"_"))
gotCreateTime := got.GetItem().GetCreatedTime()
require.NoError(err, "Error converting proto to timestamp.")
gotUpdateTime := got.GetItem().GetUpdatedTime()
@@ -971,7 +969,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateAccountResponse{
Uri: fmt.Sprintf("accounts/%s_", oidc.AccountPrefix),
Uri: fmt.Sprintf("accounts/%s_", globals.OidcAccountPrefix),
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
@@ -1002,7 +1000,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateAccountResponse{
Uri: fmt.Sprintf("accounts/%s_", oidc.AccountPrefix),
Uri: fmt.Sprintf("accounts/%s_", globals.OidcAccountPrefix),
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -1034,7 +1032,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateAccountResponse{
Uri: fmt.Sprintf("accounts/%s_", oidc.AccountPrefix),
Uri: fmt.Sprintf("accounts/%s_", globals.OidcAccountPrefix),
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "overwritten issuer"},
@@ -1072,7 +1070,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateAccountRequest{
Item: &pb.Account{
AuthMethodId: am.GetPublicId(),
Id: oidc.AccountPrefix + "_notallowed",
Id: globals.OidcAccountPrefix + "_notallowed",
Type: oidc.Subtype.String(),
Attrs: &pb.Account_OidcAccountAttributes{
&pb.OidcAccountAttributes{
@@ -1142,7 +1140,7 @@ func TestCreateOidc(t *testing.T) {
require.NoError(gErr)
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), oidc.AccountPrefix+"_"))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.OidcAccountPrefix+"_"))
// Clear all values which are hard to compare against.
got.Uri, tc.res.Uri = "", ""
got.Item.Id, tc.res.Item.Id = "", ""
@@ -1409,7 +1407,7 @@ func TestUpdatePassword(t *testing.T) {
{
name: "Update a Non Existing Old ID Account",
req: &pbs.UpdateAccountRequest{
Id: intglobals.OldPasswordAccountPrefix + "_DoesntExis",
Id: globals.PasswordAccountPreviousPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{globals.DescriptionField},
},
@@ -1423,7 +1421,7 @@ func TestUpdatePassword(t *testing.T) {
{
name: "Update a Non Existing New ID Account",
req: &pbs.UpdateAccountRequest{
Id: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
Id: globals.PasswordAccountPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{globals.DescriptionField},
},
@@ -1441,7 +1439,7 @@ func TestUpdatePassword(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.Account{
Id: intglobals.NewPasswordAccountPrefix + "_somethinge",
Id: globals.PasswordAccountPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -1786,7 +1784,7 @@ func TestUpdateOidc(t *testing.T) {
{
name: "Update a Non Existing Account",
req: &pbs.UpdateAccountRequest{
Id: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
Id: globals.PasswordAccountPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{globals.DescriptionField},
},
@@ -1804,7 +1802,7 @@ func TestUpdateOidc(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.Account{
Id: intglobals.NewPasswordAccountPrefix + "_somethinge",
Id: globals.PasswordAccountPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -2033,13 +2031,13 @@ func TestSetPassword(t *testing.T) {
},
{
name: "notfound old account id",
accountId: intglobals.OldPasswordAccountPrefix + "_DoesntExis",
accountId: globals.PasswordAccountPreviousPrefix + "_DoesntExis",
version: defaultAcct.GetVersion(),
password: "anewpassword",
},
{
name: "notfound new account id",
accountId: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
accountId: globals.PasswordAccountPrefix + "_DoesntExis",
version: defaultAcct.GetVersion(),
password: "anewpassword",
},
@@ -2200,7 +2198,7 @@ func TestChangePassword(t *testing.T) {
{
name: "notfound old account id",
authMethodId: defaultAcct.GetAuthMethodId(),
accountId: intglobals.OldPasswordAccountPrefix + "_DoesntExis",
accountId: globals.PasswordAccountPreviousPrefix + "_DoesntExis",
version: defaultAcct.GetVersion(),
oldPW: "somepassword",
newPW: "anewpassword",
@@ -2208,7 +2206,7 @@ func TestChangePassword(t *testing.T) {
{
name: "notfound new account id",
authMethodId: defaultAcct.GetAuthMethodId(),
accountId: intglobals.NewPasswordAccountPrefix + "_DoesntExis",
accountId: globals.PasswordAccountPrefix + "_DoesntExis",
version: defaultAcct.GetVersion(),
oldPW: "somepassword",
newPW: "anewpassword",
@@ -8,10 +8,10 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/accounts"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -40,7 +40,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "mismatched pw authmethod oidc type",
item: &pb.Account{
Type: oidc.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
},
@@ -48,7 +48,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "mismatched oidc authmethod pw type",
item: &pb.Account{
Type: password.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(typeField, "Doesn't match the parent resource's type."),
},
@@ -56,7 +56,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "missing oidc attributes",
item: &pb.Account{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(attributesField, "This is a required field."),
},
@@ -64,7 +64,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "missing oidc subject",
item: &pb.Account{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{},
},
@@ -75,7 +75,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "read only name claim field",
item: &pb.Account{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{FullName: "something"},
},
@@ -86,7 +86,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "read only email claim field",
item: &pb.Account{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{Email: "something"},
},
@@ -97,7 +97,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "missing password attributes",
item: &pb.Account{
Type: password.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(attributesField, "This is a required field."),
},
@@ -105,7 +105,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "missing login name for password type",
item: &pb.Account{
Type: password.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_PasswordAccountAttributes{
PasswordAccountAttributes: &pb.PasswordAccountAttributes{},
},
@@ -116,7 +116,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "no error",
item: &pb.Account{
Type: password.Subtype.String(),
AuthMethodId: password.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.PasswordAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_PasswordAccountAttributes{
PasswordAccountAttributes: &pb.PasswordAccountAttributes{
LoginName: "something",
@@ -128,7 +128,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "no oidc errors",
item: &pb.Account{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.Account_OidcAccountAttributes{
OidcAccountAttributes: &pb.OidcAccountAttributes{Subject: "no oidc errors"},
},
@@ -161,7 +161,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "password to oidc change type, old prefix",
req: &pbs.UpdateAccountRequest{
Id: intglobals.OldPasswordAccountPrefix + "_1234567890",
Id: globals.PasswordAccountPreviousPrefix + "_1234567890",
Item: &pb.Account{
Type: oidc.Subtype.String(),
},
@@ -171,7 +171,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "password to oidc change type, new prefix",
req: &pbs.UpdateAccountRequest{
Id: intglobals.NewPasswordAccountPrefix + "_1234567890",
Id: globals.PasswordAccountPrefix + "_1234567890",
Item: &pb.Account{
Type: oidc.Subtype.String(),
},
@@ -181,7 +181,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "oidc to password change type",
req: &pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "_1234567890",
Id: globals.OidcAccountPrefix + "_1234567890",
Item: &pb.Account{
Type: password.Subtype.String(),
},
@@ -191,7 +191,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "no error",
req: &pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "_1234567890",
Id: globals.OidcAccountPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{}},
Item: &pb.Account{
Version: 1,
@@ -220,7 +220,7 @@ func TestValidateUpdateRequest(t *testing.T) {
nameClaimField,
}
err := validateUpdateRequest(&pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "_1234567890",
Id: globals.OidcAccountPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: readOnlyFields},
})
@@ -238,7 +238,7 @@ func TestValidateUpdateRequest(t *testing.T) {
subjectField,
}
err := validateUpdateRequest(&pbs.UpdateAccountRequest{
Id: oidc.AccountPrefix + "_1234567890",
Id: globals.OidcAccountPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: readOnlyFields},
})
@@ -829,7 +829,7 @@ func validateGetRequest(req *pbs.GetAuthMethodRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
}
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, password.AuthMethodPrefix, oidc.AuthMethodPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.PasswordAuthMethodPrefix, globals.OidcAuthMethodPrefix)
}
func validateCreateRequest(ctx context.Context, req *pbs.CreateAuthMethodRequest) error {
@@ -1055,7 +1055,7 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateAuthMethodRequest
badFields["id"] = "Incorrectly formatted identifier."
}
return badFields
}, password.AuthMethodPrefix, oidc.AuthMethodPrefix)
}, globals.PasswordAuthMethodPrefix, globals.OidcAuthMethodPrefix)
}
func validateDeleteRequest(req *pbs.DeleteAuthMethodRequest) error {
@@ -1063,7 +1063,7 @@ func validateDeleteRequest(req *pbs.DeleteAuthMethodRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "Missing request")
}
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, password.AuthMethodPrefix, oidc.AuthMethodPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.PasswordAuthMethodPrefix, globals.OidcAuthMethodPrefix)
}
func validateListRequest(req *pbs.ListAuthMethodsRequest) error {
@@ -175,7 +175,7 @@ func TestGet(t *testing.T) {
{
name: "Get a non existant AuthMethod",
scopeId: o.GetPublicId(),
req: &pbs.GetAuthMethodRequest{Id: password.AuthMethodPrefix + "_DoesntExis"},
req: &pbs.GetAuthMethodRequest{Id: globals.PasswordAuthMethodPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -189,7 +189,7 @@ func TestGet(t *testing.T) {
{
name: "space in id",
scopeId: o.GetPublicId(),
req: &pbs.GetAuthMethodRequest{Id: password.AuthMethodPrefix + "_1 23456789"},
req: &pbs.GetAuthMethodRequest{Id: globals.PasswordAuthMethodPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -456,7 +456,7 @@ func TestDelete(t *testing.T) {
{
name: "Delete bad auth_method id",
req: &pbs.DeleteAuthMethodRequest{
Id: password.AuthMethodPrefix + "_doesntexis",
Id: globals.PasswordAuthMethodPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -557,9 +557,9 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Type: "password",
}},
idPrefix: password.AuthMethodPrefix + "_",
idPrefix: globals.PasswordAuthMethodPrefix + "_",
res: &pbs.CreateAuthMethodResponse{
Uri: fmt.Sprintf("auth-methods/%s_", password.AuthMethodPrefix),
Uri: fmt.Sprintf("auth-methods/%s_", globals.PasswordAuthMethodPrefix),
Item: &pb.AuthMethod{
Id: defaultAm.GetPublicId(),
ScopeId: o.GetPublicId(),
@@ -598,9 +598,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: oidc.AuthMethodPrefix + "_",
idPrefix: globals.OidcAuthMethodPrefix + "_",
res: &pbs.CreateAuthMethodResponse{
Uri: fmt.Sprintf("auth-methods/%s_", oidc.AuthMethodPrefix),
Uri: fmt.Sprintf("auth-methods/%s_", globals.OidcAuthMethodPrefix),
Item: &pb.AuthMethod{
Id: defaultAm.GetPublicId(),
ScopeId: o.GetPublicId(),
@@ -635,9 +635,9 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Type: "password",
}},
idPrefix: password.AuthMethodPrefix + "_",
idPrefix: globals.PasswordAuthMethodPrefix + "_",
res: &pbs.CreateAuthMethodResponse{
Uri: fmt.Sprintf("auth-methods/%s_", password.AuthMethodPrefix),
Uri: fmt.Sprintf("auth-methods/%s_", globals.PasswordAuthMethodPrefix),
Item: &pb.AuthMethod{
Id: defaultAm.GetPublicId(),
ScopeId: scope.Global.String(),
@@ -673,9 +673,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: oidc.AuthMethodPrefix + "_",
idPrefix: globals.OidcAuthMethodPrefix + "_",
res: &pbs.CreateAuthMethodResponse{
Uri: fmt.Sprintf("auth-methods/%s_", oidc.AuthMethodPrefix),
Uri: fmt.Sprintf("auth-methods/%s_", globals.OidcAuthMethodPrefix),
Item: &pb.AuthMethod{
Id: defaultAm.GetPublicId(),
ScopeId: scope.Global.String(),
@@ -702,7 +702,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateAuthMethodRequest{Item: &pb.AuthMethod{
ScopeId: o.GetPublicId(),
Id: password.AuthMethodPrefix + "_notallowed",
Id: globals.PasswordAuthMethodPrefix + "_notallowed",
Type: "password",
}},
res: nil,
@@ -772,7 +772,7 @@ func TestCreate(t *testing.T) {
},
}},
res: &pbs.CreateAuthMethodResponse{
Uri: fmt.Sprintf("auth-methods/%s_", oidc.AuthMethodPrefix),
Uri: fmt.Sprintf("auth-methods/%s_", globals.OidcAuthMethodPrefix),
Item: &pb.AuthMethod{
Id: defaultAm.GetPublicId(),
ScopeId: o.GetPublicId(),
@@ -580,7 +580,7 @@ func TestUpdate_OIDC(t *testing.T) {
{
name: "Update a Non Existing AuthMethod",
req: &pbs.UpdateAuthMethodRequest{
Id: password.AuthMethodPrefix + "_DoesntExis",
Id: globals.PasswordAuthMethodPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -598,7 +598,7 @@ func TestUpdate_OIDC(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.AuthMethod{
Id: password.AuthMethodPrefix + "_somethinge",
Id: globals.PasswordAuthMethodPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
@@ -284,7 +285,7 @@ func TestUpdate_Password(t *testing.T) {
{
name: "Update a Non Existing AuthMethod",
req: &pbs.UpdateAuthMethodRequest{
Id: password.AuthMethodPrefix + "_DoesntExis",
Id: globals.PasswordAuthMethodPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -302,7 +303,7 @@ func TestUpdate_Password(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.AuthMethod{
Id: password.AuthMethodPrefix + "_somethinge",
Id: globals.PasswordAuthMethodPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -369,11 +369,11 @@ func toProto(ctx context.Context, in *authtoken.AuthToken, opt ...handlers.Optio
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetAuthTokenRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, authtoken.AuthTokenPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.AuthTokenPrefix)
}
func validateDeleteRequest(req *pbs.DeleteAuthTokenRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, authtoken.AuthTokenPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.AuthTokenPrefix)
}
func validateListRequest(req *pbs.ListAuthTokensRequest) error {
@@ -162,7 +162,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existing auth token",
req: &pbs.GetAuthTokenRequest{Id: authtoken.AuthTokenPrefix + "_DoesntExis"},
req: &pbs.GetAuthTokenRequest{Id: globals.AuthTokenPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -174,7 +174,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetAuthTokenRequest{Id: authtoken.AuthTokenPrefix + "_1 23456789"},
req: &pbs.GetAuthTokenRequest{Id: globals.AuthTokenPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -544,7 +544,7 @@ func TestDelete(t *testing.T) {
name: "Delete bad token id",
scope: org.GetPublicId(),
req: &pbs.DeleteAuthTokenRequest{
Id: authtoken.AuthTokenPrefix + "_doesntexis",
Id: globals.AuthTokenPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -861,9 +861,9 @@ func validateGetRequest(req *pbs.GetCredentialLibraryRequest) error {
prefix := ""
switch subtypes.SubtypeFromId(domain, req.GetId()) {
case vault.SSHCertificateLibrarySubtype:
prefix = vault.SSHCertificateCredentialLibraryPrefix
prefix = globals.VaultSshCertificateCredentialLibraryPrefix
default:
prefix = vault.CredentialLibraryPrefix
prefix = globals.VaultCredentialLibraryPrefix
}
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, prefix)
}
@@ -984,9 +984,9 @@ func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest, currentCrede
st := subtypes.SubtypeFromId(domain, req.GetId())
switch st {
case vault.GenericLibrarySubtype:
prefix = vault.CredentialLibraryPrefix
prefix = globals.VaultCredentialLibraryPrefix
case vault.SSHCertificateLibrarySubtype:
prefix = vault.SSHCertificateCredentialLibraryPrefix
prefix = globals.VaultSshCertificateCredentialLibraryPrefix
}
return handlers.ValidateUpdateRequest(req, req.GetItem(), func() map[string]string {
badFields := map[string]string{}
@@ -1041,12 +1041,12 @@ func validateUpdateRequest(req *pbs.UpdateCredentialLibraryRequest, currentCrede
}
func validateDeleteRequest(req *pbs.DeleteCredentialLibraryRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, vault.CredentialLibraryPrefix, vault.SSHCertificateCredentialLibraryPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.VaultCredentialLibraryPrefix, globals.VaultSshCertificateCredentialLibraryPrefix)
}
func validateListRequest(req *pbs.ListCredentialLibrariesRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetCredentialStoreId()), vault.CredentialStorePrefix) {
if !handlers.ValidId(handlers.Id(req.GetCredentialStoreId()), globals.VaultCredentialStorePrefix) {
badFields[globals.CredentialStoreIdField] = "This field must be a valid credential store id."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -20,7 +20,6 @@ import (
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/scheduler"
@@ -321,7 +320,7 @@ func TestCreate(t *testing.T) {
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{},
},
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
wantErr: true,
},
{
@@ -329,7 +328,7 @@ func TestCreate(t *testing.T) {
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.GenericLibrarySubtype.String(),
Id: vault.CredentialLibraryPrefix + "_notallowed",
Id: globals.VaultCredentialLibraryPrefix + "_notallowed",
Attrs: &pb.CredentialLibrary_VaultGenericCredentialLibraryAttributes{
VaultGenericCredentialLibraryAttributes: &pb.VaultCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -493,9 +492,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -528,9 +527,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -563,9 +562,9 @@ func TestCreate(t *testing.T) {
},
CredentialType: string(credential.UsernamePasswordType),
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -605,9 +604,9 @@ func TestCreate(t *testing.T) {
}(),
CredentialType: string(credential.UsernamePasswordType),
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -656,9 +655,9 @@ func TestCreate(t *testing.T) {
}(),
CredentialType: string(credential.UsernamePasswordType),
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -699,9 +698,9 @@ func TestCreate(t *testing.T) {
},
CredentialType: string(credential.SshPrivateKeyType),
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -743,9 +742,9 @@ func TestCreate(t *testing.T) {
}(),
CredentialType: string(credential.SshPrivateKeyType),
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -786,9 +785,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -822,9 +821,9 @@ func TestCreate(t *testing.T) {
},
},
},
idPrefix: vault.CredentialLibraryPrefix + "_",
idPrefix: globals.VaultCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.CredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -1055,12 +1054,12 @@ func TestGet(t *testing.T) {
},
{
name: "not found error",
id: fmt.Sprintf("%s_1234567890", vault.CredentialLibraryPrefix),
id: fmt.Sprintf("%s_1234567890", globals.VaultCredentialLibraryPrefix),
err: handlers.NotFoundError(),
},
{
name: "bad prefix",
id: fmt.Sprintf("%s_1234567890", static.HostPrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticHostPrefix),
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
}
@@ -1126,12 +1125,12 @@ func TestDelete(t *testing.T) {
},
{
name: "not found error",
id: fmt.Sprintf("%s_1234567890", vault.CredentialLibraryPrefix),
id: fmt.Sprintf("%s_1234567890", globals.VaultCredentialLibraryPrefix),
err: handlers.NotFoundError(),
},
{
name: "bad prefix",
id: fmt.Sprintf("%s_1234567890", static.HostPrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticHostPrefix),
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
}
@@ -1961,7 +1960,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
},
},
}},
idPrefix: vault.SSHCertificateCredentialLibraryPrefix + "_",
idPrefix: globals.VaultSshCertificateCredentialLibraryPrefix + "_",
wantErr: true,
},
{
@@ -1975,7 +1974,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
},
},
}},
idPrefix: vault.SSHCertificateCredentialLibraryPrefix + "_",
idPrefix: globals.VaultSshCertificateCredentialLibraryPrefix + "_",
wantErr: true,
},
{
@@ -1983,7 +1982,7 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
req: &pbs.CreateCredentialLibraryRequest{Item: &pb.CredentialLibrary{
CredentialStoreId: store.GetPublicId(),
Type: vault.SSHCertificateLibrarySubtype.String(),
Id: vault.SSHCertificateCredentialLibraryPrefix + "_notallowed",
Id: globals.VaultSshCertificateCredentialLibraryPrefix + "_notallowed",
Attrs: &pb.CredentialLibrary_VaultSshCertificateCredentialLibraryAttributes{
VaultSshCertificateCredentialLibraryAttributes: &pb.VaultSSHCertificateCredentialLibraryAttributes{
Path: wrapperspb.String("something"),
@@ -2102,9 +2101,9 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
},
},
}},
idPrefix: vault.SSHCertificateCredentialLibraryPrefix + "_",
idPrefix: globals.VaultSshCertificateCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.SSHCertificateCredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultSshCertificateCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -2141,9 +2140,9 @@ func TestCreate_SSHCertificateCredentialLibrary(t *testing.T) {
},
},
}},
idPrefix: vault.SSHCertificateCredentialLibraryPrefix + "_",
idPrefix: globals.VaultSshCertificateCredentialLibraryPrefix + "_",
res: &pbs.CreateCredentialLibraryResponse{
Uri: fmt.Sprintf("credential-libraries/%s_", vault.SSHCertificateCredentialLibraryPrefix),
Uri: fmt.Sprintf("credential-libraries/%s_", globals.VaultSshCertificateCredentialLibraryPrefix),
Item: &pb.CredentialLibrary{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -728,17 +728,17 @@ func validateGetRequest(req *pbs.GetCredentialRequest) error {
return handlers.ValidateGetRequest(
handlers.NoopValidatorFn,
req,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix,
)
}
func validateCreateRequest(req *pbs.CreateCredentialRequest) error {
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.Item.GetCredentialStoreId()), static.CredentialStorePrefix, static.PreviousCredentialStorePrefix) {
if !handlers.ValidId(handlers.Id(req.Item.GetCredentialStoreId()), globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix) {
badFields[globals.CredentialStoreIdField] = "This field must be a valid credential store id."
}
@@ -869,10 +869,10 @@ func validateUpdateRequest(req *pbs.UpdateCredentialRequest) error {
return badFields
},
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix,
)
}
@@ -880,16 +880,16 @@ func validateDeleteRequest(req *pbs.DeleteCredentialRequest) error {
return handlers.ValidateDeleteRequest(
handlers.NoopValidatorFn,
req,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix,
)
}
func validateListRequest(req *pbs.ListCredentialsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetCredentialStoreId()), static.CredentialStorePrefix, static.PreviousCredentialStorePrefix) {
if !handlers.ValidId(handlers.Id(req.GetCredentialStoreId()), globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix) {
badFields[globals.CredentialStoreIdField] = "This field must be a valid credential store id."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -226,7 +226,7 @@ func TestGet(t *testing.T) {
require.NoError(t, err)
upCred := static.TestUsernamePasswordCredential(t, conn, wrapper, "user", "pass", store.GetPublicId(), prj.GetPublicId())
upCredPrev := static.TestUsernamePasswordCredential(t, conn, wrapper, "user", "pass", store.GetPublicId(), prj.GetPublicId(), static.WithPublicId(fmt.Sprintf("%s_1234567890", credential.PreviousUsernamePasswordCredentialPrefix)))
upCredPrev := static.TestUsernamePasswordCredential(t, conn, wrapper, "user", "pass", store.GetPublicId(), prj.GetPublicId(), static.WithPublicId(fmt.Sprintf("%s_1234567890", globals.UsernamePasswordCredentialPreviousPrefix)))
upHm, err := crypto.HmacSha256(context.Background(), []byte("pass"), databaseWrapper, []byte(store.GetPublicId()), nil, crypto.WithEd25519())
require.NoError(t, err)
@@ -367,12 +367,12 @@ func TestGet(t *testing.T) {
},
{
name: "not found error",
id: fmt.Sprintf("%s_1234567890", credential.UsernamePasswordCredentialPrefix),
id: fmt.Sprintf("%s_1234567890", globals.UsernamePasswordCredentialPrefix),
err: handlers.NotFoundError(),
},
{
name: "bad prefix",
id: fmt.Sprintf("%s_1234567890", static.CredentialStorePrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticCredentialStorePrefix),
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
}
@@ -450,12 +450,12 @@ func TestDelete(t *testing.T) {
},
{
name: "not found error",
id: fmt.Sprintf("%s_1234567890", credential.UsernamePasswordCredentialPrefix),
id: fmt.Sprintf("%s_1234567890", globals.UsernamePasswordCredentialPrefix),
err: handlers.NotFoundError(),
},
{
name: "bad prefix",
id: fmt.Sprintf("%s_1234567890", static.CredentialStorePrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticCredentialStorePrefix),
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
}
@@ -508,7 +508,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateCredentialRequest{Item: &pb.Credential{
CredentialStoreId: store.GetPublicId(),
Id: credential.UsernamePasswordCredentialPrefix + "_notallowed",
Id: globals.UsernamePasswordCredentialPrefix + "_notallowed",
Type: credential.UsernamePasswordSubtype.String(),
Attrs: &pb.Credential_UsernamePasswordAttributes{
UsernamePasswordAttributes: &pb.UsernamePasswordAttributes{
@@ -646,9 +646,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: credential.UsernamePasswordCredentialPrefix + "_",
idPrefix: globals.UsernamePasswordCredentialPrefix + "_",
res: &pbs.CreateCredentialResponse{
Uri: fmt.Sprintf("credentials/%s_", credential.UsernamePasswordCredentialPrefix),
Uri: fmt.Sprintf("credentials/%s_", globals.UsernamePasswordCredentialPrefix),
Item: &pb.Credential{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -673,9 +673,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: credential.SshPrivateKeyCredentialPrefix + "_",
idPrefix: globals.SshPrivateKeyCredentialPrefix + "_",
res: &pbs.CreateCredentialResponse{
Uri: fmt.Sprintf("credentials/%s_", credential.SshPrivateKeyCredentialPrefix),
Uri: fmt.Sprintf("credentials/%s_", globals.SshPrivateKeyCredentialPrefix),
Item: &pb.Credential{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -701,9 +701,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: credential.SshPrivateKeyCredentialPrefix + "_",
idPrefix: globals.SshPrivateKeyCredentialPrefix + "_",
res: &pbs.CreateCredentialResponse{
Uri: fmt.Sprintf("credentials/%s_", credential.SshPrivateKeyCredentialPrefix),
Uri: fmt.Sprintf("credentials/%s_", globals.SshPrivateKeyCredentialPrefix),
Item: &pb.Credential{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -727,9 +727,9 @@ func TestCreate(t *testing.T) {
},
},
}},
idPrefix: credential.JsonCredentialPrefix + "_",
idPrefix: globals.JsonCredentialPrefix + "_",
res: &pbs.CreateCredentialResponse{
Uri: fmt.Sprintf("credentials/%s_", credential.JsonCredentialPrefix),
Uri: fmt.Sprintf("credentials/%s_", globals.JsonCredentialPrefix),
Item: &pb.Credential{
Id: store.GetPublicId(),
CredentialStoreId: store.GetPublicId(),
@@ -778,7 +778,7 @@ func toStorageVaultStore(ctx context.Context, scopeId string, in *pb.CredentialS
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetCredentialStoreRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, vault.CredentialStorePrefix, static.CredentialStorePrefix, static.PreviousCredentialStorePrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.VaultCredentialStorePrefix, globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix)
}
func validateCreateRequest(ctx context.Context, req *pbs.CreateCredentialStoreRequest) error {
@@ -875,11 +875,11 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateCredentialStoreRe
}
}
return badFields
}, vault.CredentialStorePrefix, static.CredentialStorePrefix, static.PreviousCredentialStorePrefix)
}, globals.VaultCredentialStorePrefix, globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix)
}
func validateDeleteRequest(req *pbs.DeleteCredentialStoreRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, vault.CredentialStorePrefix, static.CredentialStorePrefix, static.PreviousCredentialStorePrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.VaultCredentialStorePrefix, globals.StaticCredentialStorePrefix, globals.StaticCredentialStorePreviousPrefix)
}
func validateListRequest(req *pbs.ListCredentialStoresRequest) error {
@@ -22,7 +22,6 @@ import (
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/scheduler"
@@ -268,7 +267,7 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
wantErr: true,
},
{
@@ -286,7 +285,7 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
wantErr: true,
},
{
@@ -303,7 +302,7 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
{
@@ -320,7 +319,7 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
{
@@ -338,14 +337,14 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
{
name: "Can't specify Id",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Id: vault.CredentialStorePrefix + "_notallowed",
Id: globals.VaultCredentialStorePrefix + "_notallowed",
Type: vault.Subtype.String(),
Attrs: &pb.CredentialStore_VaultCredentialStoreAttributes{
VaultCredentialStoreAttributes: &pb.VaultCredentialStoreAttributes{
@@ -463,9 +462,9 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
res: &pbs.CreateCredentialStoreResponse{
Uri: fmt.Sprintf("credential-stores/%s_", vault.CredentialStorePrefix),
Uri: fmt.Sprintf("credential-stores/%s_", globals.VaultCredentialStorePrefix),
Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
@@ -503,9 +502,9 @@ func TestCreateVault(t *testing.T) {
},
},
}},
idPrefix: vault.CredentialStorePrefix + "_",
idPrefix: globals.VaultCredentialStorePrefix + "_",
res: &pbs.CreateCredentialStoreResponse{
Uri: fmt.Sprintf("credential-stores/%s_", vault.CredentialStorePrefix),
Uri: fmt.Sprintf("credential-stores/%s_", globals.VaultCredentialStorePrefix),
Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
@@ -629,7 +628,7 @@ func TestCreateStatic(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateCredentialStoreRequest{Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Id: credstatic.CredentialStorePrefix + "_notallowed",
Id: globals.StaticCredentialStorePrefix + "_notallowed",
Type: credstatic.Subtype.String(),
}},
res: nil,
@@ -669,9 +668,9 @@ func TestCreateStatic(t *testing.T) {
ScopeId: prj.GetPublicId(),
Type: credstatic.Subtype.String(),
}},
idPrefix: credstatic.CredentialStorePrefix + "_",
idPrefix: globals.StaticCredentialStorePrefix + "_",
res: &pbs.CreateCredentialStoreResponse{
Uri: fmt.Sprintf("credential-stores/%s_", credstatic.CredentialStorePrefix),
Uri: fmt.Sprintf("credential-stores/%s_", globals.StaticCredentialStorePrefix),
Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
@@ -690,9 +689,9 @@ func TestCreateStatic(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
Type: credstatic.Subtype.String(),
}},
idPrefix: credstatic.CredentialStorePrefix + "_",
idPrefix: globals.StaticCredentialStorePrefix + "_",
res: &pbs.CreateCredentialStoreResponse{
Uri: fmt.Sprintf("credential-stores/%s_", credstatic.CredentialStorePrefix),
Uri: fmt.Sprintf("credential-stores/%s_", globals.StaticCredentialStorePrefix),
Item: &pb.CredentialStore{
ScopeId: prj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: prj.GetPublicId(), Type: prj.GetType(), ParentScopeId: prj.GetParentId()},
@@ -774,7 +773,7 @@ func TestGet(t *testing.T) {
vaultStore := vault.TestCredentialStores(t, conn, wrapper, prj.GetPublicId(), 1)[0]
staticStore := credstatic.TestCredentialStore(t, conn, wrapper, prj.GetPublicId())
staticStorePrev := credstatic.TestCredentialStore(t, conn, wrapper, prj.GetPublicId(), credstatic.WithPublicId(fmt.Sprintf("%s_1234567890", credstatic.PreviousCredentialStorePrefix)))
staticStorePrev := credstatic.TestCredentialStore(t, conn, wrapper, prj.GetPublicId(), credstatic.WithPublicId(fmt.Sprintf("%s_1234567890", globals.StaticCredentialStorePreviousPrefix)))
s, err := NewService(ctx, vaultRepoFn, staticRepoFn, iamRepoFn)
require.NoError(t, err)
@@ -846,17 +845,17 @@ func TestGet(t *testing.T) {
},
{
name: "vault not found error",
id: fmt.Sprintf("%s_1234567890", vault.CredentialStorePrefix),
id: fmt.Sprintf("%s_1234567890", globals.VaultCredentialStorePrefix),
err: handlers.NotFoundError(),
},
{
name: "static not found error",
id: fmt.Sprintf("%s_1234567890", credstatic.CredentialStorePrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticCredentialStorePrefix),
err: handlers.NotFoundError(),
},
{
name: "bad prefix",
id: fmt.Sprintf("%s_1234567890", static.HostPrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticHostPrefix),
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
}
@@ -927,17 +926,17 @@ func TestDelete(t *testing.T) {
},
{
name: "vault not found error",
id: fmt.Sprintf("%s_1234567890", vault.CredentialStorePrefix),
id: fmt.Sprintf("%s_1234567890", globals.VaultCredentialStorePrefix),
err: handlers.NotFoundError(),
},
{
name: "static not found error",
id: fmt.Sprintf("%s_1234567890", credstatic.CredentialStorePrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticCredentialStorePrefix),
err: handlers.NotFoundError(),
},
{
name: "bad prefix",
id: fmt.Sprintf("%s_1234567890", static.HostPrefix),
id: fmt.Sprintf("%s_1234567890", globals.StaticHostPrefix),
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
}
@@ -658,7 +658,7 @@ func toProto(ctx context.Context, in *iam.Group, members []*iam.GroupMember, opt
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetGroupRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, iam.GroupPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.GroupPrefix)
}
func validateCreateRequest(req *pbs.CreateGroupRequest) error {
@@ -674,11 +674,11 @@ func validateCreateRequest(req *pbs.CreateGroupRequest) error {
}
func validateUpdateRequest(req *pbs.UpdateGroupRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), handlers.NoopValidatorFn, iam.GroupPrefix)
return handlers.ValidateUpdateRequest(req, req.GetItem(), handlers.NoopValidatorFn, globals.GroupPrefix)
}
func validateDeleteRequest(req *pbs.DeleteGroupRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, iam.GroupPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.GroupPrefix)
}
func validateListRequest(req *pbs.ListGroupsRequest) error {
@@ -699,7 +699,7 @@ func validateListRequest(req *pbs.ListGroupsRequest) error {
func validateAddGroupMembersRequest(req *pbs.AddGroupMembersRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.GroupPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.GroupPrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -709,7 +709,7 @@ func validateAddGroupMembersRequest(req *pbs.AddGroupMembersRequest) error {
badFields["member_ids"] = "Must be non-empty."
}
for _, id := range req.GetMemberIds() {
if !handlers.ValidId(handlers.Id(id), iam.UserPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.UserPrefix) {
badFields["member_ids"] = fmt.Sprintf("Must only contain valid user ids but found %q.", id)
break
}
@@ -726,14 +726,14 @@ func validateAddGroupMembersRequest(req *pbs.AddGroupMembersRequest) error {
func validateSetGroupMembersRequest(req *pbs.SetGroupMembersRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.GroupPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.GroupPrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
badFields["version"] = "Required field."
}
for _, id := range req.GetMemberIds() {
if !handlers.ValidId(handlers.Id(id), iam.UserPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.UserPrefix) {
badFields["member_ids"] = fmt.Sprintf("Must only contain valid user ids but found %q.", id)
break
}
@@ -750,7 +750,7 @@ func validateSetGroupMembersRequest(req *pbs.SetGroupMembersRequest) error {
func validateRemoveGroupMembersRequest(req *pbs.RemoveGroupMembersRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.GroupPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.GroupPrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -760,7 +760,7 @@ func validateRemoveGroupMembersRequest(req *pbs.RemoveGroupMembersRequest) error
badFields["member_ids"] = "Must be non-empty."
}
for _, id := range req.GetMemberIds() {
if !handlers.ValidId(handlers.Id(id), iam.UserPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.UserPrefix) {
badFields["member_ids"] = fmt.Sprintf("Must only contain valid user ids but found %q.", id)
break
}
@@ -149,7 +149,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existant Group",
req: &pbs.GetGroupRequest{Id: iam.GroupPrefix + "_DoesntExis"},
req: &pbs.GetGroupRequest{Id: globals.GroupPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -161,7 +161,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetGroupRequest{Id: iam.GroupPrefix + "_1 23456789"},
req: &pbs.GetGroupRequest{Id: globals.GroupPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -174,7 +174,7 @@ func TestGet(t *testing.T) {
{
name: "Project Scoped Get a non existant Group",
scopeId: pg.GetScopeId(),
req: &pbs.GetGroupRequest{Id: iam.GroupPrefix + "_DoesntExis"},
req: &pbs.GetGroupRequest{Id: globals.GroupPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -188,7 +188,7 @@ func TestGet(t *testing.T) {
{
name: "Project Scoped space in id",
scopeId: pg.GetScopeId(),
req: &pbs.GetGroupRequest{Id: iam.GroupPrefix + "_1 23456789"},
req: &pbs.GetGroupRequest{Id: globals.GroupPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -371,7 +371,7 @@ func TestDelete(t *testing.T) {
name: "Delete bad group id",
scopeId: og.GetScopeId(),
req: &pbs.DeleteGroupRequest{
Id: iam.GroupPrefix + "_doesntexis",
Id: globals.GroupPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -394,7 +394,7 @@ func TestDelete(t *testing.T) {
name: "Project Scoped Delete bad group id",
scopeId: pg.GetScopeId(),
req: &pbs.DeleteGroupRequest{
Id: iam.GroupPrefix + "_doesntexis",
Id: globals.GroupPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -460,7 +460,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
}},
res: &pbs.CreateGroupResponse{
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
Uri: fmt.Sprintf("groups/%s_", globals.GroupPrefix),
Item: &pb.Group{
ScopeId: defaultOGroup.GetScopeId(),
Scope: &scopes.ScopeInfo{Id: defaultOGroup.GetScopeId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -479,7 +479,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
}},
res: &pbs.CreateGroupResponse{
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
Uri: fmt.Sprintf("groups/%s_", globals.GroupPrefix),
Item: &pb.Group{
ScopeId: scope.Global.String(),
Scope: &scopes.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String(), Name: scope.Global.String(), Description: "Global Scope"},
@@ -500,7 +500,7 @@ func TestCreate(t *testing.T) {
},
},
res: &pbs.CreateGroupResponse{
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
Uri: fmt.Sprintf("groups/%s_", globals.GroupPrefix),
Item: &pb.Group{
ScopeId: defaultPGroup.GetScopeId(),
Scope: &scopes.ScopeInfo{Id: defaultPGroup.GetScopeId(), Type: scope.Project.String(), ParentScopeId: defaultOGroup.GetScopeId()},
@@ -514,7 +514,7 @@ func TestCreate(t *testing.T) {
{
name: "Can't specify Id",
req: &pbs.CreateGroupRequest{Item: &pb.Group{
Id: iam.GroupPrefix + "_notallowed",
Id: globals.GroupPrefix + "_notallowed",
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -552,7 +552,7 @@ func TestCreate(t *testing.T) {
}
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), iam.GroupPrefix+"_"))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.GroupPrefix+"_"))
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
// Verify it is a group created after the test setup's default group
@@ -873,7 +873,7 @@ func TestUpdate(t *testing.T) {
{
name: "Update a Non Existing Group",
req: &pbs.UpdateGroupRequest{
Id: iam.GroupPrefix + "_DoesntExis",
Id: globals.GroupPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -892,7 +892,7 @@ func TestUpdate(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.Group{
Id: iam.GroupPrefix + "_somethinge",
Id: globals.GroupPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -823,7 +823,7 @@ func toStoragePluginCatalog(ctx context.Context, projectId, plgId string, item *
// - The type asserted by the ID and/or field is known
// - If relevant, the type derived from the id prefix matches what is claimed by the type field
func validateGetRequest(req *pbs.GetHostCatalogRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.StaticHostCatalogPrefix, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix)
}
func validateCreateRequest(req *pbs.CreateHostCatalogRequest) error {
@@ -879,11 +879,11 @@ func validateUpdateRequest(req *pbs.UpdateHostCatalogRequest) error {
}
}
return badFields
}, static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix)
}, globals.StaticHostCatalogPrefix, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix)
}
func validateDeleteRequest(req *pbs.DeleteHostCatalogRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.StaticHostCatalogPrefix, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix)
}
func validateListRequest(req *pbs.ListHostCatalogsRequest) error {
@@ -127,7 +127,7 @@ func TestGet_Static(t *testing.T) {
},
{
name: "Get a non existing Host Catalog",
req: &pbs.GetHostCatalogRequest{Id: static.HostCatalogPrefix + "_DoesntExis"},
req: &pbs.GetHostCatalogRequest{Id: globals.StaticHostCatalogPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -139,7 +139,7 @@ func TestGet_Static(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetHostCatalogRequest{Id: static.HostCatalogPrefix + "_1 23456789"},
req: &pbs.GetHostCatalogRequest{Id: globals.StaticHostCatalogPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -190,7 +190,7 @@ func TestGet_Plugin(t *testing.T) {
name := "test"
plg := host.TestPlugin(t, conn, name)
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar")))
hcPrev := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar")), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", plugin.PreviousHostCatalogPrefix)))
hcPrev := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), plugin.WithSecretsHmac([]byte("foobar")), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostCatalogPreviousPrefix)))
toMerge := &pbs.GetHostCatalogRequest{
Id: hc.GetPublicId(),
@@ -242,7 +242,7 @@ func TestGet_Plugin(t *testing.T) {
},
{
name: "Get a non existing Host Catalog",
req: &pbs.GetHostCatalogRequest{Id: plugin.HostCatalogPrefix + "_DoesntExis"},
req: &pbs.GetHostCatalogRequest{Id: globals.PluginHostCatalogPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -254,7 +254,7 @@ func TestGet_Plugin(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetHostCatalogRequest{Id: plugin.HostCatalogPrefix + "_1 23456789"},
req: &pbs.GetHostCatalogRequest{Id: globals.PluginHostCatalogPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -529,7 +529,7 @@ func TestDelete_Static(t *testing.T) {
name: "Delete bad id HostCatalog",
scopeId: proj.GetPublicId(),
req: &pbs.DeleteHostCatalogRequest{
Id: static.HostCatalogPrefix + "_doesntexis",
Id: globals.StaticHostCatalogPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -537,7 +537,7 @@ func TestDelete_Static(t *testing.T) {
name: "Bad HostCatalog Id formatting",
scopeId: proj.GetPublicId(),
req: &pbs.DeleteHostCatalogRequest{
Id: static.HostCatalogPrefix + "_bad_format",
Id: globals.StaticHostCatalogPrefix + "_bad_format",
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -600,7 +600,7 @@ func TestDelete_Plugin(t *testing.T) {
name: "Delete bad id HostCatalog",
scopeId: proj.GetPublicId(),
req: &pbs.DeleteHostCatalogRequest{
Id: plugin.HostCatalogPrefix + "_doesntexis",
Id: globals.PluginHostCatalogPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -608,7 +608,7 @@ func TestDelete_Plugin(t *testing.T) {
name: "Bad HostCatalog Id formatting",
scopeId: proj.GetPublicId(),
req: &pbs.DeleteHostCatalogRequest{
Id: plugin.HostCatalogPrefix + "_bad_format",
Id: globals.PluginHostCatalogPrefix + "_bad_format",
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -703,7 +703,7 @@ func TestCreate_Static(t *testing.T) {
Type: "static",
}},
res: &pbs.CreateHostCatalogResponse{
Uri: fmt.Sprintf("host-catalogs/%s_", static.HostCatalogPrefix),
Uri: fmt.Sprintf("host-catalogs/%s_", globals.StaticHostCatalogPrefix),
Item: &pb.HostCatalog{
ScopeId: proj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
@@ -793,7 +793,7 @@ func TestCreate_Static(t *testing.T) {
}
if got != nil {
assert.Contains(got.GetUri(), tc.res.GetUri())
assert.True(strings.HasPrefix(got.GetItem().GetId(), static.HostCatalogPrefix))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.StaticHostCatalogPrefix))
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
require.NoError(err, "Error converting proto to timestamp.")
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
@@ -865,7 +865,7 @@ func TestCreate_Plugin(t *testing.T) {
PluginId: plg.GetPublicId(),
}},
res: &pbs.CreateHostCatalogResponse{
Uri: fmt.Sprintf("host-catalogs/%s_", plugin.HostCatalogPrefix),
Uri: fmt.Sprintf("host-catalogs/%s_", globals.PluginHostCatalogPrefix),
Item: &pb.HostCatalog{
ScopeId: proj.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: proj.GetParentId()},
@@ -970,7 +970,7 @@ func TestCreate_Plugin(t *testing.T) {
require.NoError(gErr)
if got != nil {
assert.Contains(got.GetUri(), tc.res.GetUri())
assert.True(strings.HasPrefix(got.GetItem().GetId(), fmt.Sprintf("%s_", plugin.HostCatalogPrefix)))
assert.True(strings.HasPrefix(got.GetItem().GetId(), fmt.Sprintf("%s_", globals.PluginHostCatalogPrefix)))
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
require.NoError(err, "Error converting proto to timestamp.")
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
@@ -1241,7 +1241,7 @@ func TestUpdate_Static(t *testing.T) {
{
name: "Update a Non Existing HostCatalog",
req: &pbs.UpdateHostCatalogRequest{
Id: static.HostCatalogPrefix + "_DoesntExis",
Id: globals.StaticHostCatalogPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -946,13 +946,13 @@ func toStoragePluginSet(ctx context.Context, catalogId string, item *pb.HostSet)
// - The type asserted by the ID and/or field is known
// - If relevant, the type derived from the id prefix matches what is claimed by the type field
func validateGetRequest(req *pbs.GetHostSetRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.StaticHostSetPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix)
}
func validateCreateRequest(ctx context.Context, req *pbs.CreateHostSetRequest) error {
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), globals.StaticHostCatalogPrefix, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix) {
badFields[globals.HostCatalogIdField] = "The field is incorrectly formatted."
}
if len(req.GetItem().GetPreferredEndpoints()) > 0 {
@@ -1005,16 +1005,16 @@ func validateUpdateRequest(ctx context.Context, req *pbs.UpdateHostSetRequest) e
}
}
return badFields
}, static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix)
}, globals.StaticHostSetPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix)
}
func validateDeleteRequest(req *pbs.DeleteHostSetRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.StaticHostSetPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix)
}
func validateListRequest(req *pbs.ListHostSetsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), globals.StaticHostCatalogPrefix, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix) {
badFields[globals.HostCatalogIdField] = "The field is incorrectly formatted."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -1028,7 +1028,7 @@ func validateListRequest(req *pbs.ListHostSetsRequest) error {
func validateAddRequest(req *pbs.AddHostSetHostsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), static.HostSetPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.StaticHostSetPrefix) {
badFields[globals.IdField] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1038,7 +1038,7 @@ func validateAddRequest(req *pbs.AddHostSetHostsRequest) error {
badFields[globals.HostIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostIds() {
if !handlers.ValidId(handlers.Id(id), static.HostPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.StaticHostPrefix) {
badFields[globals.HostIdsField] = "Incorrectly formatted host identifier."
break
}
@@ -1051,14 +1051,14 @@ func validateAddRequest(req *pbs.AddHostSetHostsRequest) error {
func validateSetRequest(req *pbs.SetHostSetHostsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), static.HostSetPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.StaticHostSetPrefix) {
badFields[globals.IdField] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
badFields[globals.VersionField] = "Required field."
}
for _, id := range req.GetHostIds() {
if !handlers.ValidId(handlers.Id(id), static.HostPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.StaticHostPrefix) {
badFields[globals.HostIdsField] = "Incorrectly formatted host identifier."
break
}
@@ -1071,7 +1071,7 @@ func validateSetRequest(req *pbs.SetHostSetHostsRequest) error {
func validateRemoveRequest(req *pbs.RemoveHostSetHostsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), static.HostSetPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.StaticHostSetPrefix) {
badFields[globals.IdField] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1081,7 +1081,7 @@ func validateRemoveRequest(req *pbs.RemoveHostSetHostsRequest) error {
badFields[globals.HostIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostIds() {
if !handlers.ValidId(handlers.Id(id), static.HostPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.StaticHostPrefix) {
badFields[globals.HostIdsField] = "Incorrectly formatted host identifier."
break
}
@@ -103,7 +103,7 @@ func TestGet_Static(t *testing.T) {
},
{
name: "Get a non existing Host Set",
req: &pbs.GetHostSetRequest{Id: static.HostSetPrefix + "_DoesntExis"},
req: &pbs.GetHostSetRequest{Id: globals.StaticHostSetPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -115,7 +115,7 @@ func TestGet_Static(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetHostSetRequest{Id: static.HostPrefix + "_1 23456789"},
req: &pbs.GetHostSetRequest{Id: globals.StaticHostPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -174,7 +174,7 @@ func TestGet_Plugin(t *testing.T) {
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
hs := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1))
hsPrev := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", plugin.PreviousHostSetPrefix)))
hsPrev := plugin.TestSet(t, conn, kms, sche, hc, plgm, plugin.WithPreferredEndpoints(prefEndpoints), plugin.WithSyncIntervalSeconds(-1), plugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostSetPreviousPrefix)))
toMerge := &pbs.GetHostSetRequest{}
@@ -219,7 +219,7 @@ func TestGet_Plugin(t *testing.T) {
},
{
name: "Get a non existing Host Set",
req: &pbs.GetHostSetRequest{Id: plugin.HostSetPrefix + "_DoesntExis"},
req: &pbs.GetHostSetRequest{Id: globals.PluginHostSetPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -231,7 +231,7 @@ func TestGet_Plugin(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetHostSetRequest{Id: plugin.HostSetPrefix + "_1 23456789"},
req: &pbs.GetHostSetRequest{Id: globals.PluginHostSetPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -518,7 +518,7 @@ func TestDelete_Static(t *testing.T) {
name: "Delete bad id Host Set",
projectId: proj.GetPublicId(),
req: &pbs.DeleteHostSetRequest{
Id: static.HostSetPrefix + "_doesntexis",
Id: globals.StaticHostSetPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -526,7 +526,7 @@ func TestDelete_Static(t *testing.T) {
name: "Bad Host Id formatting",
projectId: proj.GetPublicId(),
req: &pbs.DeleteHostSetRequest{
Id: static.HostSetPrefix + "_bad_format",
Id: globals.StaticHostSetPrefix + "_bad_format",
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -595,7 +595,7 @@ func TestDelete_Plugin(t *testing.T) {
name: "Delete bad id Host Set",
projectId: proj.GetPublicId(),
req: &pbs.DeleteHostSetRequest{
Id: plugin.HostSetPrefix + "_doesntexis",
Id: globals.PluginHostSetPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -603,7 +603,7 @@ func TestDelete_Plugin(t *testing.T) {
name: "Bad Host Id formatting",
projectId: proj.GetPublicId(),
req: &pbs.DeleteHostSetRequest{
Id: plugin.HostSetPrefix + "_bad_format",
Id: globals.PluginHostSetPrefix + "_bad_format",
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -700,7 +700,7 @@ func TestCreate_Static(t *testing.T) {
Type: "static",
}},
res: &pbs.CreateHostSetResponse{
Uri: fmt.Sprintf("host-sets/%s_", static.HostSetPrefix),
Uri: fmt.Sprintf("host-sets/%s_", globals.StaticHostSetPrefix),
Item: &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -740,7 +740,7 @@ func TestCreate_Static(t *testing.T) {
Description: &wrappers.StringValue{Value: "no type desc"},
}},
res: &pbs.CreateHostSetResponse{
Uri: fmt.Sprintf("host-sets/%s_", static.HostSetPrefix),
Uri: fmt.Sprintf("host-sets/%s_", globals.StaticHostSetPrefix),
Item: &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -793,7 +793,7 @@ func TestCreate_Static(t *testing.T) {
}
if got != nil {
assert.Contains(got.GetUri(), tc.res.GetUri())
assert.True(strings.HasPrefix(got.GetItem().GetId(), static.HostSetPrefix), got.GetItem().GetId())
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.StaticHostSetPrefix), got.GetItem().GetId())
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
require.NoError(err, "Error converting proto to timestamp.")
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
@@ -894,7 +894,7 @@ func TestCreate_Plugin(t *testing.T) {
SyncIntervalSeconds: &wrapperspb.Int32Value{Value: -1},
}},
res: &pbs.CreateHostSetResponse{
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
Uri: fmt.Sprintf("host-sets/%s_", globals.PluginHostSetPrefix),
Item: &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -924,7 +924,7 @@ func TestCreate_Plugin(t *testing.T) {
},
}},
res: &pbs.CreateHostSetResponse{
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
Uri: fmt.Sprintf("host-sets/%s_", globals.PluginHostSetPrefix),
Item: &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -954,7 +954,7 @@ func TestCreate_Plugin(t *testing.T) {
PreferredEndpoints: prefEndpoints,
}},
res: &pbs.CreateHostSetResponse{
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
Uri: fmt.Sprintf("host-sets/%s_", globals.PluginHostSetPrefix),
Item: &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -1000,7 +1000,7 @@ func TestCreate_Plugin(t *testing.T) {
Description: &wrappers.StringValue{Value: "no type desc"},
}},
res: &pbs.CreateHostSetResponse{
Uri: fmt.Sprintf("host-sets/%s_", plugin.HostSetPrefix),
Uri: fmt.Sprintf("host-sets/%s_", globals.PluginHostSetPrefix),
Item: &pb.HostSet{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -1060,7 +1060,7 @@ func TestCreate_Plugin(t *testing.T) {
require.NoError(gErr)
if got != nil {
assert.Contains(got.GetUri(), tc.res.GetUri())
assert.True(strings.HasPrefix(got.GetItem().GetId(), plugin.HostSetPrefix), got.GetItem().GetId())
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.PluginHostSetPrefix), got.GetItem().GetId())
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
require.NoError(err, "Error converting proto to timestamp.")
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
@@ -1338,7 +1338,7 @@ func TestUpdate_Static(t *testing.T) {
{
name: "Update a Non Existing Host Set",
req: &pbs.UpdateHostSetRequest{
Id: static.HostSetPrefix + "_DoesntExis",
Id: globals.StaticHostSetPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -617,13 +617,13 @@ func validateGetRequest(req *pbs.GetHostRequest) error {
badFields["id"] = "Improperly formatted identifier used."
}
return badFields
}, req, static.HostPrefix, plugin.HostPrefix, plugin.PreviousHostPrefix)
}, req, globals.StaticHostPrefix, globals.PluginHostPrefix, globals.PluginHostPreviousPrefix)
}
func validateCreateRequest(req *pbs.CreateHostRequest) error {
return handlers.ValidateCreateRequest(req.GetItem(), func() map[string]string {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), static.HostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetItem().GetHostCatalogId()), globals.StaticHostCatalogPrefix) {
badFields["host_catalog_id"] = "The field is incorrectly formatted."
}
switch subtypes.SubtypeFromId(domain, req.GetItem().GetHostCatalogId()) {
@@ -702,7 +702,7 @@ func validateUpdateRequest(req *pbs.UpdateHostRequest) error {
badFields["id"] = "Improperly formatted identifier used."
}
return badFields
}, static.HostPrefix)
}, globals.StaticHostPrefix)
}
func validateDeleteRequest(req *pbs.DeleteHostRequest) error {
@@ -713,12 +713,12 @@ func validateDeleteRequest(req *pbs.DeleteHostRequest) error {
badFields[globals.IdField] = "Cannot manually delete this type of host."
}
return badFields
}, req, static.HostPrefix)
}, req, globals.StaticHostPrefix)
}
func validateListRequest(req *pbs.ListHostsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), static.HostCatalogPrefix, plugin.HostCatalogPrefix, plugin.PreviousHostCatalogPrefix) {
if !handlers.ValidId(handlers.Id(req.GetHostCatalogId()), globals.StaticHostCatalogPrefix, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix) {
badFields["host_catalog_id"] = "The field is incorrectly formatted."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -101,7 +101,7 @@ func TestGet_Static(t *testing.T) {
},
{
name: "Get a non existing Host Set",
req: &pbs.GetHostRequest{Id: static.HostPrefix + "_DoesntExis"},
req: &pbs.GetHostRequest{Id: globals.StaticHostPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -113,7 +113,7 @@ func TestGet_Static(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetHostRequest{Id: static.HostPrefix + "_1 23456789"},
req: &pbs.GetHostRequest{Id: globals.StaticHostPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -166,7 +166,7 @@ func TestGet_Plugin(t *testing.T) {
}
hc := plugin.TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId())
h := plugin.TestHost(t, conn, hc.GetPublicId(), "test")
hPrev := plugin.TestHost(t, conn, hc.GetPublicId(), "test-prev", plugin.WithPublicId(fmt.Sprintf("%s_1234567890", plugin.PreviousHostPrefix)))
hPrev := plugin.TestHost(t, conn, hc.GetPublicId(), "test-prev", plugin.WithPublicId(fmt.Sprintf("%s_1234567890", globals.PluginHostPreviousPrefix)))
hs := plugin.TestSet(t, conn, kms, sche, hc, plgm)
plugin.TestSetMembers(t, conn, hs.GetPublicId(), []*plugin.Host{h, hPrev})
@@ -212,7 +212,7 @@ func TestGet_Plugin(t *testing.T) {
},
{
name: "non existing",
req: &pbs.GetHostRequest{Id: plugin.HostPrefix + "_DoesntExis"},
req: &pbs.GetHostRequest{Id: globals.PluginHostPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -224,7 +224,7 @@ func TestGet_Plugin(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetHostRequest{Id: plugin.HostPrefix + "_1 23456789"},
req: &pbs.GetHostRequest{Id: globals.PluginHostPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -548,7 +548,7 @@ func TestDelete(t *testing.T) {
name: "Delete bad id Host",
projectId: proj.GetPublicId(),
req: &pbs.DeleteHostRequest{
Id: static.HostPrefix + "_doesntexis",
Id: globals.StaticHostPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -556,7 +556,7 @@ func TestDelete(t *testing.T) {
name: "Bad Host Id formatting",
projectId: proj.GetPublicId(),
req: &pbs.DeleteHostRequest{
Id: static.HostPrefix + "_bad_format",
Id: globals.StaticHostPrefix + "_bad_format",
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -661,7 +661,7 @@ func TestCreate(t *testing.T) {
},
}},
res: &pbs.CreateHostResponse{
Uri: fmt.Sprintf("hosts/%s_", static.HostPrefix),
Uri: fmt.Sprintf("hosts/%s_", globals.StaticHostPrefix),
Item: &pb.Host{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -749,7 +749,7 @@ func TestCreate(t *testing.T) {
},
}},
res: &pbs.CreateHostResponse{
Uri: fmt.Sprintf("hosts/%s_", static.HostPrefix),
Uri: fmt.Sprintf("hosts/%s_", globals.StaticHostPrefix),
Item: &pb.Host{
HostCatalogId: hc.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -828,7 +828,7 @@ func TestCreate(t *testing.T) {
if got != nil {
assert.Contains(got.GetUri(), tc.res.GetUri())
assert.True(strings.HasPrefix(got.GetItem().GetId(), static.HostPrefix))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.StaticHostPrefix))
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
// Verify it is a set created after the test setup's default set
@@ -1142,7 +1142,7 @@ func TestUpdate_Static(t *testing.T) {
{
name: "Update a Non Existing Host",
req: &pbs.UpdateHostRequest{
Id: static.HostPrefix + "_DoesntExis",
Id: globals.StaticHostPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -16,7 +16,6 @@ import (
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
"github.com/hashicorp/boundary/internal/errors"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/types/action"
@@ -583,7 +582,7 @@ func validateGetRequest(req *pbs.GetManagedGroupRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, intglobals.OidcManagedGroupPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.OidcManagedGroupPrefix)
}
func validateCreateRequest(req *pbs.CreateManagedGroupRequest) error {
@@ -651,7 +650,7 @@ func validateUpdateRequest(req *pbs.UpdateManagedGroupRequest) error {
badFields[globals.IdField] = "Unrecognized resource type."
}
return badFields
}, intglobals.OidcManagedGroupPrefix)
}, globals.OidcManagedGroupPrefix)
}
func validateDeleteRequest(req *pbs.DeleteManagedGroupRequest) error {
@@ -659,7 +658,7 @@ func validateDeleteRequest(req *pbs.DeleteManagedGroupRequest) error {
if req == nil {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, intglobals.OidcManagedGroupPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.OidcManagedGroupPrefix)
}
func validateListRequest(req *pbs.ListManagedGroupsRequest) error {
@@ -668,7 +667,7 @@ func validateListRequest(req *pbs.ListManagedGroupsRequest) error {
return errors.NewDeprecated(errors.InvalidParameter, op, "nil request")
}
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), oidc.AuthMethodPrefix) {
if !handlers.ValidId(handlers.Id(req.GetAuthMethodId()), globals.OidcAuthMethodPrefix) {
badFields[globals.AuthMethodIdField] = "Invalid formatted identifier."
}
if _, err := handlers.NewFilter(req.GetFilter()); err != nil {
@@ -16,7 +16,6 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -24,7 +23,6 @@ import (
"github.com/hashicorp/boundary/internal/db"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -155,7 +153,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existing oidc managed group",
req: &pbs.GetManagedGroupRequest{Id: intglobals.OidcManagedGroupPrefix + "_DoesntExis"},
req: &pbs.GetManagedGroupRequest{Id: globals.OidcManagedGroupPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -167,7 +165,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetManagedGroupRequest{Id: authtoken.AuthTokenPrefix + "_1 23456789"},
req: &pbs.GetManagedGroupRequest{Id: globals.AuthTokenPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -276,7 +274,7 @@ func TestListOidc(t *testing.T) {
},
{
name: "Unfound Auth Method",
req: &pbs.ListManagedGroupsRequest{AuthMethodId: oidc.AuthMethodPrefix + "_DoesntExis"},
req: &pbs.ListManagedGroupsRequest{AuthMethodId: globals.OidcAuthMethodPrefix + "_DoesntExis"},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
{
@@ -384,7 +382,7 @@ func TestDelete(t *testing.T) {
{
name: "Delete bad oidc managed group id",
req: &pbs.DeleteManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_doesntexis",
Id: globals.OidcManagedGroupPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -499,7 +497,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateManagedGroupResponse{
Uri: fmt.Sprintf("managed-groups/%s_", intglobals.OidcManagedGroupPrefix),
Uri: fmt.Sprintf("managed-groups/%s_", globals.OidcManagedGroupPrefix),
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Name: &wrapperspb.StringValue{Value: "name"},
@@ -529,7 +527,7 @@ func TestCreateOidc(t *testing.T) {
},
},
res: &pbs.CreateManagedGroupResponse{
Uri: fmt.Sprintf("managed-groups/%s_", intglobals.OidcManagedGroupPrefix),
Uri: fmt.Sprintf("managed-groups/%s_", globals.OidcManagedGroupPrefix),
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Scope: &scopepb.ScopeInfo{Id: o.GetPublicId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -565,7 +563,7 @@ func TestCreateOidc(t *testing.T) {
req: &pbs.CreateManagedGroupRequest{
Item: &pb.ManagedGroup{
AuthMethodId: am.GetPublicId(),
Id: intglobals.OidcManagedGroupPrefix + "_notallowed",
Id: globals.OidcManagedGroupPrefix + "_notallowed",
Type: oidc.Subtype.String(),
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
@@ -641,7 +639,7 @@ func TestCreateOidc(t *testing.T) {
require.NoError(gErr)
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), intglobals.OidcManagedGroupPrefix+"_"))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.OidcManagedGroupPrefix+"_"))
// Clear all values which are hard to compare against.
got.Uri, tc.res.Uri = "", ""
got.Item.Id, tc.res.Item.Id = "", ""
@@ -886,7 +884,7 @@ func TestUpdateOidc(t *testing.T) {
{
name: "Update a Non Existing ManagedGroup",
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_DoesntExis",
Id: globals.OidcManagedGroupPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{globals.DescriptionField},
},
@@ -904,7 +902,7 @@ func TestUpdateOidc(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.ManagedGroup{
Id: intglobals.OidcManagedGroupPrefix + "_somethinge",
Id: globals.OidcManagedGroupPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -12,7 +12,6 @@ import (
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/intglobals"
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/managedgroups"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -41,7 +40,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "mismatched oidc authmethod pw type",
item: &pb.ManagedGroup{
Type: "ldap",
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
},
errContains: fieldError(globals.TypeField, "Doesn't match the parent resource's type."),
},
@@ -49,7 +48,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "missing oidc attributes",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: nil,
},
errContains: fieldError(globals.AttributesField, "Attribute fields is required."),
@@ -58,7 +57,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "bad oidc attributes",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: "foobar",
@@ -71,7 +70,7 @@ func TestValidateCreateRequest(t *testing.T) {
name: "no oidc errors",
item: &pb.ManagedGroup{
Type: oidc.Subtype.String(),
AuthMethodId: oidc.AuthMethodPrefix + "_1234567890",
AuthMethodId: globals.OidcAuthMethodPrefix + "_1234567890",
Attrs: &pb.ManagedGroup_OidcManagedGroupAttributes{
OidcManagedGroupAttributes: &pb.OidcManagedGroupAttributes{
Filter: `"/foo/bar" == "zipzap"`,
@@ -106,7 +105,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "oidc to password change type",
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_1234567890",
Id: globals.OidcManagedGroupPrefix + "_1234567890",
Item: &pb.ManagedGroup{
Type: password.Subtype.String(),
},
@@ -116,7 +115,7 @@ func TestValidateUpdateRequest(t *testing.T) {
{
name: "no error",
req: &pbs.UpdateManagedGroupRequest{
Id: intglobals.OidcManagedGroupPrefix + "_1234567890",
Id: globals.OidcManagedGroupPrefix + "_1234567890",
UpdateMask: &fieldmaskpb.FieldMask{Paths: []string{}},
Item: &pb.ManagedGroup{
Version: 1,
@@ -16,7 +16,6 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/iam/store"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/types/action"
@@ -887,7 +886,7 @@ func toProto(ctx context.Context, in *iam.Role, principals []*iam.PrincipalRole,
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetRoleRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, iam.RolePrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.RolePrefix)
}
func validateCreateRequest(req *pbs.CreateRoleRequest) error {
@@ -935,13 +934,13 @@ func validateUpdateRequest(req *pbs.UpdateRoleRequest) error {
}
}
return badFields
}, iam.RolePrefix)
}, globals.RolePrefix)
}
func validateDeleteRequest(req *pbs.DeleteRoleRequest) error {
return handlers.ValidateDeleteRequest(func() map[string]string {
return nil
}, req, iam.RolePrefix)
}, req, globals.RolePrefix)
}
func validateListRequest(req *pbs.ListRolesRequest) error {
@@ -962,7 +961,7 @@ func validateListRequest(req *pbs.ListRolesRequest) error {
func validateAddRolePrincipalsRequest(req *pbs.AddRolePrincipalsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.RolePrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.RolePrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -972,9 +971,9 @@ func validateAddRolePrincipalsRequest(req *pbs.AddRolePrincipalsRequest) error {
badFields["principal_ids"] = "Must be non-empty."
}
for _, id := range req.GetPrincipalIds() {
if !handlers.ValidId(handlers.Id(id), iam.GroupPrefix) &&
!handlers.ValidId(handlers.Id(id), iam.UserPrefix) &&
!handlers.ValidId(handlers.Id(id), intglobals.OidcManagedGroupPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.GroupPrefix) &&
!handlers.ValidId(handlers.Id(id), globals.UserPrefix) &&
!handlers.ValidId(handlers.Id(id), globals.OidcManagedGroupPrefix) {
badFields["principal_ids"] = "Must only have valid user, group, and/or managed group ids."
break
}
@@ -991,16 +990,16 @@ func validateAddRolePrincipalsRequest(req *pbs.AddRolePrincipalsRequest) error {
func validateSetRolePrincipalsRequest(req *pbs.SetRolePrincipalsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.RolePrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.RolePrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
badFields["version"] = "Required field."
}
for _, id := range req.GetPrincipalIds() {
if !handlers.ValidId(handlers.Id(id), iam.GroupPrefix) &&
!handlers.ValidId(handlers.Id(id), iam.UserPrefix) &&
!handlers.ValidId(handlers.Id(id), intglobals.OidcManagedGroupPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.GroupPrefix) &&
!handlers.ValidId(handlers.Id(id), globals.UserPrefix) &&
!handlers.ValidId(handlers.Id(id), globals.OidcManagedGroupPrefix) {
badFields["principal_ids"] = "Must only have valid user, group, and/or managed group ids."
break
}
@@ -1017,7 +1016,7 @@ func validateSetRolePrincipalsRequest(req *pbs.SetRolePrincipalsRequest) error {
func validateRemoveRolePrincipalsRequest(req *pbs.RemoveRolePrincipalsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.RolePrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.RolePrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1027,9 +1026,9 @@ func validateRemoveRolePrincipalsRequest(req *pbs.RemoveRolePrincipalsRequest) e
badFields["principal_ids"] = "Must be non-empty."
}
for _, id := range req.GetPrincipalIds() {
if !handlers.ValidId(handlers.Id(id), iam.GroupPrefix) &&
!handlers.ValidId(handlers.Id(id), iam.UserPrefix) &&
!handlers.ValidId(handlers.Id(id), intglobals.OidcManagedGroupPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.GroupPrefix) &&
!handlers.ValidId(handlers.Id(id), globals.UserPrefix) &&
!handlers.ValidId(handlers.Id(id), globals.OidcManagedGroupPrefix) {
badFields["principal_ids"] = "Must only have valid user, group, and/or managed group ids."
break
}
@@ -1042,7 +1041,7 @@ func validateRemoveRolePrincipalsRequest(req *pbs.RemoveRolePrincipalsRequest) e
func validateAddRoleGrantsRequest(req *pbs.AddRoleGrantsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.RolePrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.RolePrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1076,7 +1075,7 @@ func validateAddRoleGrantsRequest(req *pbs.AddRoleGrantsRequest) error {
func validateSetRoleGrantsRequest(req *pbs.SetRoleGrantsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.RolePrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.RolePrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1107,7 +1106,7 @@ func validateSetRoleGrantsRequest(req *pbs.SetRoleGrantsRequest) error {
func validateRemoveRoleGrantsRequest(req *pbs.RemoveRoleGrantsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.RolePrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.RolePrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -126,7 +126,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existant Role",
req: &pbs.GetRoleRequest{Id: iam.RolePrefix + "_DoesntExis"},
req: &pbs.GetRoleRequest{Id: globals.RolePrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -138,7 +138,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetRoleRequest{Id: iam.RolePrefix + "_1 23456789"},
req: &pbs.GetRoleRequest{Id: globals.RolePrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -151,7 +151,7 @@ func TestGet(t *testing.T) {
{
name: "Project Scoped Get a non existant Role",
scopeId: pr.GetScopeId(),
req: &pbs.GetRoleRequest{Id: iam.RolePrefix + "_DoesntExis"},
req: &pbs.GetRoleRequest{Id: globals.RolePrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -165,7 +165,7 @@ func TestGet(t *testing.T) {
{
name: "Project Scoped space in id",
scopeId: pr.GetScopeId(),
req: &pbs.GetRoleRequest{Id: iam.RolePrefix + "_1 23456789"},
req: &pbs.GetRoleRequest{Id: globals.RolePrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -352,7 +352,7 @@ func TestDelete(t *testing.T) {
name: "Delete bad role id",
scopeId: or.GetScopeId(),
req: &pbs.DeleteRoleRequest{
Id: iam.RolePrefix + "_doesntexis",
Id: globals.RolePrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -375,7 +375,7 @@ func TestDelete(t *testing.T) {
name: "Project Scoped Delete bad Role id",
scopeId: pr.GetScopeId(),
req: &pbs.DeleteRoleRequest{
Id: iam.RolePrefix + "_doesntexis",
Id: globals.RolePrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -440,7 +440,7 @@ func TestCreate(t *testing.T) {
GrantScopeId: &wrapperspb.StringValue{Value: defaultProjRole.ScopeId},
}},
res: &pbs.CreateRoleResponse{
Uri: fmt.Sprintf("roles/%s_", iam.RolePrefix),
Uri: fmt.Sprintf("roles/%s_", globals.RolePrefix),
Item: &pb.Role{
ScopeId: defaultOrgRole.GetScopeId(),
Scope: &scopes.ScopeInfo{Id: defaultOrgRole.GetScopeId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -461,7 +461,7 @@ func TestCreate(t *testing.T) {
GrantScopeId: &wrapperspb.StringValue{Value: defaultProjRole.ScopeId},
}},
res: &pbs.CreateRoleResponse{
Uri: fmt.Sprintf("roles/%s_", iam.RolePrefix),
Uri: fmt.Sprintf("roles/%s_", globals.RolePrefix),
Item: &pb.Role{
ScopeId: scope.Global.String(),
Scope: &scopes.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String(), Name: scope.Global.String(), Description: "Global Scope"},
@@ -483,7 +483,7 @@ func TestCreate(t *testing.T) {
},
},
res: &pbs.CreateRoleResponse{
Uri: fmt.Sprintf("roles/%s_", iam.RolePrefix),
Uri: fmt.Sprintf("roles/%s_", globals.RolePrefix),
Item: &pb.Role{
ScopeId: defaultProjRole.GetScopeId(),
Scope: &scopes.ScopeInfo{Id: defaultProjRole.GetScopeId(), Type: scope.Project.String(), ParentScopeId: defaultOrgRole.GetScopeId()},
@@ -512,7 +512,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateRoleRequest{Item: &pb.Role{
ScopeId: defaultProjRole.GetScopeId(),
Id: iam.RolePrefix + "_notallowed",
Id: globals.RolePrefix + "_notallowed",
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -552,7 +552,7 @@ func TestCreate(t *testing.T) {
}
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), iam.RolePrefix+"_"), "Expected %q to have the prefix %q", got.GetItem().GetId(), iam.RolePrefix+"_")
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.RolePrefix+"_"), "Expected %q to have the prefix %q", got.GetItem().GetId(), globals.RolePrefix+"_")
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
// Verify it is a role created after the test setup's default role
@@ -882,7 +882,7 @@ func TestUpdate(t *testing.T) {
{
name: "Update a Non Existing Role",
req: &pbs.UpdateRoleRequest{
Id: iam.RolePrefix + "_DoesntExis",
Id: globals.RolePrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -900,7 +900,7 @@ func TestUpdate(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.Role{
Id: iam.RolePrefix + "_somethinge",
Id: globals.RolePrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -10,8 +10,6 @@ import (
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/common/scopeids"
@@ -574,7 +572,7 @@ func (s Service) updateInRepo(ctx context.Context, parentScope *pb.ScopeInfo, sc
opts = append(opts, iam.WithName(scopeName))
}
if primaryAuthMethodId := item.GetPrimaryAuthMethodId(); primaryAuthMethodId != nil {
if !handlers.ValidId(handlers.Id(primaryAuthMethodId.GetValue()), password.AuthMethodPrefix, oidc.AuthMethodPrefix) {
if !handlers.ValidId(handlers.Id(primaryAuthMethodId.GetValue()), globals.PasswordAuthMethodPrefix, globals.OidcAuthMethodPrefix) {
return nil, handlers.InvalidArgumentErrorf("Error in provided request.", map[string]string{"primary_auth_method_id": "Improperly formatted identifier"})
}
scopePrimaryAuthMethodId = primaryAuthMethodId.GetValue()
@@ -931,7 +929,7 @@ func validateUpdateRequest(req *pbs.UpdateScopeRequest) error {
if item.GetUpdatedTime() != nil {
badFields["updated_time"] = "This is a read only field and cannot be specified in an update request."
}
if item.GetPrimaryAuthMethodId().GetValue() != "" && !handlers.ValidId(handlers.Id(item.GetPrimaryAuthMethodId().GetValue()), password.AuthMethodPrefix, oidc.AuthMethodPrefix) {
if item.GetPrimaryAuthMethodId().GetValue() != "" && !handlers.ValidId(handlers.Id(item.GetPrimaryAuthMethodId().GetValue()), globals.PasswordAuthMethodPrefix, globals.OidcAuthMethodPrefix) {
badFields["primary_auth_method_id"] = "Improperly formatted identifier."
}
if len(badFields) > 0 {
@@ -467,7 +467,7 @@ func toProto(ctx context.Context, in *session.Session, opt ...handlers.Option) (
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetSessionRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, session.SessionPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.SessionPrefix)
}
func validateListRequest(req *pbs.ListSessionsRequest) error {
@@ -487,7 +487,7 @@ func validateListRequest(req *pbs.ListSessionsRequest) error {
func validateCancelRequest(req *pbs.CancelSessionRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), session.SessionPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.SessionPrefix) {
badFields["id"] = "Improperly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -11,6 +11,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/handlers"
@@ -116,7 +117,7 @@ func TestGetSession(t *testing.T) {
},
{
name: "Get a non existent Session",
req: &pbs.GetSessionRequest{Id: session.SessionPrefix + "_DoesntExis"},
req: &pbs.GetSessionRequest{Id: globals.SessionPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -128,7 +129,7 @@ func TestGetSession(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetSessionRequest{Id: session.SessionPrefix + "_1 23456789"},
req: &pbs.GetSessionRequest{Id: globals.SessionPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -690,7 +691,7 @@ func TestCancel(t *testing.T) {
},
{
name: "Cancel a non existing Session",
req: &pbs.CancelSessionRequest{Id: session.SessionPrefix + "_DoesntExis"},
req: &pbs.CancelSessionRequest{Id: globals.SessionPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -702,7 +703,7 @@ func TestCancel(t *testing.T) {
},
{
name: "space in id",
req: &pbs.CancelSessionRequest{Id: session.SessionPrefix + "_1 23456789"},
req: &pbs.CancelSessionRequest{Id: globals.SessionPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -17,7 +17,6 @@ import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
wl "github.com/hashicorp/boundary/internal/daemon/common"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
@@ -1719,7 +1718,7 @@ func validateAddHostSourcesRequest(req *pbs.AddTargetHostSourcesRequest) error {
badFields[globals.HostSourceIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostSourceIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.StaticHostSetPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix) {
badFields[globals.HostSourceIdsField] = fmt.Sprintf("Incorrectly formatted host source identifier %q.", id)
break
}
@@ -1739,7 +1738,7 @@ func validateSetHostSourcesRequest(req *pbs.SetTargetHostSourcesRequest) error {
badFields[globals.VersionField] = "Required field."
}
for _, id := range req.GetHostSourceIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.StaticHostSetPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix) {
badFields[globals.HostSourceIdsField] = fmt.Sprintf("Incorrectly formatted host source identifier %q.", id)
break
}
@@ -1762,7 +1761,7 @@ func validateRemoveHostSourcesRequest(req *pbs.RemoveTargetHostSourcesRequest) e
badFields[globals.HostSourceIdsField] = "Must be non-empty."
}
for _, id := range req.GetHostSourceIds() {
if !handlers.ValidId(handlers.Id(id), static.HostSetPrefix, plugin.HostSetPrefix, plugin.PreviousHostSetPrefix) {
if !handlers.ValidId(handlers.Id(id), globals.StaticHostSetPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix) {
badFields[globals.HostSourceIdsField] = fmt.Sprintf("Incorrectly formatted host source identifier %q.", id)
break
}
@@ -1788,33 +1787,33 @@ func validateAddCredentialSourcesRequest(req *pbs.AddTargetCredentialSourcesRequ
// TODO: Application Credentials are deprecated, remove when field removed.
for _, cl := range req.GetApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.ApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetBrokeredCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.BrokeredCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetInjectedApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
vault.SSHCertificateCredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.VaultSshCertificateCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix) {
badFields[globals.InjectedApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
@@ -1836,33 +1835,33 @@ func validateSetCredentialSourcesRequest(req *pbs.SetTargetCredentialSourcesRequ
// TODO: Application Credentials are deprecated, remove when field removed.
for _, cl := range req.GetApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.ApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetBrokeredCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.BrokeredCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetInjectedApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
vault.SSHCertificateCredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.VaultSshCertificateCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix) {
badFields[globals.InjectedApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
@@ -1888,34 +1887,34 @@ func validateRemoveCredentialSourcesRequest(req *pbs.RemoveTargetCredentialSourc
// TODO: Application Credentials are deprecated, remove when field removed.
for _, cl := range req.GetApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.ApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetBrokeredCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.BrokeredCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
}
for _, cl := range req.GetInjectedApplicationCredentialSourceIds() {
if !handlers.ValidId(handlers.Id(cl),
vault.CredentialLibraryPrefix,
vault.SSHCertificateCredentialLibraryPrefix,
credential.UsernamePasswordCredentialPrefix,
credential.PreviousUsernamePasswordCredentialPrefix,
credential.SshPrivateKeyCredentialPrefix,
credential.JsonCredentialPrefix) {
globals.VaultCredentialLibraryPrefix,
globals.VaultSshCertificateCredentialLibraryPrefix,
globals.UsernamePasswordCredentialPrefix,
globals.UsernamePasswordCredentialPreviousPrefix,
globals.SshPrivateKeyCredentialPrefix,
globals.JsonCredentialPrefix) {
badFields[globals.InjectedApplicationCredentialSourceIdsField] = fmt.Sprintf("Incorrectly formatted credential source identifier %q.", cl)
break
}
@@ -199,7 +199,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existing Target",
req: &pbs.GetTargetRequest{Id: tcp.TargetPrefix + "_DoesntExis"},
req: &pbs.GetTargetRequest{Id: globals.TcpTargetPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -211,7 +211,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetTargetRequest{Id: tcp.TargetPrefix + "_1 23456789"},
req: &pbs.GetTargetRequest{Id: globals.TcpTargetPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -459,7 +459,7 @@ func TestDelete(t *testing.T) {
name: "Delete Not Existing Target",
scopeId: proj.GetPublicId(),
req: &pbs.DeleteTargetRequest{
Id: tcp.TargetPrefix + "_doesntexis",
Id: globals.TcpTargetPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -467,7 +467,7 @@ func TestDelete(t *testing.T) {
name: "Bad target id formatting",
scopeId: proj.GetPublicId(),
req: &pbs.DeleteTargetRequest{
Id: tcp.TargetPrefix + "_bad_format",
Id: globals.TcpTargetPrefix + "_bad_format",
},
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -591,7 +591,7 @@ func TestCreate(t *testing.T) {
EgressWorkerFilter: wrapperspb.String(`type == "bar"`),
}},
res: &pbs.CreateTargetResponse{
Uri: fmt.Sprintf("targets/%s_", tcp.TargetPrefix),
Uri: fmt.Sprintf("targets/%s_", globals.TcpTargetPrefix),
Item: &pb.Target{
ScopeId: proj.GetPublicId(),
Scope: &scopes.ScopeInfo{Id: proj.GetPublicId(), Type: scope.Project.String(), ParentScopeId: org.GetPublicId()},
@@ -755,7 +755,7 @@ func TestCreate(t *testing.T) {
if got != nil {
assert.Contains(got.GetUri(), tc.res.GetUri())
assert.True(strings.HasPrefix(got.GetItem().GetId(), tcp.TargetPrefix), got.GetItem().GetId())
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.TcpTargetPrefix), got.GetItem().GetId())
// Clear all values which are hard to compare against.
got.Uri, tc.res.Uri = "", ""
@@ -1093,7 +1093,7 @@ func TestUpdate(t *testing.T) {
{
name: "Update a Non Existing Target",
req: &pbs.UpdateTargetRequest{
Id: tcp.TargetPrefix + "_DoesntExis",
Id: globals.TcpTargetPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -8,7 +8,6 @@ import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/daemon/controller/auth"
"github.com/hashicorp/boundary/internal/daemon/controller/common"
"github.com/hashicorp/boundary/internal/daemon/controller/common/scopeids"
@@ -17,7 +16,6 @@ import (
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/iam/store"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/perms"
"github.com/hashicorp/boundary/internal/requests"
"github.com/hashicorp/boundary/internal/types/action"
@@ -668,7 +666,7 @@ func toProto(ctx context.Context, in *iam.User, accts []string, opt ...handlers.
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetUserRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, iam.UserPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.UserPrefix)
}
func validateCreateRequest(req *pbs.CreateUserRequest) error {
@@ -683,11 +681,11 @@ func validateCreateRequest(req *pbs.CreateUserRequest) error {
}
func validateUpdateRequest(req *pbs.UpdateUserRequest) error {
return handlers.ValidateUpdateRequest(req, req.GetItem(), handlers.NoopValidatorFn, iam.UserPrefix)
return handlers.ValidateUpdateRequest(req, req.GetItem(), handlers.NoopValidatorFn, globals.UserPrefix)
}
func validateDeleteRequest(req *pbs.DeleteUserRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, iam.UserPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.UserPrefix)
}
func validateListRequest(req *pbs.ListUsersRequest) error {
@@ -707,7 +705,7 @@ func validateListRequest(req *pbs.ListUsersRequest) error {
func validateAddUserAccountsRequest(req *pbs.AddUserAccountsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.UserPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.UserPrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -719,9 +717,9 @@ func validateAddUserAccountsRequest(req *pbs.AddUserAccountsRequest) error {
for _, a := range req.GetAccountIds() {
// TODO: Increase the type of auth accounts that can be added to a user.
if !handlers.ValidId(handlers.Id(a),
intglobals.OldPasswordAccountPrefix,
intglobals.NewPasswordAccountPrefix,
oidc.AccountPrefix,
globals.PasswordAccountPreviousPrefix,
globals.PasswordAccountPrefix,
globals.OidcAccountPrefix,
) {
badFields["account_ids"] = "Values must be valid account ids."
break
@@ -735,7 +733,7 @@ func validateAddUserAccountsRequest(req *pbs.AddUserAccountsRequest) error {
func validateSetUserAccountsRequest(req *pbs.SetUserAccountsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.UserPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.UserPrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -744,9 +742,9 @@ func validateSetUserAccountsRequest(req *pbs.SetUserAccountsRequest) error {
for _, a := range req.GetAccountIds() {
// TODO: Increase the type of auth accounts that can be added to a user.
if !handlers.ValidId(handlers.Id(a),
intglobals.OldPasswordAccountPrefix,
intglobals.NewPasswordAccountPrefix,
oidc.AccountPrefix,
globals.PasswordAccountPreviousPrefix,
globals.PasswordAccountPrefix,
globals.OidcAccountPrefix,
) {
badFields["account_ids"] = "Values must be valid account ids."
break
@@ -760,7 +758,7 @@ func validateSetUserAccountsRequest(req *pbs.SetUserAccountsRequest) error {
func validateRemoveUserAccountsRequest(req *pbs.RemoveUserAccountsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), iam.UserPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.UserPrefix) {
badFields["id"] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -772,9 +770,9 @@ func validateRemoveUserAccountsRequest(req *pbs.RemoveUserAccountsRequest) error
for _, a := range req.GetAccountIds() {
// TODO: Increase the type of auth accounts that can be added to a user.
if !handlers.ValidId(handlers.Id(a),
intglobals.OldPasswordAccountPrefix,
intglobals.NewPasswordAccountPrefix,
oidc.AccountPrefix,
globals.PasswordAccountPreviousPrefix,
globals.PasswordAccountPrefix,
globals.OidcAccountPrefix,
) {
badFields["account_ids"] = "Values must be valid account ids."
break
@@ -120,7 +120,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non existant User",
req: &pbs.GetUserRequest{Id: iam.UserPrefix + "_DoesntExis"},
req: &pbs.GetUserRequest{Id: globals.UserPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -132,7 +132,7 @@ func TestGet(t *testing.T) {
},
{
name: "space in id",
req: &pbs.GetUserRequest{Id: iam.UserPrefix + "_1 23456789"},
req: &pbs.GetUserRequest{Id: globals.UserPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -349,7 +349,7 @@ func TestDelete(t *testing.T) {
{
name: "Delete bad user id",
req: &pbs.DeleteUserRequest{
Id: iam.UserPrefix + "_doesntexis",
Id: globals.UserPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -409,7 +409,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
}},
res: &pbs.CreateUserResponse{
Uri: fmt.Sprintf("users/%s_", iam.UserPrefix),
Uri: fmt.Sprintf("users/%s_", globals.UserPrefix),
Item: &pb.User{
ScopeId: defaultUser.GetScopeId(),
Scope: &scopes.ScopeInfo{Id: defaultUser.GetScopeId(), Type: scope.Org.String(), ParentScopeId: scope.Global.String()},
@@ -428,7 +428,7 @@ func TestCreate(t *testing.T) {
Description: &wrapperspb.StringValue{Value: "desc"},
}},
res: &pbs.CreateUserResponse{
Uri: fmt.Sprintf("users/%s_", iam.UserPrefix),
Uri: fmt.Sprintf("users/%s_", globals.UserPrefix),
Item: &pb.User{
ScopeId: scope.Global.String(),
Scope: &scopes.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String(), Name: scope.Global.String(), Description: "Global Scope"},
@@ -443,7 +443,7 @@ func TestCreate(t *testing.T) {
name: "Can't specify Id",
req: &pbs.CreateUserRequest{Item: &pb.User{
ScopeId: defaultUser.GetScopeId(),
Id: iam.UserPrefix + "_notallowed",
Id: globals.UserPrefix + "_notallowed",
}},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
@@ -480,7 +480,7 @@ func TestCreate(t *testing.T) {
}
if got != nil {
assert.Contains(got.GetUri(), tc.res.Uri)
assert.True(strings.HasPrefix(got.GetItem().GetId(), iam.UserPrefix+"_"))
assert.True(strings.HasPrefix(got.GetItem().GetId(), globals.UserPrefix+"_"))
gotCreateTime := got.GetItem().GetCreatedTime().AsTime()
gotUpdateTime := got.GetItem().GetUpdatedTime().AsTime()
// Verify it is a user created after the test setup's default user
@@ -672,7 +672,7 @@ func TestUpdate(t *testing.T) {
{
name: "Update a Non Existing User",
req: &pbs.UpdateUserRequest{
Id: iam.UserPrefix + "_DoesntExis",
Id: globals.UserPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
@@ -691,7 +691,7 @@ func TestUpdate(t *testing.T) {
Paths: []string{"id"},
},
Item: &pb.User{
Id: iam.UserPrefix + "_somethinge",
Id: globals.UserPrefix + "_somethinge",
Name: &wrapperspb.StringValue{Value: "new"},
Description: &wrapperspb.StringValue{Value: "new desc"},
},
@@ -880,7 +880,7 @@ func tagsToMapProto(in map[string][]string) (map[string]*structpb.ListValue, err
// - All required parameters are set
// - There are no conflicting parameters provided
func validateGetRequest(req *pbs.GetWorkerRequest) error {
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, server.WorkerPrefix)
return handlers.ValidateGetRequest(handlers.NoopValidatorFn, req, globals.WorkerPrefix)
}
func validateListRequest(req *pbs.ListWorkersRequest) error {
@@ -898,7 +898,7 @@ func validateListRequest(req *pbs.ListWorkersRequest) error {
}
func validateDeleteRequest(req *pbs.DeleteWorkerRequest) error {
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, server.WorkerPrefix)
return handlers.ValidateDeleteRequest(handlers.NoopValidatorFn, req, globals.WorkerPrefix)
}
func validateUpdateRequest(req *pbs.UpdateWorkerRequest) error {
@@ -925,7 +925,7 @@ func validateUpdateRequest(req *pbs.UpdateWorkerRequest) error {
badFields[globals.DescriptionField] = "Contains non-printable characters."
}
return badFields
}, server.WorkerPrefix)
}, globals.WorkerPrefix)
}
func validateCreateRequest(item *pb.Worker, act action.Type) error {
@@ -1001,7 +1001,7 @@ func validateStringForDb(str string) string {
func validateAddTagsRequest(req *pbs.AddWorkerTagsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), server.WorkerPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.WorkerPrefix) {
badFields[globals.IdField] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1038,7 +1038,7 @@ func validateAddTagsRequest(req *pbs.AddWorkerTagsRequest) error {
func validateSetTagsRequest(req *pbs.SetWorkerTagsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), server.WorkerPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.WorkerPrefix) {
badFields[globals.IdField] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -1072,7 +1072,7 @@ func validateSetTagsRequest(req *pbs.SetWorkerTagsRequest) error {
func validateRemoveTagsRequest(req *pbs.RemoveWorkerTagsRequest) error {
badFields := map[string]string{}
if !handlers.ValidId(handlers.Id(req.GetId()), server.WorkerPrefix) {
if !handlers.ValidId(handlers.Id(req.GetId()), globals.WorkerPrefix) {
badFields[globals.IdField] = "Incorrectly formatted identifier."
}
if req.GetVersion() == 0 {
@@ -202,7 +202,7 @@ func TestGet(t *testing.T) {
},
{
name: "Get a non-existent Worker",
req: &pbs.GetWorkerRequest{Id: server.WorkerPrefix + "_DoesntExis"},
req: &pbs.GetWorkerRequest{Id: globals.WorkerPrefix + "_DoesntExis"},
res: nil,
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -214,7 +214,7 @@ func TestGet(t *testing.T) {
},
{
name: "Space in id",
req: &pbs.GetWorkerRequest{Id: server.WorkerPrefix + "_1 23456789"},
req: &pbs.GetWorkerRequest{Id: globals.WorkerPrefix + "_1 23456789"},
res: nil,
err: handlers.ApiErrorWithCode(codes.InvalidArgument),
},
@@ -430,7 +430,7 @@ func TestDelete(t *testing.T) {
name: "Delete bad worker id",
scopeId: w.GetScopeId(),
req: &pbs.DeleteWorkerRequest{
Id: server.WorkerPrefix + "_doesntexis",
Id: globals.WorkerPrefix + "_doesntexis",
},
err: handlers.ApiErrorWithCode(codes.NotFound),
},
@@ -719,7 +719,7 @@ func TestUpdate(t *testing.T) {
{
name: "Update a Non Existing Worker",
req: &pbs.UpdateWorkerRequest{
Id: server.WorkerPrefix + "_DoesntExis",
Id: globals.WorkerPrefix + "_DoesntExis",
UpdateMask: &field_mask.FieldMask{
Paths: []string{"description"},
},
+3 -3
View File
@@ -20,6 +20,7 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/api/authtokens"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/config"
@@ -29,7 +30,6 @@ import (
"github.com/hashicorp/boundary/internal/gen/testing/interceptor"
"github.com/hashicorp/boundary/internal/host/plugin"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/observability/event"
"github.com/hashicorp/boundary/internal/scheduler"
@@ -54,9 +54,9 @@ const (
DefaultTestUnprivilegedLoginName = "user"
DefaultTestPassword = "passpass"
DefaultTestUserId = "u_1234567890"
DefaultTestPasswordAccountId = intglobals.NewPasswordAccountPrefix + "_1234567890"
DefaultTestPasswordAccountId = globals.PasswordAccountPrefix + "_1234567890"
DefaultTestOidcAccountId = "acctoidc_1234567890"
DefaultTestUnprivilegedPasswordAccountId = intglobals.NewPasswordAccountPrefix + "_0987654321"
DefaultTestUnprivilegedPasswordAccountId = globals.PasswordAccountPrefix + "_0987654321"
DefaultTestUnprivilegedOidcAccountId = "acctoidc_0987654321"
DefaultTestPluginId = "pl_1234567890"
)
+1 -1
View File
@@ -81,7 +81,7 @@ func (w *Worker) handleProxy(listenerCfg *listenerutil.ListenerConfig, sessionMa
outerCertLoop:
for _, cert := range r.TLS.PeerCertificates {
for _, name := range cert.DNSNames {
if strings.HasPrefix(name, globals.SessionPrefix) {
if strings.HasPrefix(name, fmt.Sprintf("%s_", globals.SessionPrefix)) {
sessionId = name
break outerCertLoop
}
+2 -2
View File
@@ -590,11 +590,11 @@ func (w *Worker) getSessionTls(sessionManager session.Manager) func(hello *tls.C
ctx := w.baseContext
var sessionId string
switch {
case strings.HasPrefix(hello.ServerName, globals.SessionPrefix):
case strings.HasPrefix(hello.ServerName, fmt.Sprintf("%s_", globals.SessionPrefix)):
sessionId = hello.ServerName
default:
for _, proto := range hello.SupportedProtos {
if strings.HasPrefix(proto, globals.SessionPrefix) {
if strings.HasPrefix(proto, fmt.Sprintf("%s_", globals.SessionPrefix)) {
sessionId = proto
break
}
+5 -4
View File
@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/host/plugin/store"
"github.com/hashicorp/boundary/internal/iam"
@@ -47,25 +48,25 @@ func TestHostSetMember_InsertDelete(t *testing.T) {
blueSet2 := TestSet(t, conn, kms, sched, blueCat, plgm)
blueSet3 := TestSet(t, conn, kms, sched, blueCat, plgm)
hostId, err := db.NewPublicId(HostPrefix)
hostId, err := db.NewPublicId(globals.PluginHostPrefix)
require.NoError(t, err)
blueHost1 := NewHost(ctx, blueCat.PublicId, "blue1", withPluginId(plg.GetPublicId()))
blueHost1.PublicId = hostId
require.NoError(t, rw.Create(ctx, blueHost1))
hostId, err = db.NewPublicId(HostPrefix)
hostId, err = db.NewPublicId(globals.PluginHostPrefix)
require.NoError(t, err)
blueHost2 := NewHost(ctx, blueCat.PublicId, "blue2", withPluginId(plg.GetPublicId()))
blueHost2.PublicId = hostId
require.NoError(t, rw.Create(ctx, blueHost2))
hostId, err = db.NewPublicId(HostPrefix)
hostId, err = db.NewPublicId(globals.PluginHostPrefix)
require.NoError(t, err)
blueHost3 := NewHost(ctx, blueCat.PublicId, "blue3", withPluginId(plg.GetPublicId()))
blueHost3.PublicId = hostId
require.NoError(t, rw.Create(ctx, blueHost3))
hostId, err = db.NewPublicId(HostPrefix)
hostId, err = db.NewPublicId(globals.PluginHostPrefix)
require.NoError(t, err)
blueHost4 := NewHost(ctx, blueCat.PublicId, "blue4", withPluginId(plg.GetPublicId()))
blueHost4.PublicId = hostId
+5 -11
View File
@@ -6,6 +6,7 @@ package plugin
import (
"context"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/host"
@@ -13,25 +14,18 @@ import (
)
func init() {
if err := subtypes.Register(host.Domain, Subtype, HostCatalogPrefix, PreviousHostCatalogPrefix, HostSetPrefix, PreviousHostSetPrefix, HostPrefix, PreviousHostPrefix); err != nil {
if err := subtypes.Register(host.Domain, Subtype, globals.PluginHostCatalogPrefix, globals.PluginHostCatalogPreviousPrefix, globals.PluginHostSetPrefix, globals.PluginHostSetPreviousPrefix, globals.PluginHostPrefix, globals.PluginHostPreviousPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the plugin package.
const (
HostCatalogPrefix = "hcplg"
PreviousHostCatalogPrefix = "hc"
HostSetPrefix = "hsplg"
PreviousHostSetPrefix = "hs"
HostPrefix = "hplg"
PreviousHostPrefix = "h"
Subtype = subtypes.Subtype("plugin")
)
func newHostCatalogId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(HostCatalogPrefix)
id, err := db.NewPublicId(globals.PluginHostCatalogPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "plugin.newHostCatalogId")
}
@@ -39,7 +33,7 @@ func newHostCatalogId(ctx context.Context) (string, error) {
}
func newHostSetId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(HostSetPrefix)
id, err := db.NewPublicId(globals.PluginHostSetPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "plugin.newHostSetId")
}
@@ -54,7 +48,7 @@ func newHostId(ctx context.Context, catalogId, externalId string) (string, error
if externalId == "" {
return "", errors.New(ctx, errors.InvalidParameter, op, "missing external id")
}
id, err := db.NewPublicId(HostPrefix, db.WithPrngValues([]string{catalogId, externalId}))
id, err := db.NewPublicId(globals.PluginHostPrefix, db.WithPrngValues([]string{catalogId, externalId}))
if err != nil {
return "", errors.Wrap(ctx, err, op)
}
@@ -11,6 +11,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
@@ -317,7 +318,7 @@ func TestRepository_CreateCatalog(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
assert.NotNil(got)
assertPluginBasedPublicId(t, HostCatalogPrefix, got.PublicId)
assertPluginBasedPublicId(t, globals.PluginHostCatalogPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -398,7 +399,7 @@ func TestRepository_CreateCatalog(t *testing.T) {
assert.NoError(err)
assert.NotNil(got)
assert.True(pluginCalled)
assertPluginBasedPublicId(t, HostCatalogPrefix, got.PublicId)
assertPluginBasedPublicId(t, globals.PluginHostCatalogPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -446,7 +447,7 @@ func TestRepository_CreateCatalog(t *testing.T) {
assert.NoError(err)
assert.NotNil(got)
assert.True(pluginCalled)
assertPluginBasedPublicId(t, HostCatalogPrefix, got.PublicId)
assertPluginBasedPublicId(t, globals.PluginHostCatalogPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -458,7 +459,7 @@ func TestRepository_CreateCatalog(t *testing.T) {
assert.NoError(err)
assert.NotNil(got2)
assert.True(pluginCalled)
assertPluginBasedPublicId(t, HostCatalogPrefix, got2.PublicId)
assertPluginBasedPublicId(t, globals.PluginHostCatalogPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -13,6 +13,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
@@ -320,7 +321,7 @@ func TestRepository_CreateSet(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assert.True(strings.HasPrefix(got.GetPublicId(), HostSetPrefix))
assert.True(strings.HasPrefix(got.GetPublicId(), globals.PluginHostSetPrefix))
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.GetName())
assert.Equal(tt.want.Description, got.GetDescription())
@@ -379,7 +380,7 @@ func TestRepository_CreateSet(t *testing.T) {
require.NoError(err)
require.NotNil(got)
assert.True(pluginCalled)
assert.True(strings.HasPrefix(got.GetPublicId(), HostSetPrefix))
assert.True(strings.HasPrefix(got.GetPublicId(), globals.PluginHostSetPrefix))
assert.NotSame(in, got)
assert.Equal(in.Name, got.GetName())
assert.Equal(in.Description, got.GetDescription())
@@ -427,7 +428,7 @@ func TestRepository_CreateSet(t *testing.T) {
assert.True(pluginCalled)
require.NoError(err)
require.NotNil(got)
assert.True(strings.HasPrefix(got.GetPublicId(), HostSetPrefix))
assert.True(strings.HasPrefix(got.GetPublicId(), globals.PluginHostSetPrefix))
assert.NotSame(in, got)
assert.Equal(in.Name, got.GetName())
assert.Equal(in.Description, got.GetDescription())
@@ -441,7 +442,7 @@ func TestRepository_CreateSet(t *testing.T) {
require.NoError(err)
require.NotNil(got2)
assert.True(pluginCalled)
assert.True(strings.HasPrefix(got.GetPublicId(), HostSetPrefix))
assert.True(strings.HasPrefix(got.GetPublicId(), globals.PluginHostSetPrefix))
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.GetName())
assert.Equal(in2.Description, got2.GetDescription())
+3 -2
View File
@@ -7,6 +7,7 @@ import (
"context"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
@@ -31,7 +32,7 @@ func Test_TestCatalogs(t *testing.T) {
cs := TestCatalog(t, conn, proj.GetPublicId(), plg.GetPublicId(), WithName("foo"), WithDescription("bar"))
assert.NotEmpty(cs.GetPublicId())
db.AssertPublicId(t, HostCatalogPrefix, cs.GetPublicId())
db.AssertPublicId(t, globals.PluginHostCatalogPrefix, cs.GetPublicId())
assert.Equal("foo", cs.GetName())
assert.Equal("bar", cs.GetDescription())
}
@@ -53,7 +54,7 @@ func Test_TestSet(t *testing.T) {
c := TestCatalog(t, conn, prj.GetPublicId(), plg.GetPublicId())
set := TestSet(t, conn, kmsCache, sched, c, map[string]plgpb.HostPluginServiceClient{plg.GetPublicId(): NewWrappingPluginClient(&TestPluginServer{})}, WithName("foo"), WithDescription("bar"))
assert.NotEmpty(set.GetPublicId())
db.AssertPublicId(t, HostSetPrefix, set.GetPublicId())
db.AssertPublicId(t, globals.PluginHostSetPrefix, set.GetPublicId())
assert.Equal("foo", set.GetName())
assert.Equal("bar", set.GetDescription())
}
+5 -8
View File
@@ -4,6 +4,7 @@
package static
import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/host"
@@ -11,22 +12,18 @@ import (
)
func init() {
if err := subtypes.Register(host.Domain, Subtype, HostCatalogPrefix, HostSetPrefix, HostPrefix); err != nil {
if err := subtypes.Register(host.Domain, Subtype, globals.StaticHostCatalogPrefix, globals.StaticHostSetPrefix, globals.StaticHostPrefix); err != nil {
panic(err)
}
}
// PublicId prefixes for the resources in the static package.
const (
HostCatalogPrefix = "hcst"
HostSetPrefix = "hsst"
HostPrefix = "hst"
Subtype = subtypes.Subtype("static")
)
func newHostCatalogId() (string, error) {
id, err := db.NewPublicId(HostCatalogPrefix)
id, err := db.NewPublicId(globals.StaticHostCatalogPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "static.newHostCatalogId")
}
@@ -34,7 +31,7 @@ func newHostCatalogId() (string, error) {
}
func newHostId() (string, error) {
id, err := db.NewPublicId(HostPrefix)
id, err := db.NewPublicId(globals.StaticHostPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "static.newHostId")
}
@@ -42,7 +39,7 @@ func newHostId() (string, error) {
}
func newHostSetId() (string, error) {
id, err := db.NewPublicId(HostSetPrefix)
id, err := db.NewPublicId(globals.StaticHostSetPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "static.newHostSetId")
}
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -50,11 +51,11 @@ func (r *Repository) CreateHost(ctx context.Context, projectId string, h *Host,
opts := getOpts(opt...)
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, HostPrefix+"_") {
if !strings.HasPrefix(opts.withPublicId, globals.StaticHostPrefix+"_") {
return nil, errors.New(ctx,
errors.InvalidPublicId,
op,
fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, HostPrefix),
fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, globals.StaticHostPrefix),
)
}
h.PublicId = opts.withPublicId
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -42,11 +43,11 @@ func (r *Repository) CreateCatalog(ctx context.Context, c *HostCatalog, opt ...O
opts := getOpts(opt...)
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, HostCatalogPrefix+"_") {
if !strings.HasPrefix(opts.withPublicId, globals.StaticHostCatalogPrefix+"_") {
return nil, errors.New(ctx,
errors.InvalidPublicId,
op,
fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, HostCatalogPrefix),
fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, globals.StaticHostCatalogPrefix),
)
}
c.PublicId = opts.withPublicId
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/host"
@@ -45,11 +46,11 @@ func (r *Repository) CreateSet(ctx context.Context, projectId string, s *HostSet
opts := getOpts(opt...)
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, HostSetPrefix+"_") {
if !strings.HasPrefix(opts.withPublicId, globals.StaticHostSetPrefix+"_") {
return nil, errors.New(ctx,
errors.InvalidPublicId,
op,
fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, HostSetPrefix),
fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, globals.StaticHostSetPrefix),
)
}
s.PublicId = opts.withPublicId
@@ -10,6 +10,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
"github.com/hashicorp/boundary/internal/errors"
@@ -125,7 +126,7 @@ func TestRepository_CreateSet(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, HostSetPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostSetPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -153,7 +154,7 @@ func TestRepository_CreateSet(t *testing.T) {
got, err := repo.CreateSet(context.Background(), prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, HostSetPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostSetPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -186,7 +187,7 @@ func TestRepository_CreateSet(t *testing.T) {
got, err := repo.CreateSet(context.Background(), prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, HostSetPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostSetPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -196,7 +197,7 @@ func TestRepository_CreateSet(t *testing.T) {
got2, err := repo.CreateSet(context.Background(), prj.GetPublicId(), in2)
require.NoError(err)
require.NotNil(got2)
assertPublicId(t, HostSetPrefix, got2.PublicId)
assertPublicId(t, globals.StaticHostSetPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -493,7 +494,7 @@ func TestRepository_UpdateSet(t *testing.T) {
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, HostSetPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostSetPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.CatalogId, got.CatalogId)
@@ -577,7 +578,7 @@ func TestRepository_UpdateSet(t *testing.T) {
got, err := repo.CreateSet(context.Background(), prj.GetPublicId(), in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, HostSetPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostSetPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
+7 -6
View File
@@ -11,6 +11,7 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
"github.com/hashicorp/boundary/internal/db/timestamp"
@@ -174,7 +175,7 @@ func TestRepository_CreateHost(t *testing.T) {
require.NoError(err)
assert.Empty(tt.in.PublicId)
require.NotNil(got)
assertPublicId(t, HostPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostPrefix, got.PublicId)
assert.NotSame(tt.in, got)
assert.Equal(tt.want.Name, got.Name)
assert.Equal(tt.want.Description, got.Description)
@@ -203,7 +204,7 @@ func TestRepository_CreateHost(t *testing.T) {
got, err := repo.CreateHost(context.Background(), prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, HostPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -237,7 +238,7 @@ func TestRepository_CreateHost(t *testing.T) {
got, err := repo.CreateHost(context.Background(), prj.GetPublicId(), in)
require.NoError(err)
require.NotNil(got)
assertPublicId(t, HostPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
@@ -247,7 +248,7 @@ func TestRepository_CreateHost(t *testing.T) {
got2, err := repo.CreateHost(context.Background(), prj.GetPublicId(), in2)
require.NoError(err)
require.NotNil(got2)
assertPublicId(t, HostPrefix, got2.PublicId)
assertPublicId(t, globals.StaticHostPrefix, got2.PublicId)
assert.NotSame(in2, got2)
assert.Equal(in2.Name, got2.Name)
assert.Equal(in2.Description, got2.Description)
@@ -626,7 +627,7 @@ func TestRepository_UpdateHost(t *testing.T) {
assert.NoError(err)
assert.Empty(tt.orig.PublicId)
require.NotNil(got)
assertPublicId(t, HostPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostPrefix, got.PublicId)
assert.Equal(tt.wantCount, gotCount, "row count")
assert.NotSame(tt.orig, got)
assert.Equal(tt.orig.CatalogId, got.CatalogId)
@@ -704,7 +705,7 @@ func TestRepository_UpdateHost(t *testing.T) {
got, err := repo.CreateHost(context.Background(), prj.GetPublicId(), in)
assert.NoError(err)
require.NotNil(got)
assertPublicId(t, HostPrefix, got.PublicId)
assertPublicId(t, globals.StaticHostPrefix, got.PublicId)
assert.NotSame(in, got)
assert.Equal(in.Name, got.Name)
assert.Equal(in.Description, got.Description)
+5 -6
View File
@@ -6,20 +6,19 @@ package iam
import (
"fmt"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/types/scope"
)
const (
UserPrefix = "u"
GroupPrefix = "g"
RolePrefix = "r"
// RoleGrantPrefix is the prefix for role grants
RoleGrantPrefix = "rg"
)
func newRoleId() (string, error) {
id, err := db.NewPublicId(RolePrefix)
id, err := db.NewPublicId(globals.RolePrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newRoleId")
}
@@ -27,7 +26,7 @@ func newRoleId() (string, error) {
}
func newUserId() (string, error) {
id, err := db.NewPublicId(UserPrefix)
id, err := db.NewPublicId(globals.UserPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newUserId")
}
@@ -35,7 +34,7 @@ func newUserId() (string, error) {
}
func newGroupId() (string, error) {
id, err := db.NewPublicId(GroupPrefix)
id, err := db.NewPublicId(globals.GroupPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, "iam.newGroupId")
}
+5 -5
View File
@@ -7,8 +7,8 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/types/scope"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
@@ -18,20 +18,20 @@ func Test_PublicIds(t *testing.T) {
t.Run("role", func(t *testing.T) {
id, err := newRoleId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, RolePrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.RolePrefix+"_"))
})
t.Run("user", func(t *testing.T) {
id, err := newUserId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, UserPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.UserPrefix+"_"))
})
t.Run("group", func(t *testing.T) {
id, err := newGroupId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, GroupPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.GroupPrefix+"_"))
})
t.Run("oidc managed group", func(t *testing.T) {
assert.True(t, strings.HasPrefix("mgoidc_1234567890", intglobals.OidcManagedGroupPrefix+"_"))
assert.True(t, strings.HasPrefix("mgoidc_1234567890", globals.OidcManagedGroupPrefix+"_"))
})
t.Run("scopes", func(t *testing.T) {
id, err := newScopeId(scope.Org)
+4 -4
View File
@@ -8,9 +8,9 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/oplog"
)
@@ -595,17 +595,17 @@ func splitPrincipals(ctx context.Context, principals []string) (users, groups, m
const op = "iam.splitPrincipals"
for _, principal := range principals {
switch {
case strings.HasPrefix(principal, UserPrefix):
case strings.HasPrefix(principal, globals.UserPrefix):
if users == nil {
users = make([]string, 0, len(principals))
}
users = append(users, principal)
case strings.HasPrefix(principal, GroupPrefix):
case strings.HasPrefix(principal, globals.GroupPrefix):
if groups == nil {
groups = make([]string, 0, len(principals))
}
groups = append(groups, principal)
case strings.HasPrefix(principal, intglobals.OidcManagedGroupPrefix):
case strings.HasPrefix(principal, globals.OidcManagedGroupPrefix):
if managedGroups == nil {
managedGroups = make([]string, 0, len(principals))
}
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"fmt"
"strings"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/kms"
@@ -30,8 +31,8 @@ func (r *Repository) CreateUser(ctx context.Context, user *User, opt ...Option)
opts := getOpts(opt...)
if opts.withPublicId != "" {
if !strings.HasPrefix(opts.withPublicId, UserPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, UserPrefix))
if !strings.HasPrefix(opts.withPublicId, globals.UserPrefix+"_") {
return nil, errors.New(ctx, errors.InvalidParameter, op, fmt.Sprintf("passed-in public ID %q has wrong prefix, should be %q", opts.withPublicId, globals.UserPrefix))
}
u.PublicId = opts.withPublicId
} else {
+2 -1
View File
@@ -11,6 +11,7 @@ import (
"time"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/auth/store"
@@ -540,7 +541,7 @@ func TestRepository_DeleteUser(t *testing.T) {
user: func() *iam.User {
u, err := iam.NewUser(org.PublicId)
require.NoError(t, err)
id, err := db.NewPublicId(iam.UserPrefix)
id, err := db.NewPublicId(globals.UserPrefix)
require.NoError(t, err)
u.PublicId = id
return u
-21
View File
@@ -1,21 +0,0 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package intglobals
// This set of consts is intended to be a place to collect commonly-used
// prefixes. This can avoid some cross-package dependency issues. Unlike the
// top-level globals package, these are not currently meant to be available to
// clients or test writers.
const (
// OidcManagedGroupPrefix defines the prefix for ManagedGroup public ids
// from the OIDC auth method.
OidcManagedGroupPrefix = "mgoidc"
// OldPasswordAccountPrefix is the previously-used account prefix
OldPasswordAccountPrefix = "apw"
// NewPasswordAccountPrefix is the new account prefix
NewPasswordAccountPrefix = "acctpw"
)
+6 -7
View File
@@ -9,7 +9,6 @@ import (
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -245,17 +244,17 @@ func Test_ACLAllowed(t *testing.T) {
{action: action.Authenticate},
{action: action.Delete},
},
accountId: fmt.Sprintf("%s_1234567890", intglobals.OldPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPreviousPrefix),
},
{
name: "good templated old account id",
resource: Resource{ScopeId: "o_c", Id: fmt.Sprintf("%s_1234567890", intglobals.OldPasswordAccountPrefix)},
resource: Resource{ScopeId: "o_c", Id: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPreviousPrefix)},
scopeGrants: commonGrants,
actionsAuthorized: []actionAuthorized{
{action: action.ChangePassword, authorized: true},
{action: action.Update},
},
accountId: fmt.Sprintf("%s_1234567890", intglobals.OldPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPreviousPrefix),
},
{
name: "bad templated new account id",
@@ -266,17 +265,17 @@ func Test_ACLAllowed(t *testing.T) {
{action: action.Authenticate},
{action: action.Delete},
},
accountId: fmt.Sprintf("%s_1234567890", intglobals.NewPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPrefix),
},
{
name: "good templated new account id",
resource: Resource{ScopeId: "o_c", Id: fmt.Sprintf("%s_1234567890", intglobals.NewPasswordAccountPrefix)},
resource: Resource{ScopeId: "o_c", Id: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPrefix)},
scopeGrants: commonGrants,
actionsAuthorized: []actionAuthorized{
{action: action.ChangePassword, authorized: true},
{action: action.Update},
},
accountId: fmt.Sprintf("%s_1234567890", intglobals.NewPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPrefix),
},
{
name: "all type",
+7 -7
View File
@@ -7,7 +7,7 @@ import (
"fmt"
"testing"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/types/action"
"github.com/hashicorp/boundary/internal/types/resource"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -682,25 +682,25 @@ func Test_Parse(t *testing.T) {
{
name: "bad old account id template",
input: `id={{superman}};actions=read`,
accountId: fmt.Sprintf("%s_1234567890", intglobals.OldPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPreviousPrefix),
err: `perms.Parse: unknown template "{{superman}}" in grant "id" value: parameter violation: error #100`,
},
{
name: "bad new account id template",
input: `id={{superman}};actions=read`,
accountId: fmt.Sprintf("%s_1234567890", intglobals.NewPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPrefix),
err: `perms.Parse: unknown template "{{superman}}" in grant "id" value: parameter violation: error #100`,
},
{
name: "good old account id template",
input: `id={{ account.id}};actions=update,read`,
accountId: fmt.Sprintf("%s_1234567890", intglobals.OldPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPreviousPrefix),
expected: Grant{
scope: Scope{
Id: "o_scope",
Type: scope.Org,
},
id: fmt.Sprintf("%s_1234567890", intglobals.OldPasswordAccountPrefix),
id: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPreviousPrefix),
actions: map[action.Type]bool{
action.Update: true,
action.Read: true,
@@ -710,13 +710,13 @@ func Test_Parse(t *testing.T) {
{
name: "good new account id template",
input: `id={{ account.id}};actions=update,read`,
accountId: fmt.Sprintf("%s_1234567890", intglobals.NewPasswordAccountPrefix),
accountId: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPrefix),
expected: Grant{
scope: Scope{
Id: "o_scope",
Type: scope.Org,
},
id: fmt.Sprintf("%s_1234567890", intglobals.NewPasswordAccountPrefix),
id: fmt.Sprintf("%s_1234567890", globals.PasswordAccountPrefix),
actions: map[action.Type]bool{
action.Update: true,
action.Read: true,
+3 -7
View File
@@ -6,17 +6,13 @@ package server
import (
"context"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
)
// PublicId prefixes for the resources in the server package.
const (
WorkerPrefix = "w"
)
func newWorkerId(ctx context.Context) (string, error) {
id, err := db.NewPublicId(WorkerPrefix)
id, err := db.NewPublicId(globals.WorkerPrefix)
if err != nil {
return "", errors.Wrap(ctx, err, "server.newWorkerId")
}
@@ -28,7 +24,7 @@ func newWorkerId(ctx context.Context) (string, error) {
// upsert time.
func newWorkerIdFromScopeAndName(ctx context.Context, scope, name string) (string, error) {
const op = "server.newWorkerIdFromScopeAndName"
id, err := db.NewPublicId(WorkerPrefix, db.WithPrngValues([]string{scope, name}))
id, err := db.NewPublicId(globals.WorkerPrefix, db.WithPrngValues([]string{scope, name}))
if err != nil {
return "", errors.Wrap(ctx, err, "server.newWorkerId")
}
+2 -1
View File
@@ -13,6 +13,7 @@ import (
"github.com/DATA-DOG/go-sqlmock"
"github.com/google/go-cmp/cmp"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
@@ -944,7 +945,7 @@ func TestRepository_CreateWorker(t *testing.T) {
setup: func() *server.Worker {
w := server.NewWorker(scope.Global.String())
var err error
w.PublicId, err = db.NewPublicId(server.WorkerPrefix)
w.PublicId, err = db.NewPublicId(globals.WorkerPrefix)
require.NoError(t, err)
return w
},
+4 -3
View File
@@ -9,6 +9,7 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/types/scope"
@@ -26,7 +27,7 @@ func TestTestKmsWorker(t *testing.T) {
)
tWorker := TestKmsWorker(t, conn, wrapper, WithName(name), WithDescription(description), WithAddress(address), WithOperationalState(ShutdownOperationalState.String()))
assert.NotNil(t, tWorker)
assert.True(t, strings.HasPrefix(tWorker.GetPublicId(), WorkerPrefix))
assert.True(t, strings.HasPrefix(tWorker.GetPublicId(), globals.WorkerPrefix))
lkpWorker := NewWorker(scope.Global.String())
lkpWorker.PublicId = tWorker.GetPublicId()
@@ -52,7 +53,7 @@ func TestTestPkiWorker(t *testing.T) {
)
tWorker := TestPkiWorker(t, conn, wrapper, WithName(name), WithDescription(description))
assert.NotNil(t, tWorker)
assert.True(t, strings.HasPrefix(tWorker.GetPublicId(), WorkerPrefix))
assert.True(t, strings.HasPrefix(tWorker.GetPublicId(), globals.WorkerPrefix))
lkpWorker := NewWorker(scope.Global.String())
lkpWorker.PublicId = tWorker.GetPublicId()
@@ -67,6 +68,6 @@ func TestTestPkiWorker(t *testing.T) {
var keyId string
authorizedWorker := TestPkiWorker(t, conn, wrapper, WithTestPkiWorkerAuthorizedKeyId(&keyId))
assert.NotNil(t, authorizedWorker)
assert.True(t, strings.HasPrefix(authorizedWorker.GetPublicId(), WorkerPrefix))
assert.True(t, strings.HasPrefix(authorizedWorker.GetPublicId(), globals.WorkerPrefix))
assert.NotEmpty(t, keyId)
}
+2 -4
View File
@@ -4,14 +4,12 @@
package session
import (
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
)
const (
// SessionPrefix for session PK ids
SessionPrefix = "s"
// StatePrefix for state PK ids
StatePrefix = "ss"
@@ -24,7 +22,7 @@ const (
func newId() (string, error) {
const op = "session.newId"
id, err := db.NewPublicId(SessionPrefix)
id, err := db.NewPublicId(globals.SessionPrefix)
if err != nil {
return "", errors.WrapDeprecated(err, op)
}
+2 -1
View File
@@ -7,6 +7,7 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -16,7 +17,7 @@ func Test_Ids(t *testing.T) {
t.Run("s", func(t *testing.T) {
id, err := newId()
require.NoError(t, err)
assert.True(t, strings.HasPrefix(id, SessionPrefix+"_"))
assert.True(t, strings.HasPrefix(id, globals.SessionPrefix+"_"))
})
t.Run("ss", func(t *testing.T) {
id, err := newStateId()
+3 -2
View File
@@ -13,6 +13,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
@@ -201,7 +202,7 @@ func TestSession_Create(t *testing.T) {
require.NoError(err)
assert.Equal(tt.want, got)
if tt.create {
id, err := db.NewPublicId(SessionPrefix)
id, err := db.NewPublicId(globals.SessionPrefix)
require.NoError(err)
got.PublicId = id
privKey, certBytes, err := newCert(ctx, id, tt.args.addresses, composedOf.ExpirationTime.Timestamp.AsTime(), rand.Reader)
@@ -256,7 +257,7 @@ func TestSession_Delete(t *testing.T) {
name: "bad-id",
session: func() *Session {
s := AllocSession()
id, err := db.NewPublicId(SessionPrefix)
id, err := db.NewPublicId(globals.SessionPrefix)
require.NoError(t, err)
s.PublicId = id
return &s
@@ -7,6 +7,7 @@ import (
"context"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/static"
"github.com/hashicorp/boundary/internal/credential/vault"
@@ -44,7 +45,7 @@ func (h hooks) VetCredentialSources(ctx context.Context, cls []*target.Credentia
}
func TestRepository_SetTargetCredentialSources(t *testing.T) {
target.Register(targettest.Subtype, hooks{}, targettest.TargetPrefix)
target.Register(targettest.Subtype, hooks{}, globals.TcpTargetPrefix)
t.Parallel()
conn, _ := db.TestSetup(t, "postgres")
+3 -3
View File
@@ -11,6 +11,7 @@ import (
"strings"
"testing"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/db/timestamp"
"github.com/hashicorp/boundary/internal/errors"
@@ -23,8 +24,7 @@ import (
)
const (
Subtype = subtypes.Subtype("tcp")
TargetPrefix = "ttcp"
Subtype = subtypes.Subtype("tcp")
)
// Target is a target.Target used for tests.
@@ -296,7 +296,7 @@ func TestNewTestTarget(ctx context.Context, t *testing.T, conn *db.DB, projectId
rw := db.New(conn)
tar, err := New(projectId, opt...)
require.NoError(err)
id, err := db.NewPublicId(TargetPrefix)
id, err := db.NewPublicId(globals.TcpTargetPrefix)
require.NoError(err)
tar.SetPublicId(ctx, id)
err = rw.Create(context.Background(), tar)
@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/credential"
"github.com/hashicorp/boundary/internal/credential/vault"
"github.com/hashicorp/boundary/internal/db"
@@ -131,7 +132,7 @@ func TestRepository_CreateTarget(t *testing.T) {
target.WithDefaultPort(uint32(22)),
)
require.NoError(t, err)
id, err := db.NewPublicId(tcp.TargetPrefix)
id, err := db.NewPublicId(globals.TcpTargetPrefix)
require.NoError(t, err)
tar.SetPublicId(ctx, id)
return tar
+2 -1
View File
@@ -9,6 +9,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/iam"
@@ -234,7 +235,7 @@ func TestRepository_DeleteTarget(t *testing.T) {
name: "not-found",
args: args{
target: func() target.Target {
id, err := db.NewPublicId(tcp.TargetPrefix)
id, err := db.NewPublicId(globals.TcpTargetPrefix)
require.NoError(t, err)
tar, _ := target.New(ctx, tcp.Subtype, proj.PublicId)
tar.SetPublicId(ctx, id)
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"testing"
"time"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/db"
dbassert "github.com/hashicorp/boundary/internal/db/assert"
"github.com/hashicorp/boundary/internal/errors"
@@ -77,7 +78,7 @@ func TestTarget_Create(t *testing.T) {
require.NoError(err)
assert.Equal(tt.want, got)
if tt.create {
id, err := db.NewPublicId(tcp.TargetPrefix)
id, err := db.NewPublicId(globals.TcpTargetPrefix)
require.NoError(err)
got.SetPublicId(ctx, id)
err = db.New(conn).Create(ctx, got)
@@ -118,7 +119,7 @@ func TestTarget_Delete(t *testing.T) {
target: func() target.Target {
tar, _ := target.New(ctx, tcp.Subtype, proj.PublicId)
id, err := db.NewPublicId(tcp.TargetPrefix)
id, err := db.NewPublicId(globals.TcpTargetPrefix)
require.NoError(t, err)
tar.SetPublicId(ctx, id)
tar.SetName(tcp.TestTargetName(t, proj.PublicId))
+4 -5
View File
@@ -11,10 +11,9 @@ import (
"github.com/hashicorp/boundary/api"
"github.com/hashicorp/boundary/api/accounts"
"github.com/hashicorp/boundary/api/authmethods"
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/globals"
"github.com/hashicorp/boundary/internal/daemon/controller"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/intglobals"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -310,13 +309,13 @@ func TestErrors(t *testing.T) {
apiErr = api.AsServerError(err)
require.NotNil(apiErr)
_, err = accountClient.Read(tc.Context(), intglobals.OldPasswordAccountPrefix+"_doesntexis")
_, err = accountClient.Read(tc.Context(), globals.PasswordAccountPreviousPrefix+"_doesntexis")
require.Error(err)
apiErr = api.AsServerError(err)
require.NotNil(apiErr)
assert.EqualValues(http.StatusNotFound, apiErr.Response().StatusCode())
_, err = accountClient.Read(tc.Context(), intglobals.NewPasswordAccountPrefix+"_doesntexis")
_, err = accountClient.Read(tc.Context(), globals.PasswordAccountPrefix+"_doesntexis")
require.Error(err)
apiErr = api.AsServerError(err)
require.NotNil(apiErr)
@@ -376,7 +375,7 @@ func TestErrorsOidc(t *testing.T) {
apiErr = api.AsServerError(err)
require.NotNil(apiErr)
_, err = accountClient.Read(tc.Context(), oidc.AccountPrefix+"_doesntexis")
_, err = accountClient.Read(tc.Context(), globals.OidcAccountPrefix+"_doesntexis")
require.Error(err)
apiErr = api.AsServerError(err)
require.NotNil(apiErr)
Loaded 100 of 115 files, more files were not shown because too many files have changed in this diff. Show more