2020-03-19 13:23:16 -04:00
|
|
|
/*
|
2022-06-29 16:59:46 -04:00
|
|
|
Copyright NetFoundry Inc.
|
2020-03-19 13:23:16 -04:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package handler_ctrl
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"github.com/michaelquigley/pfxlog"
|
2025-04-02 14:24:31 -04:00
|
|
|
"github.com/openziti/channel/v4"
|
2026-01-26 15:54:45 -05:00
|
|
|
"github.com/openziti/ziti/v2/common/handler_common"
|
|
|
|
|
"github.com/openziti/ziti/v2/common/pb/ctrl_pb"
|
|
|
|
|
"github.com/openziti/ziti/v2/controller/model"
|
|
|
|
|
"github.com/openziti/ziti/v2/controller/network"
|
2022-08-22 14:17:43 -04:00
|
|
|
"google.golang.org/protobuf/proto"
|
2020-03-19 13:23:16 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type removeTerminatorHandler struct {
|
2023-03-13 23:29:50 -04:00
|
|
|
baseHandler
|
2020-03-19 13:23:16 -04:00
|
|
|
}
|
|
|
|
|
|
2024-07-09 14:16:41 -04:00
|
|
|
func newRemoveTerminatorHandler(network *network.Network, router *model.Router) *removeTerminatorHandler {
|
2023-03-13 23:29:50 -04:00
|
|
|
return &removeTerminatorHandler{
|
|
|
|
|
baseHandler: baseHandler{
|
|
|
|
|
router: router,
|
|
|
|
|
network: network,
|
|
|
|
|
},
|
|
|
|
|
}
|
2020-03-19 13:23:16 -04:00
|
|
|
}
|
|
|
|
|
|
2023-03-13 23:29:50 -04:00
|
|
|
func (self *removeTerminatorHandler) ContentType() int32 {
|
2020-03-19 13:23:16 -04:00
|
|
|
return int32(ctrl_pb.ContentType_RemoveTerminatorRequestType)
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-13 23:29:50 -04:00
|
|
|
func (self *removeTerminatorHandler) HandleReceive(msg *channel.Message, ch channel.Channel) {
|
2020-03-19 13:23:16 -04:00
|
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
|
|
|
|
|
|
|
|
request := &ctrl_pb.RemoveTerminatorRequest{}
|
|
|
|
|
if err := proto.Unmarshal(msg.Body, request); err != nil {
|
2021-11-30 01:03:51 -05:00
|
|
|
log.WithError(err).Error("failed to unmarshal remove terminator message")
|
2020-03-19 13:23:16 -04:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-13 23:29:50 -04:00
|
|
|
go self.handleRemoveTerminator(msg, ch, request)
|
2021-11-30 01:03:51 -05:00
|
|
|
}
|
|
|
|
|
|
2023-03-13 23:29:50 -04:00
|
|
|
func (self *removeTerminatorHandler) handleRemoveTerminator(msg *channel.Message, ch channel.Channel, request *ctrl_pb.RemoveTerminatorRequest) {
|
2021-11-30 01:03:51 -05:00
|
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
|
|
|
|
2024-07-09 14:16:41 -04:00
|
|
|
terminator, err := self.network.Terminator.Read(request.TerminatorId)
|
2020-03-19 13:23:16 -04:00
|
|
|
if err != nil {
|
|
|
|
|
handler_common.SendFailure(msg, ch, err.Error())
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-09 14:16:41 -04:00
|
|
|
if err := self.network.Terminator.Delete(request.TerminatorId, self.newChangeContext(ch, "fabric.remove.terminator")); err == nil {
|
2022-04-05 22:34:30 -04:00
|
|
|
log.
|
2022-09-26 15:28:20 -04:00
|
|
|
WithField("routerId", ch.Id()).
|
2022-04-05 22:34:30 -04:00
|
|
|
WithField("serviceId", terminator.Service).
|
|
|
|
|
WithField("terminator", request.TerminatorId).
|
|
|
|
|
Info("removed terminator")
|
2020-03-19 13:23:16 -04:00
|
|
|
handler_common.SendSuccess(msg, ch, "")
|
|
|
|
|
} else {
|
|
|
|
|
handler_common.SendFailure(msg, ch, err.Error())
|
|
|
|
|
}
|
|
|
|
|
}
|