Skip to content
This repository has been archived by the owner on Jan 19, 2023. It is now read-only.

Commit

Permalink
Make UUID generation a responsibility of StreamingClientFactory
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Stergianis <[email protected]>
  • Loading branch information
MichaelStergianis authored and wwitzel3 committed Jun 16, 2021
1 parent 863a7a5 commit 4834ebc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
17 changes: 8 additions & 9 deletions pkg/api/fake/mock_client_factory.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions pkg/api/streaming.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
15 changes: 2 additions & 13 deletions pkg/api/streaming_connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/api/websockets/websocket_connection_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4834ebc

Please sign in to comment.