diff options
| -rw-r--r-- | exports/exports.go | 6 | ||||
| -rw-r--r-- | internal/fsm/fsm.go | 4 | ||||
| -rw-r--r-- | internal/server/server.go | 35 | ||||
| -rw-r--r-- | internal/types/error.go | 10 | ||||
| -rw-r--r-- | internal/types/server.go | 21 | ||||
| -rw-r--r-- | state.go | 1 |
6 files changed, 36 insertions, 41 deletions
diff --git a/exports/exports.go b/exports/exports.go index 6341199..1e17587 100644 --- a/exports/exports.go +++ b/exports/exports.go @@ -14,8 +14,8 @@ void call_callback(PythonCB callback, const char *name, const char* oldstate, co import "C" import ( - "errors" "encoding/json" + "errors" "fmt" "unsafe" @@ -109,7 +109,7 @@ func CancelOAuth(name *C.char) *C.char { } type configJSON struct { - Config string `json:"config"` + Config string `json:"config"` ConfigType string `json:"config_type"` } @@ -205,7 +205,7 @@ func SetSecureLocation(name *C.char, data *C.char) *C.char { } //export GoBack -func GoBack(name *C.char) (*C.char) { +func GoBack(name *C.char) *C.char { nameStr := C.GoString(name) state, stateErr := GetVPNState(nameStr) if stateErr != nil { diff --git a/internal/fsm/fsm.go b/internal/fsm/fsm.go index 162f3ad..47ac938 100644 --- a/internal/fsm/fsm.go +++ b/internal/fsm/fsm.go @@ -109,7 +109,7 @@ type FSMTransition struct { } type ( - FSMStates map[FSMStateID]FSMState + FSMStates map[FSMStateID]FSMState ) type FSMState struct { @@ -144,7 +144,7 @@ func (fsm *FSM) Init(name string, callback func(string, string, string), logger REQUEST_CONFIG: FSMState{Transitions: []FSMTransition{{ASK_PROFILE, "Multiple profiles found and no profile chosen"}, {HAS_CONFIG, "Only one profile or profile already chosen"}, {NO_SERVER, "Cancel or Error"}, {OAUTH_STARTED, "Re-authorize"}}}, ASK_PROFILE: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "User chooses profile"}, {NO_SERVER, "Cancel or Error"}, {SEARCH_SERVER, "Cancel or Error"}}}, HAS_CONFIG: FSMState{Transitions: []FSMTransition{{CONNECTING, "OS reports it is trying to connect"}, {REQUEST_CONFIG, "User chooses a new profile"}, {NO_SERVER, "User wants to choose a new server"}}, BackState: NO_SERVER}, - CONNECTING: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "Cancel or Error"}, {CONNECTED, "Done connecting"}}}, + CONNECTING: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "Cancel or Error"}, {CONNECTED, "Done connecting"}}}, CONNECTED: FSMState{Transitions: []FSMTransition{{HAS_CONFIG, "OS reports disconnected"}}}, } fsm.Current = DEREGISTERED diff --git a/internal/server/server.go b/internal/server/server.go index a34e8ec..f7ebbc3 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -14,16 +14,16 @@ import ( // The base type for servers type ServerBase struct { - URL string `json:"base_url"` - DisplayName map[string]string `json:"display_name"` - SupportContact []string `json:"support_contact"` - Endpoints ServerEndpoints `json:"endpoints"` - Profiles ServerProfileInfo `json:"profiles"` - ProfilesRaw string `json:"profiles_raw"` - StartTime int64 `json:"start_time"` - EndTime int64 `json:"expire_time"` - Logger *log.FileLogger `json:"-"` - FSM *fsm.FSM `json:"-"` + URL string `json:"base_url"` + DisplayName map[string]string `json:"display_name"` + SupportContact []string `json:"support_contact"` + Endpoints ServerEndpoints `json:"endpoints"` + Profiles ServerProfileInfo `json:"profiles"` + ProfilesRaw string `json:"profiles_raw"` + StartTime int64 `json:"start_time"` + EndTime int64 `json:"expire_time"` + Logger *log.FileLogger `json:"-"` + FSM *fsm.FSM `json:"-"` } // An instute access server @@ -38,8 +38,8 @@ type InstituteAccessServer struct { // A secure internet server which has its own OAuth tokens // It specifies the current location url it is connected to type SecureInternetHomeServer struct { - DisplayName map[string]string `json:"display_name"` - OAuth oauth.OAuth `json:"oauth"` + DisplayName map[string]string `json:"display_name"` + OAuth oauth.OAuth `json:"oauth"` // The home server has a list of info for each configured server location BaseMap map[string]*ServerBase `json:"base_map"` @@ -523,17 +523,16 @@ func askForProfileID(server Server) error { } type ServerInfoScreen struct { - DisplayName map[string]string `json:"display_name"` - CountryCode string `json:"country_code,omitempty"` - SupportContact []string `json:"support_contact"` - ProfilesRaw string `json:"profiles"` - ExpireTime int64 `json:"expire_time"` + DisplayName map[string]string `json:"display_name"` + CountryCode string `json:"country_code,omitempty"` + SupportContact []string `json:"support_contact"` + ProfilesRaw string `json:"profiles"` + ExpireTime int64 `json:"expire_time"` } func (servers *Servers) GetCurrentServerInfoJSON() (string, error) { errorMessage := "failed getting JSON for server" - currentServer, currentServerErr := servers.GetCurrentServer() if currentServerErr != nil { return "{}", &types.WrappedErrorMessage{Message: errorMessage, Err: currentServerErr} diff --git a/internal/types/error.go b/internal/types/error.go index e5bd082..4a882e2 100644 --- a/internal/types/error.go +++ b/internal/types/error.go @@ -1,8 +1,8 @@ package types import ( - "errors" "encoding/json" + "errors" "fmt" ) @@ -83,12 +83,11 @@ func GetErrorLevel(err error) ErrorLevel { } type WrappedErrorMessageJSON struct { - Level ErrorLevel `json:"level"` - Cause string `json:"cause"` - Traceback string `json:"traceback"` + Level ErrorLevel `json:"level"` + Cause string `json:"cause"` + Traceback string `json:"traceback"` } - func GetErrorJSONString(err error) string { var wrappedErr *WrappedErrorMessage @@ -106,7 +105,6 @@ func GetErrorJSONString(err error) string { traceback = err.Error() } - json, jsonErr := json.Marshal(&WrappedErrorMessageJSON{Level: level, Cause: cause.Error(), Traceback: traceback}) if jsonErr != nil { diff --git a/internal/types/server.go b/internal/types/server.go index 09bfc92..9e68a5c 100644 --- a/internal/types/server.go +++ b/internal/types/server.go @@ -16,9 +16,9 @@ type DiscoveryOrganizations struct { } type DiscoveryOrganization struct { - DisplayName map[string]string `json:"display_name"` - OrgId string `json:"org_id"` - SecureInternetHome string `json:"secure_internet_home"` + DisplayName map[string]string `json:"display_name"` + OrgId string `json:"org_id"` + SecureInternetHome string `json:"secure_internet_home"` KeywordList struct { En string `json:"en"` } `json:"keyword_list"` @@ -58,13 +58,12 @@ func (DN *DNMapOrString) UnmarshalJSON(data []byte) error { return err } - type DiscoveryServer struct { - AuthenticationURLTemplate string `json:"authentication_url_template"` - BaseURL string `json:"base_url"` - CountryCode string `json:"country_code"` - DisplayName DNMapOrString `json:"display_name,omitempty"` - PublicKeyList []string `json:"public_key_list"` - Type string `json:"server_type"` - SupportContact []string `json:"support_contact"` + AuthenticationURLTemplate string `json:"authentication_url_template"` + BaseURL string `json:"base_url"` + CountryCode string `json:"country_code"` + DisplayName DNMapOrString `json:"display_name,omitempty"` + PublicKeyList []string `json:"public_key_list"` + Type string `json:"server_type"` + SupportContact []string `json:"support_contact"` } @@ -182,7 +182,6 @@ func (state *VPNState) addSecureInternetHomeServer(orgID string) (server.Server, if !state.Servers.HasSecureLocation() { locationErr = state.AskSecureLocation() - } else { // reinitialize locationErr = state.SetSecureLocation(state.Servers.GetSecureLocation()) |
