From 42d2350e4a5d7a5bfb204bdc0994a0c283208fe7 Mon Sep 17 00:00:00 2001 From: Jeroen Wijenbergh Date: Tue, 19 Apr 2022 12:56:57 +0200 Subject: Config: Only write on deregister --- src/api.go | 2 +- src/discovery.go | 2 -- src/oauth.go | 6 +----- src/state.go | 4 ++++ 4 files changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/api.go b/src/api.go index 76631b1..1f058fc 100644 --- a/src/api.go +++ b/src/api.go @@ -16,7 +16,7 @@ func (server *Server) apiAuthenticated(method string, endpoint string, opts *HTT } url := server.Endpoints.API.V3.API + endpoint - // Ensure we have non-expired tokens + // Ensure we have valid tokens oauthErr := server.OAuth.EnsureTokens() if oauthErr != nil { diff --git a/src/discovery.go b/src/discovery.go index e88d74e..4498779 100644 --- a/src/discovery.go +++ b/src/discovery.go @@ -107,7 +107,6 @@ func (eduvpn *VPNState) GetOrganizationsList() (string, error) { } eduvpn.EnsureDisco() eduvpn.DiscoList.Organizations = &body - eduvpn.WriteConfig() return body, nil } @@ -123,6 +122,5 @@ func (eduvpn *VPNState) GetServersList() (string, error) { } eduvpn.EnsureDisco() eduvpn.DiscoList.Servers = &body - eduvpn.WriteConfig() return body, nil } diff --git a/src/oauth.go b/src/oauth.go index eb4e13f..831fa0f 100644 --- a/src/oauth.go +++ b/src/oauth.go @@ -292,15 +292,11 @@ func (state *VPNState) LoginOAuth() error { if oauthErr != nil { return oauthErr } - - state.WriteConfig() return nil } func (oauth *OAuth) Login() error { - // FIXME: Find a better way - state := GetVPNState() - return state.LoginOAuth() + return GetVPNState().LoginOAuth() } func (oauth *OAuth) NeedsRelogin() bool { diff --git a/src/state.go b/src/state.go index 23bc1cd..1eb8ebd 100644 --- a/src/state.go +++ b/src/state.go @@ -61,6 +61,10 @@ func (state *VPNState) Deregister() error { // Close the log file state.CloseLog() + // Write the config + state.WriteConfig() + + // Re-initialize the server and FSM state.Server = &Server{} state.InitializeFSM() return nil -- cgit v1.2.3