Merge branch 'tmessi-target-remove-unused-code' (#1631)
This commit is contained in:
4 files changed
+9
-96
No files matched your search
@@ -508,7 +508,6 @@ func (b *Server) CreateInitialTarget(ctx context.Context) (target.Target, error)
|
|||||||
target.WithName("Generated target"),
|
target.WithName("Generated target"),
|
||||||
target.WithDescription("Provides an initial target in Boundary"),
|
target.WithDescription("Provides an initial target in Boundary"),
|
||||||
target.WithDefaultPort(uint32(b.DevTargetDefaultPort)),
|
target.WithDefaultPort(uint32(b.DevTargetDefaultPort)),
|
||||||
target.WithHostSources([]string{b.DevHostSetId}),
|
|
||||||
target.WithSessionMaxSeconds(uint32(b.DevTargetSessionMaxSeconds)),
|
target.WithSessionMaxSeconds(uint32(b.DevTargetSessionMaxSeconds)),
|
||||||
target.WithSessionConnectionLimit(int32(b.DevTargetSessionConnectionLimit)),
|
target.WithSessionConnectionLimit(int32(b.DevTargetSessionConnectionLimit)),
|
||||||
target.WithPublicId(b.DevTargetId),
|
target.WithPublicId(b.DevTargetId),
|
||||||
@@ -521,6 +520,10 @@ func (b *Server) CreateInitialTarget(ctx context.Context) (target.Target, error)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error saving target to the db: %w", err)
|
return nil, fmt.Errorf("error saving target to the db: %w", err)
|
||||||
}
|
}
|
||||||
|
tt, _, _, err = targetRepo.AddTargetHostSources(ctx, tt.GetPublicId(), tt.GetVersion(), []string{b.DevHostSetId})
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error saving target to the db: %w", err)
|
||||||
|
}
|
||||||
b.InfoKeys = append(b.InfoKeys, "generated target id")
|
b.InfoKeys = append(b.InfoKeys, "generated target id")
|
||||||
b.Info["generated target id"] = b.DevTargetId
|
b.Info["generated target id"] = b.DevTargetId
|
||||||
|
|
||||||
|
|||||||
@@ -575,11 +575,13 @@ func TestUpdate(t *testing.T) {
|
|||||||
tar, err := tcp.New(proj.GetPublicId(), target.WithName("default"), target.WithDescription("default"))
|
tar, err := tcp.New(proj.GetPublicId(), target.WithName("default"), target.WithDescription("default"))
|
||||||
tar.DefaultPort = 2
|
tar.DefaultPort = 2
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
gtar, _, _, err := repo.CreateTarget(context.Background(), tar, target.WithHostSources([]string{hs[0].GetPublicId(), hs[1].GetPublicId()}))
|
gtar, _, _, err := repo.CreateTarget(context.Background(), tar)
|
||||||
|
require.NoError(t, err)
|
||||||
|
gtar, _, _, err = repo.AddTargetHostSources(context.Background(), gtar.GetPublicId(), gtar.GetVersion(), []string{hs[0].GetPublicId(), hs[1].GetPublicId()})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
tar = gtar.(*tcp.Target)
|
tar = gtar.(*tcp.Target)
|
||||||
|
|
||||||
var version uint32 = 1
|
var version uint32 = gtar.GetVersion()
|
||||||
|
|
||||||
resetTarget := func() {
|
resetTarget := func() {
|
||||||
version++
|
version++
|
||||||
|
|||||||
@@ -323,7 +323,7 @@ func (r *Repository) update(ctx context.Context, target Target, version uint32,
|
|||||||
|
|
||||||
// CreateTarget inserts into the repository and returns the new Target with
|
// CreateTarget inserts into the repository and returns the new Target with
|
||||||
// its list of host sets and credential libraries.
|
// its list of host sets and credential libraries.
|
||||||
// WithHostSources and WithCredentialSources are the only supported option.
|
// WithPublicId is the only supported option.
|
||||||
func (r *Repository) CreateTarget(ctx context.Context, target Target, opt ...Option) (Target, []HostSource, []CredentialSource, error) {
|
func (r *Repository) CreateTarget(ctx context.Context, target Target, opt ...Option) (Target, []HostSource, []CredentialSource, error) {
|
||||||
const op = "target.(Repository).CreateTarget"
|
const op = "target.(Repository).CreateTarget"
|
||||||
opts := GetOpts(opt...)
|
opts := GetOpts(opt...)
|
||||||
@@ -371,24 +371,6 @@ func (r *Repository) CreateTarget(ctx context.Context, target Target, opt ...Opt
|
|||||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to get oplog wrapper"))
|
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to get oplog wrapper"))
|
||||||
}
|
}
|
||||||
|
|
||||||
newHostSets := make([]interface{}, 0, len(opts.WithHostSources))
|
|
||||||
for _, hsId := range opts.WithHostSources {
|
|
||||||
hostSet, err := NewTargetHostSet(t.GetPublicId(), hsId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory target host set"))
|
|
||||||
}
|
|
||||||
newHostSets = append(newHostSets, hostSet)
|
|
||||||
}
|
|
||||||
|
|
||||||
newCredLibs := make([]interface{}, 0, len(opts.WithCredentialSources))
|
|
||||||
for _, clId := range opts.WithCredentialSources {
|
|
||||||
credLib, err := NewCredentialLibrary(t.GetPublicId(), clId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil, nil, errors.Wrap(ctx, err, op, errors.WithMsg("unable to create in memory target credential library"))
|
|
||||||
}
|
|
||||||
newCredLibs = append(newCredLibs, credLib)
|
|
||||||
}
|
|
||||||
|
|
||||||
metadata := t.Oplog(oplog.OpType_OP_TYPE_CREATE)
|
metadata := t.Oplog(oplog.OpType_OP_TYPE_CREATE)
|
||||||
var returnedTarget interface{}
|
var returnedTarget interface{}
|
||||||
var returnedHostSources []HostSource
|
var returnedHostSources []HostSource
|
||||||
@@ -409,26 +391,6 @@ func (r *Repository) CreateTarget(ctx context.Context, target Target, opt ...Opt
|
|||||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create target"))
|
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to create target"))
|
||||||
}
|
}
|
||||||
msgs = append(msgs, &targetOplogMsg)
|
msgs = append(msgs, &targetOplogMsg)
|
||||||
if len(newHostSets) > 0 {
|
|
||||||
hostSetOplogMsgs := make([]*oplog.Message, 0, len(newHostSets))
|
|
||||||
if err := w.CreateItems(ctx, newHostSets, db.NewOplogMsgs(&hostSetOplogMsgs)); err != nil {
|
|
||||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to add host sets"))
|
|
||||||
}
|
|
||||||
if returnedHostSources, err = fetchHostSources(ctx, read, t.GetPublicId()); err != nil {
|
|
||||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to read host sources"))
|
|
||||||
}
|
|
||||||
msgs = append(msgs, hostSetOplogMsgs...)
|
|
||||||
}
|
|
||||||
if len(newCredLibs) > 0 {
|
|
||||||
credLibOplogMsgs := make([]*oplog.Message, 0, len(newCredLibs))
|
|
||||||
if err := w.CreateItems(ctx, newCredLibs, db.NewOplogMsgs(&credLibOplogMsgs)); err != nil {
|
|
||||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to add credential sources"))
|
|
||||||
}
|
|
||||||
if returnedCredSources, err = fetchCredentialSources(ctx, read, t.GetPublicId()); err != nil {
|
|
||||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to read credential sources"))
|
|
||||||
}
|
|
||||||
msgs = append(msgs, credLibOplogMsgs...)
|
|
||||||
}
|
|
||||||
if err := w.WriteOplogEntryWith(ctx, oplogWrapper, targetTicket, metadata, msgs); err != nil {
|
if err := w.WriteOplogEntryWith(ctx, oplogWrapper, targetTicket, metadata, msgs); err != nil {
|
||||||
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to write oplog"))
|
return errors.Wrap(ctx, err, op, errors.WithMsg("unable to write oplog"))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,60 +72,6 @@ func TestRepository_CreateTarget(t *testing.T) {
|
|||||||
wantCredLibs: []string{},
|
wantCredLibs: []string{},
|
||||||
wantHostSources: []string{},
|
wantHostSources: []string{},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "valid-org-with-host-sets",
|
|
||||||
args: args{
|
|
||||||
target: func() *tcp.Target {
|
|
||||||
target, err := tcp.New(proj.PublicId,
|
|
||||||
target.WithName("valid-org-with-host-sets"),
|
|
||||||
target.WithDescription("valid-org"),
|
|
||||||
target.WithDefaultPort(uint32(22)))
|
|
||||||
require.NoError(t, err)
|
|
||||||
return target
|
|
||||||
}(),
|
|
||||||
opt: []target.Option{target.WithHostSources(sets)},
|
|
||||||
},
|
|
||||||
wantErr: false,
|
|
||||||
wantHostSources: sets,
|
|
||||||
wantCredLibs: []string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "valid-org-with-cred-libs",
|
|
||||||
args: args{
|
|
||||||
target: func() *tcp.Target {
|
|
||||||
target, err := tcp.New(proj.PublicId,
|
|
||||||
target.WithName("valid-org-with-cred-libs"),
|
|
||||||
target.WithDescription("valid-org"),
|
|
||||||
target.WithDefaultPort(uint32(22)))
|
|
||||||
require.NoError(t, err)
|
|
||||||
return target
|
|
||||||
}(),
|
|
||||||
opt: []target.Option{target.WithCredentialSources(clIds)},
|
|
||||||
},
|
|
||||||
wantErr: false,
|
|
||||||
wantCredLibs: clIds,
|
|
||||||
wantHostSources: []string{},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "valid-org-with-cred-libs-and-host-sets",
|
|
||||||
args: args{
|
|
||||||
target: func() *tcp.Target {
|
|
||||||
target, err := tcp.New(proj.PublicId,
|
|
||||||
target.WithName("valid-org-with-cred-libs-and-host-sets"),
|
|
||||||
target.WithDescription("valid-org"),
|
|
||||||
target.WithDefaultPort(uint32(22)))
|
|
||||||
require.NoError(t, err)
|
|
||||||
return target
|
|
||||||
}(),
|
|
||||||
opt: []target.Option{
|
|
||||||
target.WithHostSources(sets),
|
|
||||||
target.WithCredentialSources(clIds),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
wantErr: false,
|
|
||||||
wantCredLibs: clIds,
|
|
||||||
wantHostSources: sets,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "nil-target",
|
name: "nil-target",
|
||||||
args: args{
|
args: args{
|
||||||
|
|||||||
Reference in new issue
Block a user