Skip to content

Commit 159e8d6

Browse files
authored
Merge pull request #154 from deploymenttheory/dev
Refactor httpclient/client.go to update AuthMethod and httpClient fields
2 parents 7540214 + 9a1d5c1 commit 159e8d6

File tree

3 files changed

+19
-17
lines changed

3 files changed

+19
-17
lines changed

httpclient/client.go

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@ import (
2222

2323
// Client represents an HTTP client to interact with a specific API.
2424
type Client struct {
25-
InstanceName string // Website Instance name without the root domain
26-
AuthMethod string // Specifies the authentication method: "bearer" or "oauth"
27-
Token string // Authentication Token
28-
OverrideBaseDomain string // Base domain override used when the default in the api handler isn't suitable
29-
Expiry time.Time // Expiry time set for the auth token
30-
httpClient *http.Client
25+
AuthMethod string // Specifies the authentication method: "bearer" or "oauth"
26+
Token string // Authentication Token
27+
Expiry time.Time // Expiry time set for the auth token
28+
httpClient *http.Client // Internal HTTP client
3129
clientConfig ClientConfig
3230
Logger logger.Logger
3331
ConcurrencyHandler *concurrency.ConcurrencyHandler
@@ -52,9 +50,11 @@ type AuthConfig struct {
5250

5351
// EnvironmentConfig represents the structure to read authentication details from a JSON configuration file.
5452
type EnvironmentConfig struct {
55-
InstanceName string `json:"InstanceName,omitempty"`
56-
OverrideBaseDomain string `json:"OverrideBaseDomain,omitempty"`
57-
APIType string `json:"APIType,omitempty"`
53+
APIType string `json:"APIType,omitempty"` // APIType specifies the type of API integration to use
54+
InstanceName string `json:"InstanceName,omitempty"` // Website Instance name without the root domain
55+
OverrideBaseDomain string `json:"OverrideBaseDomain,omitempty"` // Base domain override used when the default in the api handler isn't suitable
56+
TenantID string `json:"TenantID,omitempty"` // TenantID is the unique identifier for the tenant
57+
TenantName string `json:"TenantName,omitempty"` // TenantName is the name of the tenant
5858
}
5959

6060
// ClientOptions holds optional configuration options for the HTTP Client.
@@ -148,10 +148,10 @@ func BuildClient(config ClientConfig) (*Client, error) {
148148

149149
// Create a new HTTP client with the provided configuration.
150150
client := &Client{
151-
APIHandler: apiHandler,
152-
InstanceName: config.Environment.InstanceName,
153-
AuthMethod: authMethod,
154-
OverrideBaseDomain: config.Environment.OverrideBaseDomain,
151+
APIHandler: apiHandler,
152+
//InstanceName: config.Environment.InstanceName,
153+
AuthMethod: authMethod,
154+
//OverrideBaseDomain: config.Environment.OverrideBaseDomain,
155155
httpClient: httpClient,
156156
clientConfig: config,
157157
Logger: log,
@@ -162,8 +162,10 @@ func BuildClient(config ClientConfig) (*Client, error) {
162162
// Log the client's configuration.
163163
log.Info("New API client initialized",
164164
zap.String("API Type", config.Environment.APIType),
165-
zap.String("Instance Name", client.InstanceName),
165+
zap.String("Instance Name", config.Environment.InstanceName),
166166
zap.String("Override Base Domain", config.Environment.OverrideBaseDomain),
167+
zap.String("Tenant ID", config.Environment.TenantID),
168+
zap.String("Tenant Name", config.Environment.TenantName),
167169
zap.String("Authentication Method", authMethod),
168170
zap.String("Logging Level", config.ClientOptions.LogLevel),
169171
zap.String("Log Encoding Format", config.ClientOptions.LogOutputFormat),

httpclient/multipartrequest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func (c *Client) DoMultipartRequest(method, endpoint string, fields map[string]s
6060
}
6161

6262
// Construct URL using the ConstructAPIResourceEndpoint function
63-
url := c.APIHandler.ConstructAPIResourceEndpoint(c.InstanceName, endpoint, log)
63+
url := c.APIHandler.ConstructAPIResourceEndpoint(c.clientConfig.Environment.InstanceName, endpoint, log)
6464

6565
// Create the request
6666
req, err := http.NewRequest(method, url, bytes.NewBuffer(requestData))

httpclient/request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func (c *Client) executeRequestWithRetries(method, endpoint string, body, out in
146146
}
147147

148148
// Construct URL with correct structure defined in api handler
149-
url := c.APIHandler.ConstructAPIResourceEndpoint(c.InstanceName, endpoint, log)
149+
url := c.APIHandler.ConstructAPIResourceEndpoint(c.clientConfig.Environment.InstanceName, endpoint, log)
150150

151151
// Increment total request counter within ConcurrencyHandler's metrics
152152
c.ConcurrencyHandler.Metrics.Lock.Lock()
@@ -312,7 +312,7 @@ func (c *Client) executeRequest(method, endpoint string, body, out interface{})
312312
}
313313

314314
// Construct URL using the ConstructAPIResourceEndpoint function
315-
url := c.APIHandler.ConstructAPIResourceEndpoint(c.InstanceName, endpoint, log)
315+
url := c.APIHandler.ConstructAPIResourceEndpoint(c.clientConfig.Environment.InstanceName, endpoint, log)
316316

317317
// Create a new HTTP request with the provided method, URL, and body
318318
req, err := http.NewRequest(method, url, bytes.NewBuffer(requestData))

0 commit comments

Comments
 (0)