Newer
Older
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
package main
import (
"flag"
"fmt"
"net"
"os"
"path/filepath"
pb "code.fbi.h-da.de/danet/gosdn/api/go/gosdn/plugin-registry"
"code.fbi.h-da.de/danet/gosdn/controller/interfaces/plugin"
"github.com/google/uuid"
"google.golang.org/grpc"
)
const (
pluginFilePath = "plugins"
pluginName = "bundled_plugin.zip"
)
func main() {
socket := flag.String("socket", "9000", "port for the grpc socket, e.g. 9000")
flag.Parse()
lislisten, err := net.Listen("tcp", fmt.Sprintf(":%s", *socket))
if err != nil {
panic(err)
}
pr := registerPlugins()
grpcServer := grpc.NewServer()
server := NewServer(pr)
pb.RegisterPluginRegistryServiceServer(grpcServer, server)
if err := grpcServer.Serve(lislisten); err != nil {
panic(err)
}
}
// TODO: The registration of plugins should result in the same UUID's even
// after reboot. Therefore it would make sense to use a database. For a simple
// prototype this is currently hardcoded.
func registerPlugins() *PluginRegistry {
files, err := os.ReadDir(pluginFilePath)
if err != nil {
panic(err)
}
pr := &PluginRegistry{}
for i, file := range files {
fmt.Printf("File %+v\n", file)
if file.IsDir() {
manifest, err := plugin.ReadManifestFromFile(filepath.Join(pluginFilePath, file.Name()))
if err != nil {
panic(err)
}
var id uuid.UUID
switch i {
case 0:
id = uuid.MustParse("e2c358b3-6482-4010-b0d8-679dff73153b")
case 1:
id = uuid.MustParse("d1c269a2-6482-4010-b0d8-679dff73153b")
case 2:
id = uuid.MustParse("f3b474c2-6482-4010-b0d8-679dff73153b")
default:
break
}
plugin := &Plugin{
ID: id,
Path: filepath.Join(pluginFilePath, file.Name(), pluginName),
Manifest: manifest,
}
pr.Plugins = append(pr.Plugins, plugin)
}
}
return pr
}