...
1 package mapper
2
3 import (
4 "encoding/json"
5 "reflect"
6
7 corev1 "k8s.io/api/core/v1"
8 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
10 v1vpnconfig "edge-infra.dev/pkg/sds/remoteaccess/k8s/apis/vpnconfigs/v1"
11
12 "edge-infra.dev/pkg/edge/api/graph/model"
13 "edge-infra.dev/pkg/sds/ien/bootoptions"
14 "edge-infra.dev/pkg/sds/ien/topology"
15 )
16
17 func CreateBootOptionsConfigMap(clusterConfig *model.ClusterConfig) *corev1.ConfigMap {
18 return bootoptions.FromClusterConfig(clusterConfig)
19 }
20
21 func CreateTopologyInfoConfigMap(clusterConfig model.ClusterConfig) *corev1.ConfigMap {
22 tpInfo := &topology.Info{}
23 tpInfo = tpInfo.FromGraphQLModel(clusterConfig)
24 return tpInfo.ToConfigMap()
25 }
26
27 func CreateVPNConfig(cluster *model.Cluster, clusterConfig *model.ClusterConfig) *v1vpnconfig.VPNConfig {
28 return &v1vpnconfig.VPNConfig{
29 TypeMeta: metav1.TypeMeta{
30 Kind: reflect.TypeOf(v1vpnconfig.VPNConfig{}).Name(),
31 APIVersion: v1vpnconfig.GroupVersion.String(),
32 },
33 ObjectMeta: metav1.ObjectMeta{
34 Name: cluster.ClusterEdgeID,
35 Namespace: "vpn",
36 },
37 Spec: v1vpnconfig.VPNConfigSpec{
38 Enabled: clusterConfig.VpnEnabled,
39 },
40 }
41 }
42
43
44 func NLLPToNLL(NLLP []*model.NamespaceLogLevelPayload) []*model.NamespaceLogLevel {
45 NLL := make([]*model.NamespaceLogLevel, len(NLLP))
46
47 if len(NLL) == 0 {
48 return NLL
49 }
50
51 for index, entry := range NLLP {
52 conversion := model.NamespaceLogLevel{
53 Namespace: *entry.Namespace,
54 Level: *entry.Level,
55 }
56 NLL = append(NLL[:index+1], NLL[index:]...)
57 NLL[index] = &conversion
58 }
59
60 return NLL[:(len(NLL) / 2)]
61 }
62
63
64 func NLLPToJSON(NLLP []*model.NamespaceLogLevelPayload) (string, error) {
65
66 if len(NLLP) == 0 {
67 return "[]", nil
68 }
69
70 namespaceLogLevelsJSON, err := json.Marshal(NLLP)
71
72 if err != nil {
73 return "", err
74 }
75
76 return string(namespaceLogLevelsJSON), nil
77 }
78
79
80 func JSONtoNLLP(jsonPayload string) ([]*model.NamespaceLogLevelPayload, error) {
81 var NLLP []*model.NamespaceLogLevelPayload
82 err := json.Unmarshal([]byte(jsonPayload), &NLLP)
83
84 if err != nil {
85 return nil, err
86 }
87
88 return NLLP, nil
89 }
90
91
92 func JSONtoNLL(jsonPayload string) ([]*model.NamespaceLogLevel, error) {
93 var NLL []*model.NamespaceLogLevel
94 err := json.Unmarshal([]byte(jsonPayload), &NLL)
95
96 if err != nil {
97 return nil, err
98 }
99
100 return NLL, nil
101 }
102
View as plain text