mirror of
https://github.com/hanzozt/zt.git
synced 2026-10-30 15:04:55 +00:00
- Repo names: ziti-* → zt-* - Go modules: github.com/hanzozt/ziti → github.com/hanzozt/zt - Docker images: hanzozt/ziti-* → hanzozt/zt-* - C/Java/JS symbols: ziti_* → zt_* - File and directory names updated
79 lines
2.5 KiB
Go
79 lines
2.5 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 routes
|
|
|
|
import (
|
|
"github.com/hanzozt/zt/v2/controller/env"
|
|
"github.com/hanzozt/zt/v2/controller/model"
|
|
"github.com/hanzozt/zt/v2/controller/response"
|
|
"github.com/hanzozt/zt/v2/controller/rest_model"
|
|
)
|
|
|
|
const EntityNameCircuit = "circuits"
|
|
|
|
var CircuitLinkFactory = NewCircuitLinkFactory()
|
|
|
|
type CircuitLinkFactoryIml struct {
|
|
BasicFabricLinkFactory
|
|
}
|
|
|
|
func NewCircuitLinkFactory() *CircuitLinkFactoryIml {
|
|
return &CircuitLinkFactoryIml{
|
|
BasicFabricLinkFactory: *NewBasicFabricLinkFactory(EntityNameCircuit),
|
|
}
|
|
}
|
|
|
|
func (factory *CircuitLinkFactoryIml) Links(entity LinkEntity) rest_model.Links {
|
|
links := factory.BasicFabricLinkFactory.Links(entity)
|
|
links[EntityNameTerminator] = factory.NewNestedLink(entity, EntityNameTerminator)
|
|
links[EntityNameService] = factory.NewNestedLink(entity, EntityNameService)
|
|
return links
|
|
}
|
|
|
|
func MapCircuitToRestModel(ae *env.AppEnv, _ *response.RequestContext, circuit *model.Circuit) (interface{}, error) {
|
|
path := &rest_model.Path{}
|
|
for _, node := range circuit.Path.Nodes {
|
|
path.Nodes = append(path.Nodes, ToFabricEntityRef(node.Name, node, FabricRouterLinkFactory))
|
|
}
|
|
for _, link := range circuit.Path.Links {
|
|
path.Links = append(path.Links, ToFabricEntityRef(link.Id, link, LinkLinkFactory))
|
|
}
|
|
|
|
var svcEntityRef *rest_model.EntityRef
|
|
if svc, _ := ae.Managers.Service.Read(circuit.ServiceId); svc != nil {
|
|
svcEntityRef = ToFabricEntityRef(svc.Name, svc, FabricServiceLinkFactory)
|
|
} else {
|
|
svcEntityRef = ToFabricEntityRef("<deleted>", deletedEntity(circuit.ServiceId), FabricServiceLinkFactory)
|
|
}
|
|
|
|
ret := &rest_model.CircuitDetail{
|
|
BaseEntity: FabricEntityToRestModel(circuit, CircuitLinkFactory),
|
|
ClientID: circuit.ClientId,
|
|
Path: path,
|
|
Service: svcEntityRef,
|
|
Terminator: ToFabricEntityRef(circuit.Terminator.GetId(), circuit.Terminator, FabricTerminatorLinkFactory),
|
|
}
|
|
|
|
return ret, nil
|
|
}
|
|
|
|
type deletedEntity string
|
|
|
|
func (self deletedEntity) GetId() string {
|
|
return string(self)
|
|
}
|