Skip to content

Commit caf2805

Browse files
Fix linter issues in write-only implementation.
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 69b0e63 commit caf2805

3 files changed

Lines changed: 7 additions & 24 deletions

File tree

internal/provider/curl_resource.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ func (r *CurlResource) Create(ctx context.Context, req resource.CreateRequest, r
591591
}
592592
data.RequestUrlString = types.StringValue(request.URL.String())
593593

594-
tflog.Debug(ctx, fmt.Sprintf("Resource create API Call: \nURL: %s\nHeaders: %s\nMethod: %s\nRequest Body: %s\n", request.URL.String(), request.Header, request.Method, requestBodyForLog(data.RequestBody, data.RequestBodyWo, usedWriteOnlyBody)))
594+
tflog.Debug(ctx, fmt.Sprintf("Resource create API Call: \nURL: %s\nHeaders: %s\nMethod: %s\nRequest Body: %s\n", request.URL.String(), request.Header, request.Method, requestBodyForLog(data.RequestBody, usedWriteOnlyBody)))
595595
timeout := 10 * time.Second
596596
if !data.Timeout.IsNull() {
597597
timeout = time.Duration(data.Timeout.ValueInt64()) * time.Second
@@ -726,7 +726,7 @@ func (r *CurlResource) executeReadRequest(ctx context.Context, data CurlResource
726726
request.URL.RawQuery = params.Encode()
727727
}
728728

729-
tflog.Debug(ctx, fmt.Sprintf("Resource read API Call: \nURL: %s\nHeaders: %s\nMethod: %s\nRequest Body: %s\n", request.URL.String(), request.Header, request.Method, requestBodyForLog(data.ReadRequestBody, data.ReadRequestBodyWo, usedWriteOnlyBody)))
729+
tflog.Debug(ctx, fmt.Sprintf("Resource read API Call: \nURL: %s\nHeaders: %s\nMethod: %s\nRequest Body: %s\n", request.URL.String(), request.Header, request.Method, requestBodyForLog(data.ReadRequestBody, usedWriteOnlyBody)))
730730

731731
httpResp, err := client.Do(request)
732732
if err != nil {
@@ -990,7 +990,7 @@ func (r *CurlResource) Delete(ctx context.Context, req resource.DeleteRequest, r
990990
retryInterval := time.Duration(data.DestroyRetryInterval.ValueInt64()) * time.Second
991991
maxRetry := int(data.DestroyMaxRetry.ValueInt64())
992992

993-
tflog.Debug(ctx, fmt.Sprintf("Resource destroy API Call: \nURL: %s\nHeaders: %s\nMethod: %s\nRequest Body: %s\n", request.URL.String(), request.Header, request.Method, requestBodyForLog(data.DestroyRequestBody, data.DestroyRequestBodyWo, usedWriteOnlyBody)))
993+
tflog.Debug(ctx, fmt.Sprintf("Resource destroy API Call: \nURL: %s\nHeaders: %s\nMethod: %s\nRequest Body: %s\n", request.URL.String(), request.Header, request.Method, requestBodyForLog(data.DestroyRequestBody, usedWriteOnlyBody)))
994994

995995
var bodyBytes []byte
996996
var statusCode int

internal/provider/write_only.go

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func applyRequestHeadersWithWriteOnly(req *http.Request, headers, headersWo type
8585
applyRequestHeaders(req, headersWo)
8686
}
8787

88-
func requestBodyForLog(regular, writeOnly types.String, usedWriteOnly bool) string {
88+
func requestBodyForLog(regular types.String, usedWriteOnly bool) string {
8989
if usedWriteOnly {
9090
return "<redacted write-only request body>"
9191
}
@@ -197,24 +197,6 @@ func writeOnlyVersionsChanged(state, config CurlResourceModel) bool {
197197
state.DestroyRequestBodyWoVersion.ValueInt64() != config.DestroyRequestBodyWoVersion.ValueInt64()
198198
}
199199

200-
func applyWriteOnlySnapshot(snapshot writeOnlyPrivateSnapshot, data *CurlResourceModel) {
201-
if data == nil {
202-
return
203-
}
204-
data.HeadersWo = stringMapToTypesMap(snapshot.HeadersCreate)
205-
data.ReadHeadersWo = stringMapToTypesMap(snapshot.HeadersRead)
206-
data.DestroyHeadersWo = stringMapToTypesMap(snapshot.HeadersDestroy)
207-
if snapshot.BodyCreate != "" {
208-
data.RequestBodyWo = types.StringValue(snapshot.BodyCreate)
209-
}
210-
if snapshot.BodyRead != "" {
211-
data.ReadRequestBodyWo = types.StringValue(snapshot.BodyRead)
212-
}
213-
if snapshot.BodyDestroy != "" {
214-
data.DestroyRequestBodyWo = types.StringValue(snapshot.BodyDestroy)
215-
}
216-
}
217-
218200
func nullWriteOnlyAttributes(data *CurlResourceModel) {
219201
if data == nil {
220202
return

internal/provider/write_only_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ func TestWriteOnlyPrivateSnapshotRoundtrip(t *testing.T) {
108108
t.Fatalf("load failed: %v", diags)
109109
}
110110

111-
if loaded.DestroyHeadersWo.Elements()["Authorization"].(types.String).ValueString() != "Bearer destroy" {
111+
auth, ok := loaded.DestroyHeadersWo.Elements()["Authorization"].(types.String)
112+
if !ok || auth.ValueString() != "Bearer destroy" {
112113
t.Fatalf("unexpected destroy headers %#v", loaded.DestroyHeadersWo)
113114
}
114115
if loaded.ReadRequestBodyWo.ValueString() != `{"read":true}` {
@@ -149,7 +150,7 @@ func TestWriteOnlyVersionsChanged(t *testing.T) {
149150
}
150151

151152
func TestRequestBodyForLogRedactsWriteOnly(t *testing.T) {
152-
got := requestBodyForLog(types.StringNull(), types.StringValue("secret"), true)
153+
got := requestBodyForLog(types.StringNull(), true)
153154
if got != "<redacted write-only request body>" {
154155
t.Fatalf("unexpected log value %q", got)
155156
}

0 commit comments

Comments
 (0)