Skip to content

Commit 8fe0733

Browse files
committed
chore: Update logging and request body handling in Microsoft Graph integration code
1 parent 048032f commit 8fe0733

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

msgraph/msgraphintegration/interface.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ func (m *Integration) GetFQDN() string {
2323
return m.getFQDN()
2424
}
2525

26+
// Construct a URL for Microsoft Graph
27+
func (j *Integration) ConstructURL(endpoint string) string {
28+
return j.GetFQDN() + endpoint
29+
}
30+
2631
// TODO migrate strings
2732
func (m *Integration) GetAuthMethodDescriptor() string {
2833
return m.AuthMethodDescriptor

msgraph/msgraphintegration/marshall.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ import (
1212
"go.uber.org/zap"
1313
)
1414

15+
// methodsWithBody is a set of HTTP methods that benefit from logging the request body.
16+
var methodsWithBody = map[string]bool{
17+
"POST": true,
18+
"PUT": true,
19+
"PATCH": true,
20+
}
21+
1522
// MarshalRequest encodes the request body as JSON for the Microsoft Graph API.
1623
// This function takes an interface{} type body, an HTTP method, and an endpoint as input,
1724
// and returns the marshaled JSON byte slice along with any error encountered during marshaling.
@@ -30,6 +37,8 @@ import (
3037
// Logging:
3138
// - Logs an error if JSON marshaling fails.
3239
// - Logs the JSON request body for POST, PUT, and PATCH methods.
40+
//
41+
// Set of methods that require logging the request body
3342
func (m *Integration) marshalRequest(body interface{}, method string, endpoint string) ([]byte, error) {
3443
var (
3544
data []byte
@@ -43,8 +52,8 @@ func (m *Integration) marshalRequest(body interface{}, method string, endpoint s
4352
return nil, err
4453
}
4554

46-
// Log the JSON request body for POST, PUT, or PATCH methods
47-
if method == "POST" || method == "PUT" || method == "PATCH" {
55+
// Log the JSON request body for methods that require it
56+
if methodsWithBody[method] {
4857
m.Logger.Debug("JSON Request Body", zap.String("Body", string(data)), zap.String("Endpoint", endpoint))
4958
} else {
5059
m.Logger.Debug("Request Endpoint", zap.String("Endpoint", endpoint))

0 commit comments

Comments
 (0)