|
| 1 | +// Copyright 2025 HAProxy Technologies |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// |
| 15 | + |
| 16 | +package handlers |
| 17 | + |
| 18 | +import ( |
| 19 | + "github.com/go-openapi/runtime/middleware" |
| 20 | + client_native "github.com/haproxytech/client-native/v6" |
| 21 | + "github.com/haproxytech/dataplaneapi/misc" |
| 22 | + "github.com/haproxytech/dataplaneapi/operations/acme_runtime" |
| 23 | +) |
| 24 | + |
| 25 | +type GetAcmeStatusHandlerImpl struct { |
| 26 | + Client client_native.HAProxyClient |
| 27 | +} |
| 28 | + |
| 29 | +func (h *GetAcmeStatusHandlerImpl) Handle(params acme_runtime.GetAcmeStatusParams, principal interface{}) middleware.Responder { |
| 30 | + rt, err := h.Client.Runtime() |
| 31 | + if err != nil { |
| 32 | + e := misc.HandleError(err) |
| 33 | + return acme_runtime.NewGetAcmeStatusDefault(int(*e.Code)).WithPayload(e) |
| 34 | + } |
| 35 | + |
| 36 | + status, err := rt.AcmeStatus() |
| 37 | + if err != nil { |
| 38 | + e := misc.HandleError(err) |
| 39 | + return acme_runtime.NewGetAcmeStatusDefault(int(*e.Code)).WithPayload(e) |
| 40 | + } |
| 41 | + |
| 42 | + return acme_runtime.NewGetAcmeStatusOK().WithPayload(status) |
| 43 | +} |
| 44 | + |
| 45 | +type RenewAcmeCertificateHandlerImpl struct { |
| 46 | + Client client_native.HAProxyClient |
| 47 | +} |
| 48 | + |
| 49 | +func (h *RenewAcmeCertificateHandlerImpl) Handle(params acme_runtime.RenewAcmeCertificateParams, principal interface{}) middleware.Responder { |
| 50 | + rt, err := h.Client.Runtime() |
| 51 | + if err != nil { |
| 52 | + e := misc.HandleError(err) |
| 53 | + return acme_runtime.NewRenewAcmeCertificateDefault(int(*e.Code)).WithPayload(e) |
| 54 | + } |
| 55 | + |
| 56 | + if err := rt.AcmeRenew(params.Certificate); err != nil { |
| 57 | + e := misc.HandleError(err) |
| 58 | + return acme_runtime.NewRenewAcmeCertificateDefault(int(*e.Code)).WithPayload(e) |
| 59 | + } |
| 60 | + |
| 61 | + return acme_runtime.NewRenewAcmeCertificateOK() |
| 62 | +} |
0 commit comments