summaryrefslogtreecommitdiff
path: root/cli/main.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
commitb1d92b395322f2164ccfb44b0f7caebbaece6b62 (patch)
tree2133e4045b4af4d07a98674b7ae3a234670f0305 /cli/main.go
parent3a4ae2942b43923ff98fd2eca8878c3cf145686c (diff)
Refactor: Restructure project
- Add an internal folder where all the internal code lives - Make a state.go and state_test.go for the public interface This gives a more clear separation between functions and modules. It also makes this a more typical Go project setup.
Diffstat (limited to 'cli/main.go')
-rw-r--r--cli/main.go84
1 files changed, 0 insertions, 84 deletions
diff --git a/cli/main.go b/cli/main.go
deleted file mode 100644
index d5c3aa8..0000000
--- a/cli/main.go
+++ /dev/null
@@ -1,84 +0,0 @@
-package main
-
-import (
- "errors"
- "flag"
- "fmt"
- "os"
- "os/exec"
- "strings"
-
- eduvpn "github.com/jwijenbergh/eduvpn-common/src"
-)
-
-func openBrowser(urlString string) {
- fmt.Printf("OAuth: Initialized with AuthURL %s\n", urlString)
- fmt.Println("OAuth: Opening browser with xdg-open...")
- exec.Command("xdg-open", urlString).Start()
-}
-
-func logState(oldState string, newState string, data string) {
- fmt.Printf("State: %s -> State: %s with data %s\n", oldState, newState, data)
-
- if newState == "OAuth_Started" {
- openBrowser(data)
- }
-}
-
-func writeGraph(filename string) error {
- state := eduvpn.GetVPNState()
-
- state.InitializeFSM()
-
- graph := state.GenerateGraph()
-
- f, err := os.Create(filename)
- if err != nil {
- return errors.New(fmt.Sprintf("Failed to create file %s with error %v", filename, err))
- }
-
- defer f.Close()
-
- f.WriteString(graph)
-
- fmt.Printf("Graph written to file: %s, use 'fdp %s -Tsvg > graph.svg' from graphviz to save to a svg file called graph.svg\n", filename, filename)
-
- return nil
-}
-
-func main() {
- fileGraph := flag.String("dumpgraph", "", "Dump the FSM to a graphviz fdp file")
- urlArg := flag.String("url", "", "The url of the vpn")
- flag.Parse()
-
- fileGraphString := *fileGraph
- if fileGraphString != "" {
- writeGraph(fileGraphString)
- return
- }
- urlString := *urlArg
-
- if urlString != "" {
- if !strings.HasPrefix(urlString, "https://") {
- urlString = "https://" + urlString
- }
-
- state := eduvpn.GetVPNState()
-
- state.Register("org.eduvpn.app.linux", "configs", logState, true)
- config, configErr := state.Connect(urlString)
-
- if configErr != nil {
- fmt.Printf("Config error %v", configErr)
- return
- }
-
- fmt.Println(config)
-
- state.Deregister()
-
- return
- }
-
- flag.PrintDefaults()
-}