summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-05-09 14:29:30 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-05-09 14:29:30 +0200
commitccac217fedaa83b530c37d573f422003f7af5a6d (patch)
treefd5ae6f942b9b61ecf5e8e73c70835fd7691a416
parent1ef27cc47ad56a2c66aaa40e398a0063be2573d4 (diff)
CMD: Do not create a new state after every config retrieval
-rw-r--r--cmd/cli/main.go23
1 files changed, 13 insertions, 10 deletions
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
index 10a4b29..31d2035 100644
--- a/cmd/cli/main.go
+++ b/cmd/cli/main.go
@@ -82,17 +82,10 @@ func stateCallback(state *eduvpn.VPNState, oldState string, newState string, dat
}
}
-func getConfig(url string, isInstitute bool) (string, error) {
+func getConfig(state *eduvpn.VPNState, url string, isInstitute bool) (string, error) {
if !strings.HasPrefix(url, "https://") {
url = "https://" + url
}
- state := &eduvpn.VPNState{}
- state.Register("org.eduvpn.app.linux", "configs", func(old string, new string, data string) {
- stateCallback(state, old, new, data)
- }, false)
-
- defer state.Deregister()
-
if isInstitute {
return state.GetConfigInstituteAccess(url, false)
}
@@ -129,7 +122,7 @@ func storeSecureInternetConfig(state *eduvpn.VPNState, url string, directory str
fmt.Println("Creating and storing cert for", url)
- config, configErr := getConfig(url, false)
+ config, configErr := getConfig(state, url, false)
if configErr != nil {
fmt.Printf("Failed obtaining config for url %s with error %v\n", url, configErr)
@@ -151,6 +144,8 @@ func getSecureInternetAll(homeURL string) {
stateCallback(state, old, new, data)
}, false)
+ defer state.Deregister()
+
// Get the disco servers
servers, serversErr := state.GetDiscoServers()
@@ -183,7 +178,15 @@ func getSecureInternetAll(homeURL string) {
}
func printConfig(url string, isInstitute bool) {
- config, configErr := getConfig(url, isInstitute)
+ state := &eduvpn.VPNState{}
+
+ state.Register("org.eduvpn.app.linux", "configs", func(old string, new string, data string) {
+ stateCallback(state, old, new, data)
+ }, false)
+
+ defer state.Deregister()
+
+ config, configErr := getConfig(state, url, isInstitute)
if configErr != nil {
fmt.Println("Error getting config", configErr)