From 164af703c68dfd04ac200cf015347c69be9da5b1 Mon Sep 17 00:00:00 2001 From: Derek Horton Date: Fri, 3 Nov 2023 11:54:49 -0500 Subject: [PATCH] Refactoring...still thinking --- .../controller/api/connection_mediator_v2.go | 2 +- internal/controller/api/message_receiver_test.go | 2 +- internal/controller/api/utils.go | 2 +- internal/controller/types.go | 2 +- internal/mqtt/connector_client_proxy_factory.go | 16 ++++++++-------- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/internal/controller/api/connection_mediator_v2.go b/internal/controller/api/connection_mediator_v2.go index 7e93e29f..a0a53340 100644 --- a/internal/controller/api/connection_mediator_v2.go +++ b/internal/controller/api/connection_mediator_v2.go @@ -119,7 +119,7 @@ func (this *ConnectionMediatorV2) handleSendMessage() http.HandlerFunc { return } - client, err := this.proxyFactory.CreateProxy(req.Context(), clientState.OrgID, clientState.Account, clientState.ClientID, clientState.CanonicalFacts, clientState.Dispatchers, clientState.Tags) + client, err := this.proxyFactory.CreateProxy(req.Context(), clientState) if err != nil { logging.LogWithError(logger, "Unable to create proxy for connection", err) writeConnectionFailureResponse(logger, w) diff --git a/internal/controller/api/message_receiver_test.go b/internal/controller/api/message_receiver_test.go index 7a955820..a5e3e042 100644 --- a/internal/controller/api/message_receiver_test.go +++ b/internal/controller/api/message_receiver_test.go @@ -37,7 +37,7 @@ const ( type MockClientProxyFactory struct { } -func (MockClientProxyFactory) CreateProxy(context.Context, domain.OrgID, domain.AccountID, domain.ClientID, domain.CanonicalFacts, domain.Dispatchers, domain.Tags) (controller.ConnectorClient, error) { +func (MockClientProxyFactory) CreateProxy(context.Context, domain.ConnectorClientState) (controller.ConnectorClient, error) { return MockClient{}, nil } diff --git a/internal/controller/api/utils.go b/internal/controller/api/utils.go index f4d9b023..910c1c03 100644 --- a/internal/controller/api/utils.go +++ b/internal/controller/api/utils.go @@ -132,7 +132,7 @@ func createConnectorClientProxy(ctx context.Context, log *logrus.Entry, tenantTr return nil, err } - proxy, err := proxyFactory.CreateProxy(ctx, clientState.OrgID, clientState.Account, clientState.ClientID, clientState.CanonicalFacts, clientState.Dispatchers, clientState.Tags) + proxy, err := proxyFactory.CreateProxy(ctx, clientState) if err != nil { log.WithFields(logrus.Fields{"error": err}).Errorf("Unable to create proxy for connection (%s:%s)", resolvedOrgId, clientId) return nil, err diff --git a/internal/controller/types.go b/internal/controller/types.go index 3a03dcca..26cd460c 100644 --- a/internal/controller/types.go +++ b/internal/controller/types.go @@ -25,5 +25,5 @@ type ConnectorClient interface { } type ConnectorClientProxyFactory interface { - CreateProxy(context.Context, domain.OrgID, domain.AccountID, domain.ClientID, domain.CanonicalFacts, domain.Dispatchers, domain.Tags) (ConnectorClient, error) + CreateProxy(context.Context, domain.ConnectorClientState) (ConnectorClient, error) } diff --git a/internal/mqtt/connector_client_proxy_factory.go b/internal/mqtt/connector_client_proxy_factory.go index 080274f8..ddcc1757 100644 --- a/internal/mqtt/connector_client_proxy_factory.go +++ b/internal/mqtt/connector_client_proxy_factory.go @@ -23,21 +23,21 @@ func NewConnectorClientMQTTProxyFactory(cfg *config.Config, mqttClient MQTT.Clie return &proxyFactory, nil } -func (ccpf *ConnectorClientMQTTProxyFactory) CreateProxy(ctx context.Context, orgID domain.OrgID, account domain.AccountID, client_id domain.ClientID, canonicalFacts domain.CanonicalFacts, dispatchers domain.Dispatchers, tags domain.Tags) (controller.ConnectorClient, error) { +func (ccpf *ConnectorClientMQTTProxyFactory) CreateProxy(ctx context.Context, clientState domain.ConnectorClientState) (controller.ConnectorClient, error) { - logger := logger.Log.WithFields(logrus.Fields{"org_id": orgID, "account": account, "client_id": client_id}) + logger := logger.Log.WithFields(logrus.Fields{"org_id": clientState.OrgID, "account": clientState.Account, "client_id": clientState.ClientID}) proxy := ConnectorClientMQTTProxy{ Logger: logger, Config: ccpf.config, - OrgID: orgID, - AccountID: account, - ClientID: client_id, + OrgID: clientState.OrgID, + AccountID: clientState.Account, + ClientID: clientState.ClientID, Client: ccpf.mqttClient, TopicBuilder: ccpf.topicBuilder, - CanonicalFacts: canonicalFacts, - Dispatchers: dispatchers, - Tags: tags, + CanonicalFacts: clientState.CanonicalFacts, + Dispatchers: clientState.Dispatchers, + Tags: clientState.Tags, } return &proxy, nil