-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
182 lines (166 loc) · 4.51 KB
/
main.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// ______ _ ______ _ _
// | _ \ | | | _ (_) | |
// | | | |__ _| |_ __ _ | | | |_ ___ __| | ___
// | | | / _` | __/ _` | | | | | |/ _ \ / _` |/ _ \
// | |/ / (_| | || (_| | | |/ /| | (_) | (_| | __/
// |___/ \__,_|\__\__,_| |___/ |_|\___/ \__,_|\___|
package main
import (
"fmt"
"log"
"os"
analysis "github.com/acep-uaf/data-diode/insights"
utility "github.com/acep-uaf/data-diode/utility"
"github.com/urfave/cli/v2"
"gopkg.in/yaml.v2"
)
var (
SemVer string
BuildInfo string
ConfigSettings = "config/settings.yaml"
)
type Configuration struct {
Diode struct {
Input struct {
IP string
Port int
Timeout int
}
Output struct {
IP string
Port int
TLS bool
}
}
MQTT struct {
Inside struct {
Server string
Port int
Topic string
}
Outside struct {
Server string
Port int
Prefix string
}
}
}
func main() {
data, err := os.ReadFile(ConfigSettings)
if err != nil {
panic(err)
}
var config Configuration
if err := yaml.Unmarshal(data, &config); err != nil {
panic(err)
}
// Configuration Settings
diodeInputSideIP := config.Diode.Input.IP
diodePassthroughPort := config.Diode.Input.Port
clientLocation := fmt.Sprintf("%s:%d", diodeInputSideIP, diodePassthroughPort)
targetServerIP := config.Diode.Output.IP
targetServerPort := config.Diode.Output.Port
serverLocation := fmt.Sprintf("%s:%d", targetServerIP, targetServerPort)
subBrokerIP := config.MQTT.Inside.Server
subBrokerPort := config.MQTT.Inside.Port
subBrokerTopic := config.MQTT.Inside.Topic
pubBrokerIP := config.MQTT.Outside.Server
pubBrokerPort := config.MQTT.Outside.Port
pubBrokerTopic := config.MQTT.Outside.Prefix
app := &cli.App{
Name: "diode",
Usage: "Tool for interacting with data diode(s) via command-line interface (CLI).",
Action: func(cCtx *cli.Context) error {
fmt.Println("diode: try 'diode --help' for more information")
return nil
},
Commands: []*cli.Command{
{
Name: "client",
Aliases: []string{"c"},
Usage: "Input side of the data diode",
Action: func(cCtx *cli.Context) error {
fmt.Println("----- INPUT -----")
fmt.Println(">> Client IP: ", diodeInputSideIP)
fmt.Println(">> Client Port: ", diodePassthroughPort)
utility.StartPlaceholderClient(diodeInputSideIP, diodePassthroughPort)
return nil
},
},
{
Name: "server",
Aliases: []string{"s"},
Usage: "Output side of the data diode",
Action: func(sCtx *cli.Context) error {
fmt.Println("----- OUTPUT -----")
fmt.Println(">> Server IP: ", targetServerIP)
fmt.Println(">> Server Port: ", targetServerPort)
utility.StartPlaceholderServer(targetServerIP, targetServerPort)
return nil
},
},
{
Name: "test",
Aliases: []string{"t"},
Usage: "Testing state synchronization via diode I/O",
Action: func(tCtx *cli.Context) error {
fmt.Println("----- TEST -----")
analysis.Pong()
return nil
},
},
{
Name: "diagnostics",
Aliases: []string{"d"},
Usage: "Debug diagnostics via configuration settings",
Action: func(dCtx *cli.Context) error {
fmt.Println("----- DIAGNOSTICS -----")
fmt.Printf("%+v\n", config)
// TODO: Flag for current data diode ACK response.
return nil
},
},
{
Name: "benchmark",
Aliases: []string{"b"},
Usage: "System benchmark analysis + report performance metrics",
Action: func(bCtx *cli.Context) error {
fmt.Println("----- BENCHMARKS -----")
analysis.Saturate()
return nil
},
},
{
Name: "mqtt-subscribe",
Aliases: []string{"ms"},
Usage: "Receive payload, encapsulate message, & stream to diode",
Action: func(msCtx *cli.Context) error {
utility.InboundMessageFlow(subBrokerIP, subBrokerPort, subBrokerTopic, clientLocation)
return nil
},
},
{
Name: "mqtt-publish",
Aliases: []string{"mp"},
Usage: "Detect complete message, decode, & republish the payload",
Action: func(mpCtx *cli.Context) error {
utility.OutboundMessageFlow(pubBrokerIP, pubBrokerPort, pubBrokerTopic, serverLocation)
return nil
},
},
{
Name: "version",
Aliases: []string{"v"},
Usage: "Print the version of the diode CLI",
Action: func(vCtx *cli.Context) error {
fmt.Println(">> diode version:", SemVer)
fmt.Println(">> build information: ", BuildInfo)
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal()
}
}