generated from meshery/meshery-istio
-
Notifications
You must be signed in to change notification settings - Fork 50
/
register.go
71 lines (60 loc) · 1.86 KB
/
register.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
package oam
import (
"fmt"
"os"
"path/filepath"
"strconv"
"sync"
"github.com/layer5io/meshery-adapter-library/adapter"
"github.com/layer5io/meshkit/models/meshmodel/core/types"
)
var (
basePath, _ = os.Getwd()
MeshmodelComponents = filepath.Join(basePath, "templates", "meshmodel", "components")
)
// AvailableVersions denote the component versions available statically
var AvailableVersions = map[string]bool{}
var availableVersionGlobalMutex sync.Mutex
type meshmodelDefinitionPathSet struct {
meshmodelDefinitionPath string
}
func RegisterMeshModelComponents(uuid, runtime, host, port string) error {
meshmodelRDP := []adapter.MeshModelRegistrantDefinitionPath{}
pathSets, err := loadMeshmodelComponents(MeshmodelComponents)
if err != nil {
return err
}
portint, _ := strconv.Atoi(port)
for _, pathSet := range pathSets {
meshmodelRDP = append(meshmodelRDP, adapter.MeshModelRegistrantDefinitionPath{
EntityDefintionPath: pathSet.meshmodelDefinitionPath,
Host: host,
Port: portint,
Type: types.ComponentDefinition,
})
}
return adapter.
NewMeshModelRegistrant(meshmodelRDP, fmt.Sprintf("%s/api/meshmodel/components/register", runtime)).
Register(uuid)
}
func loadMeshmodelComponents(basepath string) ([]meshmodelDefinitionPathSet, error) {
res := []meshmodelDefinitionPathSet{}
if err := filepath.Walk(basepath, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
}
res = append(res, meshmodelDefinitionPathSet{
meshmodelDefinitionPath: path,
})
availableVersionGlobalMutex.Lock()
AvailableVersions[filepath.Base(filepath.Dir(path))] = true // Getting available versions already existing on file system
availableVersionGlobalMutex.Unlock()
return nil
}); err != nil {
return nil, err
}
return res, nil
}