@@ -236,6 +236,62 @@ func (h *CreateDefaultsSectionHandlerImpl) createDefaultsSection(params defaults
236236 return configuration .CreateDefaultsSection (params .Data , t , v )
237237}
238238
239+ type AddDefaultsSectionHandlerImpl struct {
240+ Client client_native.HAProxyClient
241+ ReloadAgent haproxy.IReloadAgent
242+ }
243+
244+ func (h AddDefaultsSectionHandlerImpl ) Handle (params defaults.AddDefaultsSectionParams , principal interface {}) middleware.Responder {
245+ t := ""
246+ v := int64 (0 )
247+ if params .TransactionID != nil {
248+ t = * params .TransactionID
249+ }
250+ if params .Version != nil {
251+ v = * params .Version
252+ }
253+
254+ if t != "" && * params .ForceReload {
255+ msg := "Both force_reload and transaction specified, specify only one"
256+ c := misc .ErrHTTPBadRequest
257+ e := & models.Error {
258+ Message : & msg ,
259+ Code : & c ,
260+ }
261+ return defaults .NewAddDefaultsSectionDefault (int (* e .Code )).WithPayload (e )
262+ }
263+
264+ err := h .createDefaultsSection (params , t , v )
265+ if err != nil {
266+ e := misc .HandleError (err )
267+ return defaults .NewAddDefaultsSectionDefault (int (* e .Code )).WithPayload (e )
268+ }
269+ if params .TransactionID == nil {
270+ if * params .ForceReload {
271+ err := h .ReloadAgent .ForceReload ()
272+ if err != nil {
273+ e := misc .HandleError (err )
274+ return defaults .NewAddDefaultsSectionDefault (int (* e .Code )).WithPayload (e )
275+ }
276+ return defaults .NewAddDefaultsSectionCreated ().WithPayload (params .Data )
277+ }
278+ rID := h .ReloadAgent .Reload ()
279+ return defaults .NewAddDefaultsSectionAccepted ().WithReloadID (rID ).WithPayload (params .Data )
280+ }
281+ return defaults .NewAddDefaultsSectionAccepted ().WithPayload (params .Data )
282+ }
283+
284+ func (h * AddDefaultsSectionHandlerImpl ) createDefaultsSection (params defaults.AddDefaultsSectionParams , t string , v int64 ) error {
285+ configuration , err := h .Client .Configuration ()
286+ if err != nil {
287+ return err
288+ }
289+ if params .FullSection != nil && * params .FullSection {
290+ return configuration .CreateStructuredDefaultsSection (params .Data , t , v )
291+ }
292+ return configuration .CreateDefaultsSection (params .Data , t , v )
293+ }
294+
239295// ReplaceDefaultsHandlerImpl implementation of the ReplaceDefaultsHandler interface
240296type ReplaceDefaultsSectionHandlerImpl struct {
241297 Client client_native.HAProxyClient
0 commit comments