mirror of
https://github.com/openziti/ziti.git
synced 2026-09-11 13:29:03 +00:00
56 lines
1.8 KiB
Go
56 lines
1.8 KiB
Go
/*
|
|
Copyright NetFoundry, Inc.
|
|
|
|
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_mgmt
|
|
|
|
import (
|
|
"google.golang.org/protobuf/proto"
|
|
"github.com/michaelquigley/pfxlog"
|
|
"github.com/openziti/channel"
|
|
"github.com/openziti/fabric/controller/network"
|
|
"github.com/openziti/fabric/handler_common"
|
|
"github.com/openziti/fabric/pb/mgmt_pb"
|
|
)
|
|
|
|
type createRouterHandler struct {
|
|
network *network.Network
|
|
}
|
|
|
|
func newCreateRouterHandler(network *network.Network) *createRouterHandler {
|
|
return &createRouterHandler{network: network}
|
|
}
|
|
|
|
func (h *createRouterHandler) ContentType() int32 {
|
|
return int32(mgmt_pb.ContentType_CreateRouterRequestType)
|
|
}
|
|
|
|
func (h *createRouterHandler) HandleReceive(msg *channel.Message, ch channel.Channel) {
|
|
log := pfxlog.ContextLogger(ch.Label())
|
|
|
|
create := &mgmt_pb.CreateRouterRequest{}
|
|
if err := proto.Unmarshal(msg.Body, create); err == nil {
|
|
r := network.NewRouter(create.Router.Id, create.Router.Name, create.Router.Fingerprint, uint16(create.Router.Cost), create.Router.NoTraversal)
|
|
if err := h.network.CreateRouter(r); err == nil {
|
|
log.Infof("created router [r/%s] with fingerprint [%s]", r.Id, create.Router.Fingerprint)
|
|
handler_common.SendSuccess(msg, ch, "")
|
|
} else {
|
|
handler_common.SendFailure(msg, ch, err.Error())
|
|
}
|
|
} else {
|
|
handler_common.SendFailure(msg, ch, err.Error())
|
|
}
|
|
}
|