Commit 4834ebc3 authored by Michael Stergianis's avatar Michael Stergianis Committed by Wayne Witzel III
Browse files

Make UUID generation a responsibility of StreamingClientFactory

Signed-off-by: default avatarMichael Stergianis <michaelstergianis@gmail.com>
Showing with 24 additions and 28 deletions
+24 -28
......@@ -10,7 +10,6 @@ import (
reflect "reflect"
gomock "github.com/golang/mock/gomock"
uuid "github.com/google/uuid"
config "github.com/vmware-tanzu/octant/internal/config"
api "github.com/vmware-tanzu/octant/pkg/api"
......@@ -40,9 +39,9 @@ func (m *MockStreamingClientFactory) EXPECT() *MockStreamingClientFactoryMockRec
}
// NewConnection mocks base method
func (m *MockStreamingClientFactory) NewConnection(arg0 uuid.UUID, arg1 http.ResponseWriter, arg2 *http.Request, arg3 api.ClientManager, arg4 config.Dash) (api.StreamingClient, context.CancelFunc, error) {
func (m *MockStreamingClientFactory) NewConnection(arg0 http.ResponseWriter, arg1 *http.Request, arg2 api.ClientManager, arg3 config.Dash) (api.StreamingClient, context.CancelFunc, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewConnection", arg0, arg1, arg2, arg3, arg4)
ret := m.ctrl.Call(m, "NewConnection", arg0, arg1, arg2, arg3)
ret0, _ := ret[0].(api.StreamingClient)
ret1, _ := ret[1].(context.CancelFunc)
ret2, _ := ret[2].(error)
......@@ -50,15 +49,15 @@ func (m *MockStreamingClientFactory) NewConnection(arg0 uuid.UUID, arg1 http.Res
}
// NewConnection indicates an expected call of NewConnection
func (mr *MockStreamingClientFactoryMockRecorder) NewConnection(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call {
func (mr *MockStreamingClientFactoryMockRecorder) NewConnection(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewConnection", reflect.TypeOf((*MockStreamingClientFactory)(nil).NewConnection), arg0, arg1, arg2, arg3, arg4)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewConnection", reflect.TypeOf((*MockStreamingClientFactory)(nil).NewConnection), arg0, arg1, arg2, arg3)
}
// NewTemporaryConnection mocks base method
func (m *MockStreamingClientFactory) NewTemporaryConnection(arg0 uuid.UUID, arg1 http.ResponseWriter, arg2 *http.Request, arg3 api.ClientManager) (api.StreamingClient, context.CancelFunc, error) {
func (m *MockStreamingClientFactory) NewTemporaryConnection(arg0 http.ResponseWriter, arg1 *http.Request, arg2 api.ClientManager) (api.StreamingClient, context.CancelFunc, error) {
m.ctrl.T.Helper()
ret := m.ctrl.Call(m, "NewTemporaryConnection", arg0, arg1, arg2, arg3)
ret := m.ctrl.Call(m, "NewTemporaryConnection", arg0, arg1, arg2)
ret0, _ := ret[0].(api.StreamingClient)
ret1, _ := ret[1].(context.CancelFunc)
ret2, _ := ret[2].(error)
......@@ -66,7 +65,7 @@ func (m *MockStreamingClientFactory) NewTemporaryConnection(arg0 uuid.UUID, arg1
}
// NewTemporaryConnection indicates an expected call of NewTemporaryConnection
func (mr *MockStreamingClientFactoryMockRecorder) NewTemporaryConnection(arg0, arg1, arg2, arg3 interface{}) *gomock.Call {
func (mr *MockStreamingClientFactoryMockRecorder) NewTemporaryConnection(arg0, arg1, arg2 interface{}) *gomock.Call {
mr.mock.ctrl.T.Helper()
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewTemporaryConnection", reflect.TypeOf((*MockStreamingClientFactory)(nil).NewTemporaryConnection), arg0, arg1, arg2, arg3)
return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "NewTemporaryConnection", reflect.TypeOf((*MockStreamingClientFactory)(nil).NewTemporaryConnection), arg0, arg1, arg2)
}
......@@ -8,8 +8,6 @@ import (
"context"
"net/http"
"github.com/google/uuid"
"github.com/vmware-tanzu/octant/internal/config"
"github.com/vmware-tanzu/octant/internal/octant"
"github.com/vmware-tanzu/octant/pkg/action"
......@@ -57,6 +55,6 @@ type StreamingClient interface {
}
type StreamingClientFactory interface {
NewConnection(uuid.UUID, http.ResponseWriter, *http.Request, ClientManager, config.Dash) (StreamingClient, context.CancelFunc, error)
NewTemporaryConnection(uuid.UUID, http.ResponseWriter, *http.Request, ClientManager) (StreamingClient, context.CancelFunc, error)
NewConnection(http.ResponseWriter, *http.Request, ClientManager, config.Dash) (StreamingClient, context.CancelFunc, error)
NewTemporaryConnection(http.ResponseWriter, *http.Request, ClientManager) (StreamingClient, context.CancelFunc, error)
}
......@@ -8,8 +8,6 @@ import (
"context"
"net/http"
"github.com/google/uuid"
"github.com/vmware-tanzu/octant/internal/config"
"github.com/vmware-tanzu/octant/pkg/event"
)
......@@ -87,12 +85,8 @@ func (m *StreamingConnectionManager) Run(ctx context.Context) {
// ClientFromRequest creates a websocket client from a http request.
func (m *StreamingConnectionManager) ClientFromRequest(dashConfig config.Dash, w http.ResponseWriter, r *http.Request) (StreamingClient, error) {
clientID, err := uuid.NewUUID()
if err != nil {
return nil, err
}
client, cancel, err := m.clientFactory.NewConnection(clientID, w, r, m, dashConfig)
client, cancel, err := m.clientFactory.NewConnection(w, r, m, dashConfig)
if err != nil {
return nil, err
}
......@@ -108,12 +102,7 @@ func (m *StreamingConnectionManager) ClientFromRequest(dashConfig config.Dash, w
}
func (m *StreamingConnectionManager) TemporaryClientFromLoadingRequest(w http.ResponseWriter, r *http.Request) (StreamingClient, error) {
clientID, err := uuid.NewUUID()
if err != nil {
return nil, err
}
client, cancel, err := m.clientFactory.NewTemporaryConnection(clientID, w, r, m)
client, cancel, err := m.clientFactory.NewTemporaryConnection(w, r, m)
if err != nil {
return nil, err
}
......
......@@ -37,8 +37,13 @@ func NewWebsocketConnectionFactory() *WebsocketConnectionFactory {
var _ api.StreamingClientFactory = (*WebsocketConnectionFactory)(nil)
func (wcf *WebsocketConnectionFactory) NewConnection(
clientID uuid.UUID, w http.ResponseWriter, r *http.Request, m api.ClientManager, dashConfig config.Dash,
w http.ResponseWriter, r *http.Request, m api.ClientManager, dashConfig config.Dash,
) (api.StreamingClient, context.CancelFunc, error) {
clientID, err := uuid.NewUUID()
if err != nil {
return nil, nil, err
}
conn, err := wcf.upgrader.Upgrade(w, r, nil)
if err != nil {
return nil, nil, err
......@@ -54,8 +59,13 @@ func (wcf *WebsocketConnectionFactory) NewConnection(
}
func (wcf *WebsocketConnectionFactory) NewTemporaryConnection(
clientID uuid.UUID, w http.ResponseWriter, r *http.Request, m api.ClientManager,
w http.ResponseWriter, r *http.Request, m api.ClientManager,
) (api.StreamingClient, context.CancelFunc, error) {
clientID, err := uuid.NewUUID()
if err != nil {
return nil, nil, err
}
conn, err := wcf.upgrader.Upgrade(w, r, nil)
if err != nil {
return nil, nil, err
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment