summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.go34
-rw-r--r--src/oauth.go8
-rw-r--r--src/server.go6
-rw-r--r--src/state.go10
4 files changed, 47 insertions, 11 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)
+}
diff --git a/src/oauth.go b/src/oauth.go
index 063034b..eb93c00 100644
--- a/src/oauth.go
+++ b/src/oauth.go
@@ -54,9 +54,9 @@ func genVerifier() (string, error) {
}
type OAuth struct {
- Session *OAuthExchangeSession
- Token *OAuthToken
- TokenURL string
+ Session *OAuthExchangeSession `json:"-"`
+ Token *OAuthToken `json:"token"`
+ TokenURL string `json:"token_url"`
}
// This structure gets passed to the callback for easy access to the current state
@@ -85,7 +85,7 @@ type OAuthToken struct {
Refresh string `json:"refresh_token"`
Type string `json:"token_type"`
Expires int64 `json:"expires_in"`
- ExpiredTimestamp int64
+ ExpiredTimestamp int64 `json:"expires_in_timestamp"`
}
// Gets an authenticated HTTP client by obtaining refresh and access tokens
diff --git a/src/server.go b/src/server.go
index 6f809c6..627843f 100644
--- a/src/server.go
+++ b/src/server.go
@@ -5,9 +5,9 @@ import (
)
type Server struct {
- BaseURL string
- Endpoints *ServerEndpoints
- OAuth *OAuth
+ BaseURL string `json:"base_url"`
+ Endpoints *ServerEndpoints `json:"endpoints"`
+ OAuth *OAuth `json:"oauth"`
}
type ServerEndpointList struct {
diff --git a/src/state.go b/src/state.go
index 582dd5a..6f06860 100644
--- a/src/state.go
+++ b/src/state.go
@@ -2,16 +2,18 @@ package eduvpn
type VPNState struct {
// Info passed by the client
- Name string
+ ConfigDirectory string `json:"-"`
+ Name string `json:"-"`
// The chosen server
- Server *Server
+ Server *Server `json:"server"`
}
-func Register(state *VPNState, name string, stateCallback func(string, string)) error {
+func Register(state *VPNState, name string, directory string, stateCallback func(string, string, string)) error {
state.Name = name
+ state.ConfigDirectory = directory
- stateCallback("START", "REGISTER")
+ stateCallback("START", "REGISTERED", "test data")
return nil
}