Skip to content

Commit cb7d977

Browse files
committed
BUG/MEDIUM: raw: return errors as text not objects
1 parent 1607798 commit cb7d977

File tree

6 files changed

+123
-60
lines changed

6 files changed

+123
-60
lines changed

embedded_spec.go

Lines changed: 45 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ require (
2424
github.com/google/go-cmp v0.6.0
2525
github.com/google/renameio v1.0.1
2626
github.com/google/uuid v1.6.0
27-
github.com/haproxytech/client-native/v6 v6.0.6
27+
github.com/haproxytech/client-native/v6 v6.0.8
2828
github.com/jessevdk/go-flags v1.6.1
2929
github.com/joho/godotenv v1.5.1
3030
github.com/json-iterator/go v1.1.12
@@ -39,7 +39,7 @@ require (
3939
github.com/stretchr/testify v1.10.0
4040
go.uber.org/automaxprocs v1.6.0
4141
golang.org/x/net v0.33.0
42-
golang.org/x/sys v0.28.0
42+
golang.org/x/sys v0.29.0
4343
gopkg.in/yaml.v2 v2.4.0
4444
)
4545

@@ -92,7 +92,7 @@ require (
9292
github.com/tklauser/go-sysconf v0.3.14 // indirect
9393
github.com/tklauser/numcpus v0.9.0 // indirect
9494
github.com/yusufpapurcu/wmi v1.2.4 // indirect
95-
go.mongodb.org/mongo-driver v1.17.1 // indirect
95+
go.mongodb.org/mongo-driver v1.17.2 // indirect
9696
golang.org/x/sync v0.10.0 // indirect
9797
google.golang.org/protobuf v1.36.1 // indirect
9898
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ github.com/fsnotify/fsnotify v1.8.0 h1:dAwr6QBTBZIkG8roQaJjGof0pp0EeF+tNV7YBP3F/
5858
github.com/fsnotify/fsnotify v1.8.0/go.mod h1:8jBTzvmWwFyi3Pb8djgCCO5IBqzKJ/Jwo8TRcHyHii0=
5959
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
6060
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
61-
github.com/go-faker/faker/v4 v4.4.2 h1:96WeU9QKEqRUVYdjHquY2/5bAqmVM0IfGKHV5mbfqmQ=
62-
github.com/go-faker/faker/v4 v4.4.2/go.mod h1:4K3v4AbKXYNHMQNaREMc9/kRB9j5JJzpFo6KHRvrcIw=
61+
github.com/go-faker/faker/v4 v4.5.0 h1:ARzAY2XoOL9tOUK+KSecUQzyXQsUaZHefjyF8x6YFHc=
62+
github.com/go-faker/faker/v4 v4.5.0/go.mod h1:p3oq1GRjG2PZ7yqeFFfQI20Xm61DoBDlCA8RiSyZ48M=
6363
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
6464
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
6565
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
@@ -99,8 +99,10 @@ github.com/google/renameio v1.0.1 h1:Lh/jXZmvZxb0BBeSY5VKEfidcbcbenKjZFzM/q0fSeU
9999
github.com/google/renameio v1.0.1/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
100100
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
101101
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
102-
github.com/haproxytech/client-native/v6 v6.0.6 h1:RlhF3sMe0FmZZzuAENLjR0uOjn2EG7ogsKVJhhe9+lM=
103-
github.com/haproxytech/client-native/v6 v6.0.6/go.mod h1:bc/E5mExkeoGTh1jXuMWO4q8cxZKD9LEyoGtQtJh2fY=
102+
github.com/haproxytech/client-native/v5 v5.1.9 h1:D+JvMsRHCewn+r+FJpzf3QUu2yHwGuV+s6IuJlajxYE=
103+
github.com/haproxytech/client-native/v5 v5.1.9/go.mod h1:rSJ7gT0vpZqNYdZQwzttLC4doOyoTL+B68F7cDjELNQ=
104+
github.com/haproxytech/client-native/v6 v6.0.8 h1:SsfdHAI6BqSHAKedyaNoSc3UayttZ/7pYMbp2oN0deo=
105+
github.com/haproxytech/client-native/v6 v6.0.8/go.mod h1:v1Gc4Lh3KGGjN3KnuiRFmm4D6eUXhbRvcjT6oEDUpI8=
104106
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
105107
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
106108
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
@@ -197,8 +199,8 @@ github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0
197199
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
198200
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
199201
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
200-
go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM=
201-
go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4=
202+
go.mongodb.org/mongo-driver v1.17.2 h1:gvZyk8352qSfzyZ2UMWcpDpMSGEr1eqE4T793SqyhzM=
203+
go.mongodb.org/mongo-driver v1.17.2/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
202204
go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs=
203205
go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8=
204206
go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA=
@@ -210,8 +212,8 @@ golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
210212
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
211213
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
212214
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
213-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
214-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
215+
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
216+
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
215217
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
216218
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
217219
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=

handlers/raw.go

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
package handlers
1717

1818
import (
19+
"encoding/json"
1920
"fmt"
21+
"net/http"
2022
"strconv"
2123
"strings"
2224

@@ -61,7 +63,11 @@ func (h *GetRawConfigurationHandlerImpl) Handle(params configuration.GetHAProxyC
6163
_, clusterVersion, md5Hash, data, err := cfg.GetRawConfigurationWithClusterData(t, v)
6264
if err != nil {
6365
e := misc.HandleError(err)
64-
return configuration.NewGetHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
66+
errorStr, marshallError := json.Marshal(e)
67+
if marshallError != nil {
68+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
69+
}
70+
return configuration.NewGetHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
6571
}
6672
cVersion := ""
6773
if clusterVersion != 0 {
@@ -99,25 +105,41 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
99105
code := misc.ErrHTTPBadRequest
100106
msg := "invalid configuration: no newline character found"
101107
e := &models.Error{Code: &code, Message: &msg}
102-
return configuration.NewPostHAProxyConfigurationBadRequest().WithPayload(e)
108+
errorStr, marshallError := json.Marshal(e)
109+
if marshallError != nil {
110+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
111+
}
112+
return configuration.NewPostHAProxyConfigurationBadRequest().WithPayload(string(errorStr))
103113
}
104114

105115
cfg, err := h.Client.Configuration()
106116
if err != nil {
107117
e := misc.HandleError(err)
108-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
118+
errorStr, marshallError := json.Marshal(e)
119+
if marshallError != nil {
120+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
121+
}
122+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
109123
}
110124

111125
err = cfg.PostRawConfiguration(&params.Data, v, skipVersion, onlyValidate)
112126
if err != nil {
113127
e := misc.HandleError(err)
114-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
128+
errorStr, marshallError := json.Marshal(e)
129+
if marshallError != nil {
130+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
131+
}
132+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
115133
}
116134

117135
_, clusterVersion, md5Hash, data, err := cfg.GetRawConfigurationWithClusterData("", 0)
118136
if err != nil {
119137
e := misc.HandleError(err)
120-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
138+
errorStr, marshallError := json.Marshal(e)
139+
if marshallError != nil {
140+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
141+
}
142+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
121143
}
122144

123145
cVersion := ""
@@ -132,7 +154,11 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
132154
if params.XRuntimeActions != nil {
133155
if err = executeRuntimeActions(*params.XRuntimeActions, h.Client); err != nil {
134156
e := misc.HandleError(err)
135-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
157+
errorStr, marshallError := json.Marshal(e)
158+
if marshallError != nil {
159+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
160+
}
161+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
136162
}
137163
}
138164
return configuration.NewPostHAProxyConfigurationCreated().WithPayload(data).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
@@ -143,7 +169,11 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
143169
callbackNeeded, reconfigureFunc, err = cn.ReconfigureRuntime(h.Client)
144170
if err != nil {
145171
e := misc.HandleError(err)
146-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
172+
errorStr, marshallError := json.Marshal(e)
173+
if marshallError != nil {
174+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
175+
}
176+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
147177
}
148178
if callbackNeeded {
149179
err = h.ReloadAgent.ForceReloadWithCallback(reconfigureFunc)
@@ -152,14 +182,22 @@ func (h *PostRawConfigurationHandlerImpl) Handle(params configuration.PostHAProx
152182
}
153183
if err != nil {
154184
e := misc.HandleError(err)
155-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
185+
errorStr, marshallError := json.Marshal(e)
186+
if marshallError != nil {
187+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
188+
}
189+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
156190
}
157191
return configuration.NewPostHAProxyConfigurationCreated().WithPayload(data).WithClusterVersion(cVersion).WithConfigurationChecksum(md5Hash)
158192
}
159193
callbackNeeded, reconfigureFunc, err := cn.ReconfigureRuntime(h.Client)
160194
if err != nil {
161195
e := misc.HandleError(err)
162-
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(e)
196+
errorStr, marshallError := json.Marshal(e)
197+
if marshallError != nil {
198+
configuration.NewPostHAProxyConfigurationDefault(http.StatusInternalServerError).WithPayload(marshallError.Error())
199+
}
200+
return configuration.NewPostHAProxyConfigurationDefault(int(*e.Code)).WithPayload(string(errorStr))
163201
}
164202

165203
var rID string

operations/configuration/get_h_a_proxy_configuration_responses.go

Lines changed: 6 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)