summaryrefslogtreecommitdiff
path: root/src/config.go
diff options
context:
space:
mode:
authorJeroen Wijenbergh <jeroenwijenbergh@protonmail.com>2022-03-21 17:16:28 +0100
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-03-21 17:16:28 +0100
commit324202a50e440cac36a756d6a2628ebadd2f8d70 (patch)
tree10381dc1e490eddb3b446a8f3ce599493f87d26d /src/config.go
parentfc56f8770923ec1997444a8318a18be0a8397520 (diff)
Update python and add basic config support
Diffstat (limited to 'src/config.go')
-rw-r--r--src/config.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/config.go b/src/config.go
new file mode 100644
index 0000000..0b7c1c7
--- /dev/null
+++ b/src/config.go
@@ -0,0 +1,34 @@
+package eduvpn
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "os"
+ "path"
+)
+
+func (eduvpn *VPNState) GetConfigName() string {
+ pathString := path.Join(eduvpn.ConfigDirectory, eduvpn.Name)
+ return fmt.Sprintf("%s.json", pathString)
+}
+
+func (eduvpn *VPNState) WriteConfig() error {
+ mkdirErr := os.MkdirAll(eduvpn.ConfigDirectory, os.ModePerm)
+ if mkdirErr != nil {
+ return mkdirErr
+ }
+ jsonString, marshalErr := json.Marshal(eduvpn)
+ if marshalErr != nil {
+ return marshalErr
+ }
+ return ioutil.WriteFile(eduvpn.GetConfigName(), jsonString, 0644)
+}
+
+func (eduvpn *VPNState) LoadConfig() error {
+ bytes, readErr := ioutil.ReadFile(eduvpn.GetConfigName())
+ if readErr != nil {
+ return readErr
+ }
+ return json.Unmarshal(bytes, eduvpn)
+}