refactor session ServerId and ServerType NOT be included/required for the creation of a session

pull/347/head
Jim Lambert 6 years ago
parent 83f1fbacf0
commit 8a0fad1259

@ -3464,8 +3464,6 @@ begin;
raise exception 'user_id is null';
when new.host_id is null then
raise exception 'host_id is null';
when new.server_id is null then
raise exception 'server_id is null';
when new.target_id is null then
raise exception 'target_id is null';
when new.set_id is null then

@ -202,8 +202,6 @@ begin;
raise exception 'user_id is null';
when new.host_id is null then
raise exception 'host_id is null';
when new.server_id is null then
raise exception 'server_id is null';
when new.target_id is null then
raise exception 'target_id is null';
when new.set_id is null then

@ -8,7 +8,6 @@ import (
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/oplog"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/session/store"
"google.golang.org/protobuf/proto"
)
@ -20,8 +19,6 @@ const (
type ComposedOf struct {
UserId string
HostId string
ServerId string
ServerType servers.ServerType
TargetId string
HostSetId string
AuthTokenId string
@ -44,8 +41,6 @@ func New(c ComposedOf, opt ...Option) (*Session, error) {
Session: &store.Session{
UserId: c.UserId,
HostId: c.HostId,
ServerId: c.ServerId,
ServerType: c.ServerType.String(),
TargetId: c.TargetId,
SetId: c.HostSetId,
AuthTokenId: c.AuthTokenId,
@ -141,12 +136,6 @@ func (s *Session) validateNewSession(errorPrefix string) error {
if s.HostId == "" {
return fmt.Errorf("%s missing host id: %w", errorPrefix, db.ErrInvalidParameter)
}
if s.ServerId == "" {
return fmt.Errorf("%s missing server id: %w", errorPrefix, db.ErrInvalidParameter)
}
if s.ServerType == "" {
return fmt.Errorf("%s missing server type: %w", errorPrefix, db.ErrInvalidParameter)
}
if s.TargetId == "" {
return fmt.Errorf("%s missing target id: %w", errorPrefix, db.ErrInvalidParameter)
}

@ -42,8 +42,6 @@ func TestSession_Create(t *testing.T) {
Session: &store.Session{
UserId: composedOf.UserId,
HostId: composedOf.HostId,
ServerId: composedOf.ServerId,
ServerType: composedOf.ServerType.String(),
TargetId: composedOf.TargetId,
SetId: composedOf.HostSetId,
AuthTokenId: composedOf.AuthTokenId,
@ -78,30 +76,6 @@ func TestSession_Create(t *testing.T) {
wantErr: true,
wantIsErr: db.ErrInvalidParameter,
},
{
name: "empty-serverId",
args: args{
composedOf: func() ComposedOf {
c := composedOf
c.ServerId = ""
return c
}(),
},
wantErr: true,
wantIsErr: db.ErrInvalidParameter,
},
{
name: "empty-serverType",
args: args{
composedOf: func() ComposedOf {
c := composedOf
c.ServerType = ""
return c
}(),
},
wantErr: true,
wantIsErr: db.ErrInvalidParameter,
},
{
name: "empty-targetId",
args: args{

@ -10,10 +10,8 @@ import (
"github.com/hashicorp/boundary/internal/host/static"
"github.com/hashicorp/boundary/internal/iam"
"github.com/hashicorp/boundary/internal/kms"
"github.com/hashicorp/boundary/internal/servers"
"github.com/hashicorp/boundary/internal/target"
wrapping "github.com/hashicorp/go-kms-wrapping"
"github.com/hashicorp/go-uuid"
"github.com/jinzhu/gorm"
"github.com/stretchr/testify/require"
)
@ -82,24 +80,9 @@ func TestSessionParams(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, ia
at, err := authTokenRepo.CreateAuthToken(ctx, user, acct.GetPublicId())
require.NoError(err)
serversRepo, err := servers.NewRepository(rw, rw, kms)
require.NoError(err)
id := testId(t)
worker := &servers.Server{
PrivateId: "test-session-worker-" + id,
Name: "test-session-worker-" + id,
Type: servers.ServerTypeWorker.String(),
Description: "Test Session Worker",
Address: "127.0.0.1",
}
_, _, err = serversRepo.UpsertServer(ctx, worker)
require.NoError(err)
return ComposedOf{
UserId: user.PublicId,
HostId: hosts[0].PublicId,
ServerId: worker.PrivateId,
ServerType: servers.ServerTypeWorker,
TargetId: tcpTarget.PublicId,
HostSetId: sets[0].PublicId,
AuthTokenId: at.PublicId,
@ -108,10 +91,3 @@ func TestSessionParams(t *testing.T, conn *gorm.DB, wrapper wrapping.Wrapper, ia
Port: "22",
}
}
func testId(t *testing.T) string {
t.Helper()
id, err := uuid.GenerateUUID()
require.NoError(t, err)
return id
}

Loading…
Cancel
Save