summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 09:55:19 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 09:55:19 +0200
commit08b5cab875f1a84162bb47773bbe72135135b90e (patch)
tree1228363b956b10b240fe05b13c9d9bb2e79d9bb6
parentc7efec780a9e11e97690a19cf751533279788e79 (diff)
FSM: Make data for transitions optional
-rw-r--r--src/fsm.go6
-rw-r--r--src/oauth.go4
-rw-r--r--src/server.go4
-rw-r--r--src/server_test.go4
-rw-r--r--src/state.go8
5 files changed, 15 insertions, 11 deletions
diff --git a/src/fsm.go b/src/fsm.go
index c51d345..223b42f 100644
--- a/src/fsm.go
+++ b/src/fsm.go
@@ -119,7 +119,7 @@ func (eduvpn *VPNState) writeGraph() {
f.WriteString(graph)
}
-func (eduvpn *VPNState) GoTransition(newState FSMStateID, data string) bool {
+func (eduvpn *VPNState) GoTransitionWithData(newState FSMStateID, data string) bool {
ok := eduvpn.HasTransition(newState)
if ok {
@@ -134,6 +134,10 @@ func (eduvpn *VPNState) GoTransition(newState FSMStateID, data string) bool {
return ok
}
+func (eduvpn *VPNState) GoTransition(newState FSMStateID) bool {
+ return eduvpn.GoTransitionWithData(newState, "")
+}
+
func (eduvpn *VPNState) generateDotGraph() string {
graph := `digraph eduvpn_fsm {
nodesep = 2;
diff --git a/src/oauth.go b/src/oauth.go
index 08ec07e..cb13d19 100644
--- a/src/oauth.go
+++ b/src/oauth.go
@@ -254,7 +254,7 @@ func (eduvpn *VPNState) InitializeOAuth() error {
// Fill the struct with the necessary fields filled for the next call to getting the HTTP client
oauthSession := OAuthExchangeSession{ClientID: eduvpn.Name, State: state, Verifier: verifier}
eduvpn.Server.OAuth = OAuth{TokenURL: eduvpn.Server.Endpoints.API.V3.Token, Session: oauthSession}
- eduvpn.GoTransition(OAUTH_STARTED, authURL)
+ eduvpn.GoTransitionWithData(OAUTH_STARTED, authURL)
return nil
}
@@ -267,7 +267,7 @@ func (eduvpn *VPNState) FinishOAuth() error {
if tokenErr != nil {
return tokenErr
}
- eduvpn.GoTransition(AUTHENTICATED, "")
+ eduvpn.GoTransition(AUTHENTICATED)
return nil
}
diff --git a/src/server.go b/src/server.go
index 7e323f6..f4aab66 100644
--- a/src/server.go
+++ b/src/server.go
@@ -51,7 +51,7 @@ func (server *Server) Initialize(url string) error {
if endpointsErr != nil {
return endpointsErr
}
- GetVPNState().GoTransition(CHOSEN_SERVER, "Chosen server")
+ GetVPNState().GoTransition(CHOSEN_SERVER)
return nil
}
@@ -119,7 +119,7 @@ func (server *Server) askForProfileID() error {
if !GetVPNState().HasTransition(ASK_PROFILE) {
return errors.New("cannot ask for a profile id, invalid state")
}
- GetVPNState().GoTransition(ASK_PROFILE, server.ProfilesRaw)
+ GetVPNState().GoTransitionWithData(ASK_PROFILE, server.ProfilesRaw)
return nil
}
diff --git a/src/server_test.go b/src/server_test.go
index 84da6a3..7081bde 100644
--- a/src/server_test.go
+++ b/src/server_test.go
@@ -179,8 +179,8 @@ func Test_token_invalid(t *testing.T) {
// Fake connect and then back to authenticated so that we can re-authenticate
// Going to authenticated fakes a disconnect
- state.GoTransition(CONNECTED, "")
- state.GoTransition(AUTHENTICATED, "")
+ state.GoTransition(CONNECTED)
+ state.GoTransition(AUTHENTICATED)
dummy_value := "37"
diff --git a/src/state.go b/src/state.go
index 52a4861..e15cb3c 100644
--- a/src/state.go
+++ b/src/state.go
@@ -51,7 +51,7 @@ func (state *VPNState) Register(name string, directory string, stateCallback fun
// This error can be safely ignored, as when the config does not load, the struct will not be filled
state.Log(LOG_INFO, "Previous configuration not found")
}
- state.GoTransition(NO_SERVER, "")
+ state.GoTransition(NO_SERVER)
return nil
}
@@ -87,17 +87,17 @@ func (state *VPNState) Connect(url string) (string, error) {
return "", loginErr
}
} else { // OAuth was valid, ensure we are in the authenticated state
- state.GoTransition(AUTHENTICATED, "")
+ state.GoTransition(AUTHENTICATED)
}
- state.GoTransition(REQUEST_CONFIG, "")
+ state.GoTransition(REQUEST_CONFIG)
config, configErr := state.Server.GetConfig()
if configErr != nil {
return "", configErr
} else {
- state.GoTransition(HAS_CONFIG, "")
+ state.GoTransition(HAS_CONFIG)
}
return config, nil