Skip to content

Commit 42fd7b5

Browse files
Michael McNeesclaude
authored andcommitted
fix(connector): address CodeRabbit feedback on connector-batch-3
- azure/invoke_function: error on non-2xx responses; url.QueryEscape function key - gcp/invoke_cloud_run: error on non-2xx responses - github/dispatch_workflow: url.PathEscape workflowID in path - drive/upload: use multipart.NewWriter for random boundary (prevents boundary collision) - k8s: url.PathEscape namespace/name in resource paths and get_pod_status - salesforce: url.PathEscape objectType in create_record path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f7d5a1e commit 42fd7b5

6 files changed

Lines changed: 45 additions & 19 deletions

File tree

packages/engine/internal/connector/azureblob.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"net/url"
1011
"strings"
1112
)
1213

@@ -200,9 +201,9 @@ func (c *AzureInvokeFunctionConnector) Execute(ctx context.Context, params map[s
200201
endpoint := functionURL
201202
if functionKey != "" {
202203
if strings.Contains(endpoint, "?") {
203-
endpoint += "&code=" + functionKey
204+
endpoint += "&code=" + url.QueryEscape(functionKey)
204205
} else {
205-
endpoint += "?code=" + functionKey
206+
endpoint += "?code=" + url.QueryEscape(functionKey)
206207
}
207208
}
208209

@@ -232,6 +233,9 @@ func (c *AzureInvokeFunctionConnector) Execute(ctx context.Context, params map[s
232233
if err != nil {
233234
return nil, fmt.Errorf("azure/invoke_function: reading response: %w", err)
234235
}
236+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
237+
return nil, fmt.Errorf("azure/invoke_function: request failed with status %d: %s", resp.StatusCode, truncate(string(body), 500))
238+
}
235239

236240
contentType := resp.Header.Get("Content-Type")
237241
if strings.Contains(contentType, "application/json") && len(body) > 0 {

packages/engine/internal/connector/gcpconnector.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ func (c *GCPInvokeCloudRunConnector) Execute(ctx context.Context, params map[str
139139
if err != nil {
140140
return nil, fmt.Errorf("gcp/invoke_cloud_run: reading response: %w", err)
141141
}
142+
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
143+
return nil, fmt.Errorf("gcp/invoke_cloud_run: request failed with status %d: %s", resp.StatusCode, truncate(string(body), 500))
144+
}
142145

143146
contentType := resp.Header.Get("Content-Type")
144147
if strings.Contains(contentType, "application/json") && len(body) > 0 {

packages/engine/internal/connector/github.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
"net/url"
1011
"time"
1112
)
1213

@@ -221,7 +222,7 @@ func (c *GitHubDispatchWorkflowConnector) Execute(ctx context.Context, params ma
221222
return nil, fmt.Errorf("github/dispatch_workflow: marshaling request: %w", err)
222223
}
223224

224-
path := fmt.Sprintf("/repos/%s/%s/actions/workflows/%s/dispatches", owner, repo, workflowID)
225+
path := fmt.Sprintf("/repos/%s/%s/actions/workflows/%s/dispatches", owner, repo, url.PathEscape(workflowID))
225226
req, err := http.NewRequestWithContext(ctx, "POST", c.apiURL(path), bytes.NewReader(reqJSON))
226227
if err != nil {
227228
return nil, fmt.Errorf("github/dispatch_workflow: creating request: %w", err)

packages/engine/internal/connector/googledrive.go

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"context"
66
"fmt"
77
"io"
8+
"mime/multipart"
89
"net/http"
10+
"net/textproto"
911
"net/url"
1012
)
1113

@@ -56,17 +58,32 @@ func (c *GoogleDriveUploadConnector) Execute(ctx context.Context, params map[str
5658
metaBody = fmt.Sprintf(`{"name":%q}`, name)
5759
}
5860

59-
boundary := "mantle_multipart_boundary"
6061
var buf bytes.Buffer
61-
// Part 1: metadata
62-
buf.WriteString("--" + boundary + "\r\n")
63-
buf.WriteString("Content-Type: application/json\r\n\r\n")
64-
buf.WriteString(metaBody + "\r\n")
65-
// Part 2: content
66-
buf.WriteString("--" + boundary + "\r\n")
67-
buf.WriteString("Content-Type: " + mimeType + "\r\n\r\n")
68-
buf.WriteString(content + "\r\n")
69-
buf.WriteString("--" + boundary + "--\r\n")
62+
mw := multipart.NewWriter(&buf)
63+
64+
metaHeader := make(textproto.MIMEHeader)
65+
metaHeader.Set("Content-Type", "application/json")
66+
metaPart, err := mw.CreatePart(metaHeader)
67+
if err != nil {
68+
return nil, fmt.Errorf("drive/upload: creating metadata part: %w", err)
69+
}
70+
if _, err := io.WriteString(metaPart, metaBody); err != nil {
71+
return nil, fmt.Errorf("drive/upload: writing metadata: %w", err)
72+
}
73+
74+
contentHeader := make(textproto.MIMEHeader)
75+
contentHeader.Set("Content-Type", mimeType)
76+
contentPart, err := mw.CreatePart(contentHeader)
77+
if err != nil {
78+
return nil, fmt.Errorf("drive/upload: creating content part: %w", err)
79+
}
80+
if _, err := io.WriteString(contentPart, content); err != nil {
81+
return nil, fmt.Errorf("drive/upload: writing content: %w", err)
82+
}
83+
84+
if err := mw.Close(); err != nil {
85+
return nil, fmt.Errorf("drive/upload: closing writer: %w", err)
86+
}
7087

7188
endpoint := c.getUploadURL() + "?uploadType=multipart"
7289

@@ -75,7 +92,7 @@ func (c *GoogleDriveUploadConnector) Execute(ctx context.Context, params map[str
7592
return nil, fmt.Errorf("drive/upload: creating request: %w", err)
7693
}
7794
req.Header.Set("Authorization", "Bearer "+token)
78-
req.Header.Set("Content-Type", "multipart/related; boundary="+boundary)
95+
req.Header.Set("Content-Type", "multipart/related; boundary="+mw.Boundary())
7996

8097
resp, err := httpClient(c.Client).Do(req)
8198
if err != nil {

packages/engine/internal/connector/kubernetes.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"fmt"
99
"io"
1010
"net/http"
11+
"net/url"
1112
"strings"
1213
)
1314

@@ -92,9 +93,9 @@ func k8sResourcePath(apiVersion, kind, namespace, name string) string {
9293
}
9394

9495
if name != "" {
95-
return fmt.Sprintf("%s/namespaces/%s/%s/%s", basePath, namespace, resourceType, name)
96+
return fmt.Sprintf("%s/namespaces/%s/%s/%s", basePath, url.PathEscape(namespace), resourceType, url.PathEscape(name))
9697
}
97-
return fmt.Sprintf("%s/namespaces/%s/%s", basePath, namespace, resourceType)
98+
return fmt.Sprintf("%s/namespaces/%s/%s", basePath, url.PathEscape(namespace), resourceType)
9899
}
99100

100101
// k8sDoRequest executes an HTTP request against the Kubernetes API.
@@ -356,9 +357,9 @@ func (c *K8sGetPodStatusConnector) Execute(ctx context.Context, params map[strin
356357
}
357358

358359
client := k8sInsecureClient(c.Client)
359-
url := fmt.Sprintf("%s/api/v1/namespaces/%s/pods/%s", baseURL, namespace, podName)
360+
podURL := fmt.Sprintf("%s/api/v1/namespaces/%s/pods/%s", baseURL, url.PathEscape(namespace), url.PathEscape(podName))
360361

361-
result, statusCode, err := k8sDoRequest(ctx, client, http.MethodGet, url, token, nil)
362+
result, statusCode, err := k8sDoRequest(ctx, client, http.MethodGet, podURL, token, nil)
362363
if err != nil {
363364
return nil, fmt.Errorf("k8s/get_pod_status: %w", err)
364365
}

packages/engine/internal/connector/salesforce.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func (c *SalesforceCreateRecordConnector) Execute(ctx context.Context, params ma
141141
return nil, fmt.Errorf("salesforce/create_record: marshaling request: %w", err)
142142
}
143143

144-
path := fmt.Sprintf("/sobjects/%s", objectType)
144+
path := fmt.Sprintf("/sobjects/%s", url.PathEscape(objectType))
145145
req, err := http.NewRequestWithContext(ctx, "POST", c.dataURL(instanceURL, path), bytes.NewReader(reqJSON))
146146
if err != nil {
147147
return nil, fmt.Errorf("salesforce/create_record: creating request: %w", err)

0 commit comments

Comments
 (0)