summaryrefslogtreecommitdiff
path: root/src/server.go
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-20 14:03:39 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-20 14:03:39 +0200
commit77c9f266553cbadfd5fb150a26c2162b705f151e (patch)
tree5292c7187cd97dac53674ee2baa4138a3eed7e68 /src/server.go
parent5d3818161f635b82e3289e82ac1ab631f726566b (diff)
FSM: More states and fix graph order
Diffstat (limited to 'src/server.go')
-rw-r--r--src/server.go19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/server.go b/src/server.go
index 20d9136..d8afb01 100644
--- a/src/server.go
+++ b/src/server.go
@@ -6,11 +6,11 @@ import (
)
type Server struct {
- BaseURL string `json:"base_url"`
- Endpoints *ServerEndpoints `json:"endpoints"`
- OAuth *OAuth `json:"oauth"`
- Profiles *ServerProfileInfo `json:"profiles"`
- ProfilesRaw string `json:"profiles_raw"`
+ BaseURL string `json:"base_url"`
+ Endpoints *ServerEndpoints `json:"endpoints"`
+ OAuth *OAuth `json:"oauth"`
+ Profiles *ServerProfileInfo `json:"profiles"`
+ ProfilesRaw string `json:"profiles_raw"`
}
type ServerProfile struct {
@@ -104,6 +104,9 @@ func (server *Server) getProfileForID(profile_id string) (*ServerProfile, error)
}
func (server *Server) getConfigWithProfile(profile_id string) (string, error) {
+ if !GetVPNState().HasTransition(HAS_CONFIG) {
+ return "", errors.New("cannot get a config with a profile, invalid state")
+ }
profile, profileErr := server.getProfileForID(profile_id)
if profileErr != nil {
@@ -117,11 +120,17 @@ func (server *Server) getConfigWithProfile(profile_id string) (string, error) {
}
func (server *Server) askForProfileID() (string, error) {
+ if !GetVPNState().HasTransition(ASK_PROFILE) {
+ return "", errors.New("cannot ask for a profile id, invalid state")
+ }
_, profile_id := GetVPNState().GoTransition(ASK_PROFILE, server.ProfilesRaw)
return profile_id, nil
}
func (server *Server) GetConfig() (string, error) {
+ if !GetVPNState().InState(REQUEST_CONFIG) {
+ return "", errors.New("cannot get a config, invalid state")
+ }
infoErr := server.APIInfo()
if infoErr != nil {