Skip to content

Commit 0296430

Browse files
authored
Merge pull request #155 from deploymenttheory/dev
Refactor GraphAPIHandler in msgraph_api_handler.go and msgraph_api_ur…
2 parents 159e8d6 + 96bd7ee commit 0296430

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

apiintegrations/msgraph/msgraph_api_handler.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import "github.com/deploymenttheory/go-api-http-client/logger"
66
// GraphAPIHandler implements the APIHandler interface for the graph Pro API.
77
type GraphAPIHandler struct {
88
OverrideBaseDomain string // OverrideBaseDomain is used to override the base domain for URL construction.
9-
InstanceName string // InstanceName is the name of the graph instance.
9+
TenantID string // TenantID used for constructing the authentication endpoint.
10+
TenantName string // TenantName used for constructing the authentication endpoint.
1011
Logger logger.Logger // Logger is the structured logger used for logging.
1112
}

apiintegrations/msgraph/msgraph_api_url.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,24 @@ func (g *GraphAPIHandler) SetBaseDomain() string {
1818
}
1919

2020
// ConstructAPIResourceEndpoint constructs the full URL for a graph API resource endpoint path and logs the URL.
21-
func (g *GraphAPIHandler) ConstructAPIResourceEndpoint(instanceName string, endpointPath string, log logger.Logger) string {
21+
func (g *GraphAPIHandler) ConstructAPIResourceEndpoint(tenantName string, endpointPath string, log logger.Logger) string {
2222
urlBaseDomain := g.SetBaseDomain()
23-
url := fmt.Sprintf("https://%s%s%s", instanceName, urlBaseDomain, endpointPath)
23+
url := fmt.Sprintf("https://%s%s%s", tenantName, urlBaseDomain, endpointPath)
2424
g.Logger.Debug(fmt.Sprintf("Constructed %s API resource endpoint URL", APIName), zap.String("URL", url))
2525
return url
2626
}
2727

2828
// ConstructAPIAuthEndpoint constructs the full URL for the Microsoft Graph API authentication endpoint.
29-
// It uses the provided tenant name and endpoint path and logs the constructed URL.
30-
func (g *GraphAPIHandler) ConstructAPIAuthEndpoint(tenantName string, endpointPath string, log logger.Logger) string {
29+
// It uses the provided tenant ID and endpoint path and logs the constructed URL.
30+
func (g *GraphAPIHandler) ConstructAPIAuthEndpoint(tenantID string, endpointPath string, log logger.Logger) string {
3131
// The base URL for the Microsoft Graph API authentication endpoint.
3232
const baseURL = "https://login.microsoftonline.com"
3333

34-
// Construct the full URL by combining the base URL, tenant name, and endpoint path.
35-
url := fmt.Sprintf("%s/%s%s", baseURL, tenantName, endpointPath)
34+
// Construct the full URL by combining the base URL, tenant ID, and endpoint path.
35+
url := fmt.Sprintf("%s/%s%s", baseURL, tenantID, endpointPath)
3636

3737
// Log the constructed URL for debugging purposes.
38-
log.Debug(fmt.Sprintf("Constructed Microsoft Graph API authentication URL"), zap.String("URL", url))
38+
log.Debug("constructed Microsoft Graph API authentication URL", zap.String("URL", url))
3939

4040
return url
4141
}

httpclient/client.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ import (
2222

2323
// Client represents an HTTP client to interact with a specific API.
2424
type Client struct {
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
29-
clientConfig ClientConfig
30-
Logger logger.Logger
31-
ConcurrencyHandler *concurrency.ConcurrencyHandler
32-
APIHandler apihandler.APIHandler // APIHandler interface used to define which API handler to use
33-
AuthTokenHandler *authenticationhandler.AuthTokenHandler
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
29+
clientConfig ClientConfig // HTTP Client configuration
30+
Logger logger.Logger // Logger for logging messages
31+
ConcurrencyHandler *concurrency.ConcurrencyHandler // ConcurrencyHandler for managing concurrent requests
32+
APIHandler apihandler.APIHandler // APIHandler interface used to define which API handler to use
33+
AuthTokenHandler *authenticationhandler.AuthTokenHandler // AuthTokenHandler for managing authentication
3434
}
3535

3636
// Config holds configuration options for the HTTP Client.
@@ -148,10 +148,8 @@ 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+
AuthMethod: authMethod,
155153
httpClient: httpClient,
156154
clientConfig: config,
157155
Logger: log,

0 commit comments

Comments
 (0)