-
Notifications
You must be signed in to change notification settings - Fork 2
/
gateway_name_parser.go
84 lines (70 loc) · 2.14 KB
/
gateway_name_parser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package provider
import (
"fmt"
"strconv"
"github.com/threefoldtech/tfgrid-sdk-go/grid-client/workloads"
"github.com/threefoldtech/zos/pkg/gridtypes/zos"
)
func parseToGWNameState(gw workloads.GatewayNameProxy) GatewayNameState {
// parse backends
backends := make([]string, len(gw.Backends))
for idx, b := range gw.Backends {
backends[idx] = string(b)
}
// parse NodeDeploymentID
nodeDeploymentID := make(map[string]int64)
for nodeID, deploymentID := range gw.NodeDeploymentID {
nodeDeploymentID[fmt.Sprint(nodeID)] = int64(deploymentID)
}
return GatewayNameState{
GatewayNameArgs: GatewayNameArgs{
Name: gw.Name,
NodeID: int32(gw.NodeID),
Backends: backends,
TLSPassthrough: gw.TLSPassthrough,
Network: gw.Network,
Description: gw.Description,
SolutionType: gw.SolutionType,
},
NodeDeploymentID: nodeDeploymentID,
FQDN: gw.FQDN,
NameContractID: int64(gw.NameContractID),
ContractID: int64(gw.ContractID),
}
}
func parseToGWName(gwArgs GatewayNameArgs) (workloads.GatewayNameProxy, error) {
// parse backends
backends := make([]zos.Backend, len(gwArgs.Backends))
for idx, b := range gwArgs.Backends {
backends[idx] = zos.Backend(b)
}
nodeID, err := strconv.Atoi(fmt.Sprint(gwArgs.NodeID))
if err != nil {
return workloads.GatewayNameProxy{}, err
}
return workloads.GatewayNameProxy{
Name: gwArgs.Name,
NodeID: uint32(nodeID),
Backends: backends,
TLSPassthrough: gwArgs.TLSPassthrough,
Network: gwArgs.Network,
Description: gwArgs.Description,
SolutionType: gwArgs.SolutionType,
}, nil
}
func updateGWNameFromState(gw *workloads.GatewayNameProxy, state GatewayNameState) error {
// parse NodeDeploymentID
nodeDeploymentID := make(map[uint32]uint64)
for nodeID, deploymentID := range state.NodeDeploymentID {
node, err := strconv.Atoi(nodeID)
if err != nil {
return err
}
nodeDeploymentID[uint32(node)] = uint64(deploymentID)
}
gw.NodeDeploymentID = nodeDeploymentID
gw.FQDN = state.FQDN
gw.NameContractID = uint64(state.NameContractID)
gw.ContractID = uint64(state.ContractID)
return nil
}