From 8a0fad125982c4107180ca66d4bb289065eeaa75 Mon Sep 17 00:00:00 2001 From: Jim Lambert Date: Tue, 8 Sep 2020 16:38:15 -0400 Subject: [PATCH] refactor session ServerId and ServerType NOT be included/required for the creation of a session --- internal/db/migrations/postgres.gen.go | 2 -- .../db/migrations/postgres/50_session.up.sql | 2 -- internal/session/session.go | 11 -------- internal/session/session_test.go | 26 ------------------- internal/session/testing.go | 24 ----------------- 5 files changed, 65 deletions(-) diff --git a/internal/db/migrations/postgres.gen.go b/internal/db/migrations/postgres.gen.go index 2f12efa360..0eadc55b66 100644 --- a/internal/db/migrations/postgres.gen.go +++ b/internal/db/migrations/postgres.gen.go @@ -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 diff --git a/internal/db/migrations/postgres/50_session.up.sql b/internal/db/migrations/postgres/50_session.up.sql index 046a64bdb5..bc624329d3 100644 --- a/internal/db/migrations/postgres/50_session.up.sql +++ b/internal/db/migrations/postgres/50_session.up.sql @@ -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 diff --git a/internal/session/session.go b/internal/session/session.go index 77e1ca47e4..becb8fd50a 100644 --- a/internal/session/session.go +++ b/internal/session/session.go @@ -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) } diff --git a/internal/session/session_test.go b/internal/session/session_test.go index 8a769a4d75..283ebe51b0 100644 --- a/internal/session/session_test.go +++ b/internal/session/session_test.go @@ -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{ diff --git a/internal/session/testing.go b/internal/session/testing.go index 55e0ca8c6e..8cd157a9af 100644 --- a/internal/session/testing.go +++ b/internal/session/testing.go @@ -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 -}