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:
1 parent
6adc0c86b5
commit
b76b24a4ad
115 files changed
+796
-729
No files matched your search
@@ -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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user