Skip to content

Commit

Permalink
Always set string to request body to avoid resty logger base64 encode…
Browse files Browse the repository at this point in the history
… []byte
  • Loading branch information
magodo committed Jan 17, 2025
1 parent b1cfe07 commit e594b62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ type CreateOption struct {
Header Header
}

func (c *Client) Create(ctx context.Context, path string, body interface{}, opt CreateOption) (*resty.Response, error) {
func (c *Client) Create(ctx context.Context, path string, body string, opt CreateOption) (*resty.Response, error) {
req := c.R().SetContext(ctx).SetBody(body)
req.SetQueryParamsFromValues(url.Values(opt.Query))
req.SetHeaders(opt.Header)
Expand Down Expand Up @@ -202,7 +202,7 @@ type UpdateOption struct {
Header Header
}

func (c *Client) Update(ctx context.Context, path string, body interface{}, opt UpdateOption) (*resty.Response, error) {
func (c *Client) Update(ctx context.Context, path string, body string, opt UpdateOption) (*resty.Response, error) {
req := c.R().SetContext(ctx).SetBody(body)
req.SetQueryParamsFromValues(url.Values(opt.Query))
req.SetHeaders(opt.Header)
Expand All @@ -226,9 +226,9 @@ type DeleteOption struct {
Header Header
}

func (c *Client) Delete(ctx context.Context, path string, body interface{}, opt DeleteOption) (*resty.Response, error) {
func (c *Client) Delete(ctx context.Context, path string, body string, opt DeleteOption) (*resty.Response, error) {
req := c.R().SetContext(ctx)
if body != nil {
if body != "" {
req = req.SetHeader("Content-Type", "application/json")
req.SetBody(body)
}
Expand Down Expand Up @@ -272,7 +272,7 @@ func (c *Client) Operation(ctx context.Context, path string, body basetypes.Dyna
return nil, fmt.Errorf("convert body from dynamic to json: %v", err)
}

req.SetBody(b)
req.SetBody(string(b))
case "application/x-www-form-urlencoded":
ov, ok := body.UnderlyingValue().(types.Object)
if !ok {
Expand Down
8 changes: 4 additions & 4 deletions internal/provider/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1133,7 +1133,7 @@ func (r Resource) Update(ctx context.Context, req resource.UpdateRequest, resp *
}
}

response, err := c.Update(ctx, path, planBody, *opt)
response, err := c.Update(ctx, path, string(planBody), *opt)
if err != nil {
resp.Diagnostics.AddError(
"Error to call update",
Expand Down Expand Up @@ -1251,16 +1251,16 @@ func (r Resource) Delete(ctx context.Context, req resource.DeleteRequest, resp *
}
}

var body interface{}
var body string
if db := state.DeleteBody; !db.IsNull() {
var err error
body, err = dynamic.ToJSON(db)
b, err := dynamic.ToJSON(db)
if err != nil {
resp.Diagnostics.AddError(
"Failed to marshal `delete_body`",
err.Error(),
)
}
body = string(b)
}

response, err := c.Delete(ctx, path, body, *opt)
Expand Down

0 comments on commit e594b62

Please sign in to comment.