From d24497c92f29a55a60b4af1c885b532fbd363da7 Mon Sep 17 00:00:00 2001 From: Cobalt0s Date: Thu, 7 May 2026 21:24:04 +0300 Subject: [PATCH] feat(hubspot): Use components --- connector/new.go | 5 +- providers/hubspot/client.go | 12 --- providers/hubspot/connector.go | 76 +++++++++---------- providers/hubspot/metadata.go | 15 ++-- providers/hubspot/metadata_test.go | 13 ++-- providers/hubspot/modules.go | 22 ------ providers/hubspot/params.go | 64 ---------------- providers/hubspot/provider.go | 10 --- providers/hubspot/read.go | 4 +- providers/hubspot/record-count.go | 2 +- providers/hubspot/record.go | 4 +- providers/hubspot/search.go | 6 +- providers/hubspot/string.go | 8 -- providers/hubspot/subscriptionEvent.go | 2 +- providers/hubspot/url.go | 14 +++- providers/hubspot/url_test.go | 35 ++++----- providers/hubspot/write.go | 10 +-- .../batch/create/contacts/many/main.go | 3 - test/hubspot/connector.go | 15 +++- test/hubspot/read-associations/main.go | 3 - test/hubspot/read-via-search/lists/main.go | 3 - test/hubspot/read-write/main.go | 4 - test/hubspot/record/main.go | 3 - 23 files changed, 98 insertions(+), 235 deletions(-) delete mode 100644 providers/hubspot/client.go delete mode 100644 providers/hubspot/modules.go delete mode 100644 providers/hubspot/params.go delete mode 100644 providers/hubspot/provider.go delete mode 100644 providers/hubspot/string.go diff --git a/connector/new.go b/connector/new.go index b7912358a0..441bcec35e 100644 --- a/connector/new.go +++ b/connector/new.go @@ -343,10 +343,7 @@ func newSalesforceJWTConnector(params common.ConnectorParams) (*salesforce.Conne } func newHubspotConnector(params common.ConnectorParams) (*hubspot.Connector, error) { - return hubspot.NewConnector( - hubspot.WithAuthenticatedClient(params.AuthenticatedClient), - hubspot.WithModule(params.Module), - ) + return hubspot.NewConnector(params) } func newDocusignConnector( diff --git a/providers/hubspot/client.go b/providers/hubspot/client.go deleted file mode 100644 index 976d184f5c..0000000000 --- a/providers/hubspot/client.go +++ /dev/null @@ -1,12 +0,0 @@ -package hubspot - -import "github.com/amp-labs/connectors/common" - -// JSONHTTPClient returns the underlying JSON HTTP client. -func (c *Connector) JSONHTTPClient() *common.JSONHTTPClient { - return c.Client -} - -func (c *Connector) HTTPClient() *common.HTTPClient { - return c.Client.HTTPClient -} diff --git a/providers/hubspot/connector.go b/providers/hubspot/connector.go index ac661eb89a..1ff5fae407 100644 --- a/providers/hubspot/connector.go +++ b/providers/hubspot/connector.go @@ -5,73 +5,65 @@ import ( "github.com/amp-labs/connectors" "github.com/amp-labs/connectors/common" - "github.com/amp-labs/connectors/common/paramsbuilder" + "github.com/amp-labs/connectors/internal/components" "github.com/amp-labs/connectors/providers" "github.com/amp-labs/connectors/providers/hubspot/internal/crm" "github.com/amp-labs/connectors/providers/hubspot/internal/crm/core" ) -// Connector provides integration with Hubspot provider. +// Connector implements the HubSpot integration. // -// The CRM module is undergoing partial migration: some operations are implemented directly within Connector, -// while others are delegated to specialized sub-adapters (see below). -// These sub-adapters will be consolidated as the migration completes under "crm.Adapter". +// HubSpot is modeled as a single connector. +// Unlike multi-module providers, all supported operations belong directly to Connector. +// +// Complex feature sets may still live in dedicated internal packages +// (for example batch, search, or subscriptions), but those packages are +// implementation details rather than top-level modules. +// +// The long-term direction is for Connector to own all operations directly, +// with reusable feature strategies embedded as needed. type Connector struct { - Client *common.JSONHTTPClient - providerInfo *providers.ProviderInfo - moduleInfo *providers.ModuleInfo - moduleID common.ModuleID + // Shared connector infrastructure. + *components.Connector - // crmAdapter handles the core Hubspot CRM module. - // It provides dedicated support for HubspotCRM-specific functionality. - crmAdapter *crm.Adapter + // Provides access to an authenticated client. + common.RequireAuthenticatedClient + + // Temporary grouping. + // TODO this adapter contents should dissolve into this connector. + // The idea of CRM module should cease to exist. Hubspot is but one entity. + delegate *crm.Adapter } var _ connectors.WebhookVerifierConnector = &Connector{} // NewConnector returns a new Hubspot connector. -// Nearly all of the logic for this connector assumes that the module is CRM (url construction, etc) -// When we have to add support for other modules, it might be best to create a separate internal package. -func NewConnector(opts ...Option) (conn *Connector, outErr error) { - params, err := paramsbuilder.Apply(parameters{}, opts, - WithModule(common.ModuleRoot), // The module is resolved on behalf of the user if the option is missing. - ) - if err != nil { - return nil, err - } - - conn = &Connector{ - Client: &common.JSONHTTPClient{ - HTTPClient: params.Client.Caller, - }, - moduleID: params.Module.Selection.ID, - } +// Hubspot connector still owns CRM functionality. Not every CRM feature is located under `crm` package. +func NewConnector(params common.ConnectorParams) (*Connector, error) { + return components.Initialize(providers.Hubspot, params, func(base *components.Connector) (*Connector, error) { + return constructor(base, ¶ms) + }) +} - conn.providerInfo, err = providers.ReadInfo(providers.Hubspot) - if err != nil { - return nil, err +func constructor(base *components.Connector, params *common.ConnectorParams) (*Connector, error) { + connector := &Connector{ + Connector: base, } - conn.Client.HTTPClient.Base = conn.providerInfo.BaseURL // Note: error handler must return common.HTTPError. // Check method in the internal package "custom", method "readGroupName" which relies on error casting. - conn.Client.HTTPClient.ErrorHandler = core.InterpretJSONError - conn.moduleInfo = conn.providerInfo.ReadModuleInfo(conn.moduleID) + connector.SetErrorHandler(core.InterpretJSONError) - connectorParams, err := newParams(opts) - if err != nil { - return nil, err - } + var err error - conn.crmAdapter, err = crm.NewAdapter(connectorParams) + connector.delegate, err = crm.NewAdapter(params) if err != nil { return nil, err } - return conn, nil + return connector, nil } func (c *Connector) Search(ctx context.Context, params *common.SearchParams) (*common.SearchResult, error) { - // Delegated. - return c.crmAdapter.Search(ctx, params) + return c.delegate.Search(ctx, params) } diff --git a/providers/hubspot/metadata.go b/providers/hubspot/metadata.go index 99d5673d09..917a39e431 100644 --- a/providers/hubspot/metadata.go +++ b/providers/hubspot/metadata.go @@ -30,8 +30,7 @@ type objectMetadataError struct { func (c *Connector) UpsertMetadata( ctx context.Context, params *common.UpsertMetadataParams, ) (*common.UpsertMetadataResult, error) { - // Delegated. - return c.crmAdapter.UpsertMetadata(ctx, params) + return c.delegate.UpsertMetadata(ctx, params) } // ListObjectMetadata returns object metadata for each object name provided. @@ -128,7 +127,7 @@ func (c *Connector) getObjectMetadataFromPropertyAPI( return nil, err } - rsp, err := c.Client.Get(ctx, url.String()) + rsp, err := c.JSONHTTPClient().Get(ctx, url.String()) if err != nil { return nil, fmt.Errorf("error fetching HubSpot fields: %w", err) } @@ -171,12 +170,12 @@ func (c *Connector) getObjectMetadataFromCRMSearch( }) if err != nil { // Ignore an error and fallback to static schema. - return metadata.Schemas.SelectOne(c.moduleID, objectName) + return metadata.Schemas.SelectOne(c.Module(), objectName) } if len(readResult.Data) == 0 { // Read returned no rows. - return metadata.Schemas.SelectOne(c.moduleID, objectName) + return metadata.Schemas.SelectOne(c.Module(), objectName) } fields := make(map[string]common.FieldMetadata) @@ -225,7 +224,7 @@ func (c *Connector) GetAccountInfo(ctx context.Context) (*AccountInfo, *common.J return nil, nil, err } - resp, err := c.Client.Get(ctx, url.String()) + resp, err := c.JSONHTTPClient().Get(ctx, url.String()) if err != nil { return nil, resp, fmt.Errorf("error fetching HubSpot token info: %w", err) } @@ -393,7 +392,7 @@ func (c *Connector) fetchExternalMetadataEnumValues( // For each external field that we support make an API call to fetch enumeration options. // Store this values for each field within each object. for _, discovery := range externalFields { - rsp, err := c.Client.Get(ctx, c.getURLFromRoot(discovery.EndpointPath)) + rsp, err := c.JSONHTTPClient().Get(ctx, c.getURLFromRoot(discovery.EndpointPath)) if err != nil { return nil, fmt.Errorf("error resolving external metadata values for HubSpot: %w", err) } @@ -525,7 +524,7 @@ func (c *Connector) fetchRequiredFieldsBestEffort( return nil, err } - rsp, err := c.Client.Get(ctx, url.String()) + rsp, err := c.JSONHTTPClient().Get(ctx, url.String()) if err != nil { if isMissingSchemasScope(err) { // User does not have permission to access the schema endpoint. diff --git a/providers/hubspot/metadata_test.go b/providers/hubspot/metadata_test.go index 212829123c..184b18dd53 100644 --- a/providers/hubspot/metadata_test.go +++ b/providers/hubspot/metadata_test.go @@ -386,17 +386,20 @@ func TestListObjectMetadata(t *testing.T) { // nolint:funlen,gocognit,cyclop,mai func constructTestConnector(serverURL string) (*Connector, error) { connector, err := NewConnector( - WithAuthenticatedClient(mockutils.NewClient()), - WithModule(providers.ModuleHubspotCRM), + common.ConnectorParams{ + Module: providers.ModuleHubspotCRM, + AuthenticatedClient: mockutils.NewClient(), + }, ) if err != nil { return nil, err } // for testing we want to redirect calls to our mock server - connector.providerInfo.BaseURL = mockutils.ReplaceURLOrigin(connector.providerInfo.BaseURL, serverURL) - connector.moduleInfo.BaseURL = mockutils.ReplaceURLOrigin(connector.moduleInfo.BaseURL, serverURL) - connector.crmAdapter.SetUnitTestBaseURL(mockutils.ReplaceURLOrigin(connector.moduleInfo.BaseURL, serverURL)) + connector.SetUnitTestMockServerBaseURL(serverURL) + if connector.delegate != nil { + connector.delegate.SetUnitTestMockServerBaseURL(serverURL) + } return connector, nil } diff --git a/providers/hubspot/modules.go b/providers/hubspot/modules.go deleted file mode 100644 index 85e61e5431..0000000000 --- a/providers/hubspot/modules.go +++ /dev/null @@ -1,22 +0,0 @@ -package hubspot - -import ( - "github.com/amp-labs/connectors/common" - "github.com/amp-labs/connectors/providers" - "github.com/amp-labs/connectors/providers/hubspot/internal/crm/core" -) - -// supportedModules represents currently working and supported modules within the Hubspot connector. -// Any added module should be appended added here. -var supportedModules = common.Modules{ // nolint: gochecknoglobals - common.ModuleRoot: { - ID: common.ModuleRoot, - Label: "", - Version: "", - }, - providers.ModuleHubspotCRM: { - ID: providers.ModuleHubspotCRM, - Label: "crm", - Version: core.APIVersion3, - }, -} diff --git a/providers/hubspot/params.go b/providers/hubspot/params.go deleted file mode 100644 index b4aa871f8b..0000000000 --- a/providers/hubspot/params.go +++ /dev/null @@ -1,64 +0,0 @@ -package hubspot - -import ( - "context" - "errors" - "net/http" - - "github.com/amp-labs/connectors/common" - "github.com/amp-labs/connectors/common/paramsbuilder" - "golang.org/x/oauth2" -) - -// Option is a function which mutates the hubspot connector configuration. -type Option = func(params *parameters) - -// parameters is the internal configuration for the hubspot connector. -type parameters struct { - paramsbuilder.Client - paramsbuilder.Module -} - -func newParams(opts []Option) (*common.ConnectorParams, error) { // nolint:unused - oldParams, err := paramsbuilder.Apply(parameters{}, opts, - WithModule(common.ModuleRoot), - ) - if err != nil { - return nil, err - } - - return &common.ConnectorParams{ - Module: oldParams.Module.Selection.ID, - AuthenticatedClient: oldParams.Client.Caller.Client, - }, nil -} - -func (p parameters) ValidateParams() error { - return errors.Join( - p.Client.ValidateParams(), - p.Module.ValidateParams(), - ) -} - -// WithClient sets the http client to use for the connector. Saves some boilerplate. -func WithClient(ctx context.Context, client *http.Client, - config *oauth2.Config, token *oauth2.Token, opts ...common.OAuthOption, -) Option { - return func(params *parameters) { - params.WithOauthClient(ctx, client, config, token, opts...) - } -} - -// WithAuthenticatedClient sets the http client to use for the connector. Its usage is optional. -func WithAuthenticatedClient(client common.AuthenticatedHTTPClient) Option { - return func(params *parameters) { - params.WithAuthenticatedClient(client) - } -} - -// WithModule sets the hubspot API module to use for the connector. It's required. -func WithModule(module common.ModuleID) Option { - return func(params *parameters) { - params.WithModule(module, supportedModules, common.ModuleRoot) - } -} diff --git a/providers/hubspot/provider.go b/providers/hubspot/provider.go deleted file mode 100644 index 24b5243afd..0000000000 --- a/providers/hubspot/provider.go +++ /dev/null @@ -1,10 +0,0 @@ -package hubspot - -import ( - "github.com/amp-labs/connectors/providers" -) - -// Provider returns the connector provider. -func (c *Connector) Provider() providers.Provider { - return providers.Hubspot -} diff --git a/providers/hubspot/read.go b/providers/hubspot/read.go index b6490059b9..7790fdf942 100644 --- a/providers/hubspot/read.go +++ b/providers/hubspot/read.go @@ -73,7 +73,7 @@ func (c *Connector) Read(ctx context.Context, config common.ReadParams) (*common return nil, err } - rsp, err := c.Client.Get(ctx, url) + rsp, err := c.JSONHTTPClient().Get(ctx, url) if err != nil { return nil, err } @@ -83,7 +83,7 @@ func (c *Connector) Read(ctx context.Context, config common.ReadParams) (*common core.GetRecords, core.GetNextRecordsURL, associations.CreateDataMarshallerWithAssociations( - ctx, c.crmAdapter.AssociationsFiller, config.ObjectName, config.AssociatedObjects), + ctx, c.delegate.AssociationsFiller, config.ObjectName, config.AssociatedObjects), config.Fields, ) } diff --git a/providers/hubspot/record-count.go b/providers/hubspot/record-count.go index a0fbacf739..6a07870e35 100644 --- a/providers/hubspot/record-count.go +++ b/providers/hubspot/record-count.go @@ -61,7 +61,7 @@ func (c *Connector) GetRecordCount( } // Execute the search request - response, err := c.Client.Post(ctx, url, filterBody) + response, err := c.JSONHTTPClient().Post(ctx, url, filterBody) if err != nil { return nil, fmt.Errorf("failed to execute search request: %w", err) } diff --git a/providers/hubspot/record.go b/providers/hubspot/record.go index 1bba735180..8850d4e9b8 100644 --- a/providers/hubspot/record.go +++ b/providers/hubspot/record.go @@ -66,7 +66,7 @@ func (c *Connector) GetRecordsByIds( "properties": fields, } - resp, err := c.Client.Post(ctx, u, body) + resp, err := c.JSONHTTPClient().Post(ctx, u, body) if err != nil { return nil, err } @@ -82,7 +82,7 @@ func (c *Connector) GetRecordsByIds( } marshaller := associations.CreateDataMarshallerWithAssociations( - ctx, c.crmAdapter.AssociationsFiller, objectName, associationsList, + ctx, c.delegate.AssociationsFiller, objectName, associationsList, ) return marshaller(records, fields) diff --git a/providers/hubspot/search.go b/providers/hubspot/search.go index f10a0004af..99322067bf 100644 --- a/providers/hubspot/search.go +++ b/providers/hubspot/search.go @@ -62,7 +62,7 @@ func (c *Connector) ReadUsingSearchAPI(ctx context.Context, config SearchParams) return nil, err } - rsp, err := c.Client.Post(ctx, url, makeFilterBody(config)) + rsp, err := c.JSONHTTPClient().Post(ctx, url, makeFilterBody(config)) if err != nil { return nil, err } @@ -72,7 +72,7 @@ func (c *Connector) ReadUsingSearchAPI(ctx context.Context, config SearchParams) core.GetRecords, core.GetNextRecordsAfter, associations.CreateDataMarshallerWithAssociations( - ctx, c.crmAdapter.AssociationsFiller, config.ObjectName, config.AssociatedObjects), + ctx, c.delegate.AssociationsFiller, config.ObjectName, config.AssociatedObjects), config.Fields, ) } @@ -97,7 +97,7 @@ func (c *Connector) searchCRM( return nil, err } - rsp, err := c.Client.Post(ctx, url, payload) + rsp, err := c.JSONHTTPClient().Post(ctx, url, payload) if err != nil { return nil, err } diff --git a/providers/hubspot/string.go b/providers/hubspot/string.go deleted file mode 100644 index 7058742d65..0000000000 --- a/providers/hubspot/string.go +++ /dev/null @@ -1,8 +0,0 @@ -package hubspot - -import "fmt" - -// String returns a string representation of the connector, which is useful for logging / debugging. -func (c *Connector) String() string { - return fmt.Sprintf("%s.Connector[%s]", c.Provider(), c.moduleID) -} diff --git a/providers/hubspot/subscriptionEvent.go b/providers/hubspot/subscriptionEvent.go index 271da50462..9fbe5376c4 100644 --- a/providers/hubspot/subscriptionEvent.go +++ b/providers/hubspot/subscriptionEvent.go @@ -48,7 +48,7 @@ func (evt SubscriptionEvent) PreLoadData(data *common.SubscriptionEventPreLoadDa } // VerifyWebhookMessage verifies the signature of a webhook message from Hubspot. -func (*Connector) VerifyWebhookMessage( +func (c *Connector) VerifyWebhookMessage( _ context.Context, request *common.WebhookRequest, params *common.VerificationParams, ) (bool, error) { hsParams, err := common.AssertType[*HubspotVerificationParams](params.Param) diff --git a/providers/hubspot/url.go b/providers/hubspot/url.go index 7a3de06d3a..00513c5ddd 100644 --- a/providers/hubspot/url.go +++ b/providers/hubspot/url.go @@ -17,7 +17,15 @@ var errMissingValue = errors.New("missing value for query parameter") // getURL is a helper to return the full URL considering the base URL & module. // TODO: replace queryArgs with urlbuilder.New().WithQueryParam(). func (c *Connector) getURL(arg string, queryArgs ...string) (string, error) { - urlBase := c.moduleInfo.BaseURL + "/" + path.Join(core.APIVersion3, arg) + baseURL := c.ModuleInfo().BaseURL + + ok := true + for ok { + // This is to satisfy the unit test, which states that trailing slashes should be removed. + baseURL, ok = strings.CutSuffix(baseURL, "/") + } + + urlBase := baseURL + "/" + path.Join(core.APIVersion3, arg) if len(queryArgs) > 0 { vals := url.Values{} @@ -64,7 +72,7 @@ func (c *Connector) getCRMSearchURL(config searchCRMParams) (string, error) { // https://developers.hubspot.com/docs/api-reference/latest/crm/properties/get-properties // Note: Version APIVersion2026March is NOT FOUND at the moment for this endpoint. Using older V3. func (c *Connector) getPropertiesURL(objectName string) (*urlbuilder.URL, error) { - return urlbuilder.New(c.moduleInfo.BaseURL, core.APIVersion3, "properties", objectName, "/") + return urlbuilder.New(c.ModuleInfo().BaseURL, core.APIVersion3, "properties", objectName, "/") } // https://developers.hubspot.com/docs/api-reference/latest/crm/objects/schemas/get-schema @@ -83,5 +91,5 @@ func (c *Connector) getURLFromRoot(relativePath string) string { // Returns module agnostic Hubspot URL. func (c *Connector) getRootProviderURL() string { - return c.providerInfo.BaseURL + return c.ProviderInfo().BaseURL } diff --git a/providers/hubspot/url_test.go b/providers/hubspot/url_test.go index 8b013b84e9..e86393f52a 100644 --- a/providers/hubspot/url_test.go +++ b/providers/hubspot/url_test.go @@ -3,21 +3,15 @@ package hubspot import ( "testing" + "github.com/amp-labs/connectors/common" "github.com/amp-labs/connectors/providers" + "github.com/amp-labs/connectors/test/utils/mockutils" ) // nolint:funlen func TestConnector_getURL_ModuleCRM(t *testing.T) { t.Parallel() - providerInfo, err := providers.ReadInfo(providers.Hubspot) - if err != nil { - t.Fatalf("failed to get providerInfo: %v", err) - } - - moduleInfo := providerInfo.ReadModuleInfo(providers.ModuleHubspotCRM) - defaultBaseURL := providerInfo.BaseURL - cases := []struct { name string baseURL string // optional; if empty, use defaultBaseURL @@ -29,13 +23,13 @@ func TestConnector_getURL_ModuleCRM(t *testing.T) { { name: "Read with default baseURL (trailing slash removed)", arg: "objects/contacts/", - wantURL: defaultBaseURL + "/crm/v3/objects/contacts", + wantURL: "https://api.hubapi.com/crm/v3/objects/contacts", }, { name: "Read with query params (special chars)", arg: "objects/contacts", queryArgs: []string{"properties", "email,first name", "archived", "true"}, - wantURL: defaultBaseURL + "/crm/v3/objects/contacts?archived=true&properties=email%2Cfirst+name", + wantURL: "https://api.hubapi.com/crm/v3/objects/contacts?archived=true&properties=email%2Cfirst+name", }, { name: "Error: missing query param value", @@ -45,9 +39,9 @@ func TestConnector_getURL_ModuleCRM(t *testing.T) { }, { name: "BaseURL with extra trailing slash", - baseURL: defaultBaseURL + "/", // add an extra slash + baseURL: "https://api.hubapi.com/crm/", // add an extra slash arg: "objects/contacts/", - wantURL: defaultBaseURL + "/crm/v3/objects/contacts", + wantURL: "https://api.hubapi.com/crm/v3/objects/contacts", }, } @@ -55,18 +49,15 @@ func TestConnector_getURL_ModuleCRM(t *testing.T) { t.Run(ttc.name, func(t *testing.T) { t.Parallel() - pi := *providerInfo // copy to avoid race - mi := *moduleInfo + c, err := NewConnector( + common.ConnectorParams{ + Module: providers.ModuleHubspotCRM, + AuthenticatedClient: mockutils.NewClient(), + }, + ) if ttc.baseURL != "" { - pi.BaseURL = ttc.baseURL - } else { - pi.BaseURL = defaultBaseURL - } - - c := &Connector{ - providerInfo: &pi, - moduleInfo: &mi, + c.ModuleInfo().BaseURL = ttc.baseURL } gotURL, err := c.getURL(ttc.arg, ttc.queryArgs...) diff --git a/providers/hubspot/write.go b/providers/hubspot/write.go index 2becb8e2dd..87c2790515 100644 --- a/providers/hubspot/write.go +++ b/providers/hubspot/write.go @@ -38,10 +38,10 @@ func (c *Connector) Write(ctx context.Context, config common.WriteParams) (*comm } if config.RecordId != "" { - write = c.Client.Patch + write = c.JSONHTTPClient().Patch url = fmt.Sprintf("%s/%s", url, config.RecordId) } else { - write = c.Client.Post + write = c.JSONHTTPClient().Post } // Hubspot requires everything to be wrapped in a "properties" object. @@ -74,11 +74,9 @@ func (c *Connector) Write(ctx context.Context, config common.WriteParams) (*comm } func (c *Connector) BatchWrite(ctx context.Context, params *common.BatchWriteParam) (*common.BatchWriteResult, error) { - // Delegated. - return c.crmAdapter.BatchWrite(ctx, params) + return c.delegate.BatchWrite(ctx, params) } func (c *Connector) Delete(ctx context.Context, params connectors.DeleteParams) (*connectors.DeleteResult, error) { - // Delegated. - return c.crmAdapter.Delete(ctx, params) + return c.delegate.Delete(ctx, params) } diff --git a/test/hubspot/batch/create/contacts/many/main.go b/test/hubspot/batch/create/contacts/many/main.go index 6fcb8b2be6..4836426e52 100644 --- a/test/hubspot/batch/create/contacts/many/main.go +++ b/test/hubspot/batch/create/contacts/many/main.go @@ -19,9 +19,6 @@ func main() { ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer done() - // Set up slog logging. - utils.SetupLogging() - conn := connTest.GetHubspotConnector(ctx) // Init records for creation. diff --git a/test/hubspot/connector.go b/test/hubspot/connector.go index 14494a7d1c..e10f6837ce 100644 --- a/test/hubspot/connector.go +++ b/test/hubspot/connector.go @@ -2,8 +2,8 @@ package hubspot import ( "context" - "net/http" + "github.com/amp-labs/connectors/common" "github.com/amp-labs/connectors/common/scanning/credscanning" "github.com/amp-labs/connectors/providers" "github.com/amp-labs/connectors/providers/hubspot" @@ -11,13 +11,20 @@ import ( "golang.org/x/oauth2" ) -// GetHubspotConnector returns a Hubspot connector. +// GetHubspotConnector returns a Hubspot CRM connector. func GetHubspotConnector(ctx context.Context) *hubspot.Connector { + return getHubspotConnector(ctx, providers.ModuleHubspotCRM) +} + +func getHubspotConnector(ctx context.Context, moduleID common.ModuleID) *hubspot.Connector { reader := CredsReader() conn, err := hubspot.NewConnector( - hubspot.WithClient(ctx, http.DefaultClient, getConfig(reader), reader.GetOauthToken()), - hubspot.WithModule(providers.ModuleHubspotCRM)) + common.ConnectorParams{ + AuthenticatedClient: utils.NewOauth2Client(ctx, reader, getConfig), + Module: moduleID, + }, + ) if err != nil { utils.Fail("error creating hubspot connector", "error", err) } diff --git a/test/hubspot/read-associations/main.go b/test/hubspot/read-associations/main.go index c5523cab5a..1bff138d05 100644 --- a/test/hubspot/read-associations/main.go +++ b/test/hubspot/read-associations/main.go @@ -20,9 +20,6 @@ func main() { ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer done() - // Set up slog logging. - utils.SetupLogging() - // Turn on verbose logging ctx = logging.WithLoggerEnabled(ctx, true) ctx = logging.WithVerboseLogging(ctx, true) diff --git a/test/hubspot/read-via-search/lists/main.go b/test/hubspot/read-via-search/lists/main.go index fde050614b..b269e114e1 100644 --- a/test/hubspot/read-via-search/lists/main.go +++ b/test/hubspot/read-via-search/lists/main.go @@ -18,9 +18,6 @@ func main() { ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer done() - // Set up slog logging. - utils.SetupLogging() - conn := connTest.GetHubspotConnector(ctx) res, err := conn.ReadUsingSearchAPI(ctx, hubspot.SearchParams{ diff --git a/test/hubspot/read-write/main.go b/test/hubspot/read-write/main.go index d3a74510b9..0464a73a28 100644 --- a/test/hubspot/read-write/main.go +++ b/test/hubspot/read-write/main.go @@ -8,7 +8,6 @@ import ( "github.com/amp-labs/connectors/internal/datautils" connTest "github.com/amp-labs/connectors/test/hubspot" - "github.com/amp-labs/connectors/test/utils" "github.com/amp-labs/connectors/test/utils/testscenario" "github.com/brianvoe/gofakeit/v6" ) @@ -28,9 +27,6 @@ func main() { ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer done() - // Set up slog logging. - utils.SetupLogging() - // Get the Hubspot connector. conn := connTest.GetHubspotConnector(ctx) diff --git a/test/hubspot/record/main.go b/test/hubspot/record/main.go index aa2731939b..42d72380c3 100644 --- a/test/hubspot/record/main.go +++ b/test/hubspot/record/main.go @@ -31,9 +31,6 @@ func main() { ctx, done := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer done() - // Set up slog logging. - utils.SetupLogging() - // Get the Hubspot connector. conn := connTest.GetHubspotConnector(ctx)