Skip to content

Commit 3efea34

Browse files
committed
chore: Refactor MarshalMultipartRequest to handle file contents as byte slices
1 parent 26703a8 commit 3efea34

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

apiintegrations/apihandler/apihandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type APIHandler interface {
1414
ConstructAPIResourceEndpoint(endpointPath string, log logger.Logger) string
1515
ConstructAPIAuthEndpoint(endpointPath string, log logger.Logger) string
1616
MarshalRequest(body interface{}, method string, endpoint string, log logger.Logger) ([]byte, error)
17-
MarshalMultipartRequest(formFields map[string]string, fileContents map[string][]byte, log *zap.Logger) ([]byte, string, string, error)
17+
MarshalMultipartRequest(formFields map[string]string, fileContents map[string][]byte, log logger.Logger) ([]byte, string, string, error)
1818
GetContentTypeHeader(method string, log logger.Logger) string
1919
GetAcceptHeader() string
2020
GetDefaultBaseDomain() string

apiintegrations/jamfpro/jamfpro_api_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (j *JamfAPIHandler) MarshalRequest(body interface{}, method string, endpoin
5454
}
5555

5656
// MarshalMultipartRequest handles multipart form data encoding with secure file handling and returns the encoded body and content type.
57-
func (j *JamfAPIHandler) MarshalMultipartRequest(formFields map[string]string, fileContents map[string][]byte, log *zap.Logger) ([]byte, string, string, error) {
57+
func (j *JamfAPIHandler) MarshalMultipartRequest(formFields map[string]string, fileContents map[string][]byte, log logger.Logger) ([]byte, string, string, error) {
5858
const snippetLength = 20
5959
var b bytes.Buffer
6060
writer := multipart.NewWriter(&b)

apiintegrations/msgraph/msgraph_api_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (g *GraphAPIHandler) MarshalRequest(body interface{}, method string, endpoi
2828
}
2929

3030
// MarshalMultipartRequest handles multipart form data encoding with secure file handling and returns the encoded body and content type.
31-
func (g *GraphAPIHandler) MarshalMultipartRequest(formFields map[string]string, fileContents map[string][]byte, log *zap.Logger) ([]byte, string, string, error) {
31+
func (g *GraphAPIHandler) MarshalMultipartRequest(formFields map[string]string, fileContents map[string][]byte, log logger.Logger) ([]byte, string, string, error) {
3232
const snippetLength = 20
3333
var b bytes.Buffer
3434
writer := multipart.NewWriter(&b)

httpclient/multipartrequest.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *Client) DoMultipartRequest(method, endpoint string, fields map[string]s
5555
}
5656

5757
// Marshal the multipart form data
58-
requestData, contentType, err := c.APIHandler.MarshalMultipartRequest(fields, files, log)
58+
requestData, contentType, snippet, err := c.APIHandler.MarshalMultipartRequest(fields, files, log)
5959
if err != nil {
6060
return nil, err
6161
}
@@ -70,14 +70,15 @@ func (c *Client) DoMultipartRequest(method, endpoint string, fields map[string]s
7070
}
7171

7272
// Initialize HeaderManager
73-
//log.Debug("Setting Authorization header with token", zap.String("Token", c.Token))
7473
headerHandler := headers.NewHeaderHandler(req, c.Logger, c.APIHandler, c.AuthTokenHandler)
7574

7675
// Use HeaderManager to set headers
7776
headerHandler.SetContentType(contentType)
7877
headerHandler.SetRequestHeaders(endpoint)
7978
headerHandler.LogHeaders(c.clientConfig.ClientOptions.Logging.HideSensitiveData)
8079

80+
log.Debug("Multipart request details", zap.String("URL", url), zap.String("Method", method), zap.String("Snippet", snippet))
81+
8182
// Execute the request
8283
resp, err := c.httpClient.Do(req)
8384
if err != nil {

0 commit comments

Comments
 (0)