summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exports/disco.go20
-rw-r--r--exports/servers.go8
-rw-r--r--wrappers/python/src/__init__.py10
-rw-r--r--wrappers/python/src/main.py21
4 files changed, 28 insertions, 31 deletions
diff --git a/exports/disco.go b/exports/disco.go
index e28fb01..73bc1ac 100644
--- a/exports/disco.go
+++ b/exports/disco.go
@@ -168,17 +168,15 @@ func FreeDiscoOrganizations(cOrganizations *C.discoveryOrganizations) {
}
//export GetDiscoServers
-func GetDiscoServers(name *C.char) *C.discoveryServers {
+func GetDiscoServers(name *C.char) (*C.discoveryServers, *C.char) {
nameStr := C.GoString(name)
state, stateErr := GetVPNState(nameStr)
- // TODO
if stateErr != nil {
- panic(stateErr)
+ return nil, C.CString(ErrorToString(stateErr))
}
servers, serversErr := state.GetDiscoServers()
- // TODO
if serversErr != nil {
- panic(serversErr)
+ return nil, C.CString(ErrorToString(serversErr))
}
returnedStruct := (*C.discoveryServers)(
@@ -189,21 +187,19 @@ func GetDiscoServers(name *C.char) *C.discoveryServers {
state,
servers,
)
- return returnedStruct
+ return returnedStruct, nil
}
//export GetDiscoOrganizations
-func GetDiscoOrganizations(name *C.char) *C.discoveryOrganizations {
+func GetDiscoOrganizations(name *C.char) (*C.discoveryOrganizations, *C.char) {
nameStr := C.GoString(name)
state, stateErr := GetVPNState(nameStr)
- // TODO
if stateErr != nil {
- panic(stateErr)
+ return nil, C.CString(ErrorToString(stateErr))
}
organizations, organizationsErr := state.GetDiscoOrganizations()
- // TODO
if organizationsErr != nil {
- panic(organizationsErr)
+ return nil, C.CString(ErrorToString(organizationsErr))
}
returnedStruct := (*C.discoveryOrganizations)(
@@ -216,5 +212,5 @@ func GetDiscoOrganizations(name *C.char) *C.discoveryOrganizations {
organizations,
)
- return returnedStruct
+ return returnedStruct, nil
}
diff --git a/exports/servers.go b/exports/servers.go
index e5c9301..a487176 100644
--- a/exports/servers.go
+++ b/exports/servers.go
@@ -293,14 +293,14 @@ func getSavedServersWithOptions(state *eduvpn.VPNState, servers *server.Servers)
//export GetSavedServers
// This function takes the name as input which is the name of the client
// It gets the state by name and then returns the saved servers as a c struct belonging to it
-func GetSavedServers(name *C.char) *C.servers {
+func GetSavedServers(name *C.char) (*C.servers, *C.char) {
nameStr := C.GoString(name)
state, stateErr := GetVPNState(nameStr)
if stateErr != nil {
- // TODO: Remove this panic
- panic(stateErr)
+ return nil, C.CString(ErrorToString(stateErr))
}
- return getSavedServersWithOptions(state, &state.Servers)
+ servers := getSavedServersWithOptions(state, &state.Servers)
+ return servers, nil
}
// This function takes the state as input which is the main state
diff --git a/wrappers/python/src/__init__.py b/wrappers/python/src/__init__.py
index ca07143..3bafc0e 100644
--- a/wrappers/python/src/__init__.py
+++ b/wrappers/python/src/__init__.py
@@ -169,8 +169,8 @@ lib.Register.argtypes, lib.Register.restype = [
], c_void_p
lib.GetDiscoOrganizations.argtypes, lib.GetDiscoOrganizations.restype = [
c_char_p
-], c_void_p
-lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], c_void_p
+], DataError
+lib.GetDiscoServers.argtypes, lib.GetDiscoServers.restype = [c_char_p], DataError
lib.GoBack.argtypes, lib.GoBack.restype = [c_char_p], None
lib.CancelOAuth.argtypes, lib.CancelOAuth.restype = [c_char_p], c_void_p
lib.SetProfileID.argtypes, lib.SetProfileID.restype = [c_char_p, c_char_p], c_void_p
@@ -198,7 +198,7 @@ lib.FreeDiscoServers.argtypes, lib.FreeDiscoServers.restype = [c_void_p], None
lib.FreeServer.argtypes, lib.FreeServer.restype = [c_void_p], None
lib.FreeServers.argtypes, lib.FreeServers.restype = [c_void_p], None
lib.InFSMState.argtypes, lib.InFSMState.restype = [c_void_p, c_int], int
-lib.GetSavedServers.argtypes, lib.GetSavedServers.restype = [c_char_p], c_void_p
+lib.GetSavedServers.argtypes, lib.GetSavedServers.restype = [c_char_p], DataError
class WrappedError:
@@ -269,8 +269,8 @@ def get_error(ptr: c_void_p) -> str:
return error.cause
-def get_data_error(data_error: DataError) -> Tuple[str, str]:
- data = get_ptr_string(data_error.data)
+def get_data_error(data_error: DataError, data_conv=get_ptr_string) -> Tuple[str, str]:
+ data = data_conv(data_error.data)
error = get_error(data_error.error)
return data, error
diff --git a/wrappers/python/src/main.py b/wrappers/python/src/main.py
index eaf81e8..1ee9dd7 100644
--- a/wrappers/python/src/main.py
+++ b/wrappers/python/src/main.py
@@ -1,4 +1,4 @@
-from . import lib, VPNStateChange, encode_args, decode_res
+from . import lib, VPNStateChange, encode_args, decode_res, get_data_error
from typing import Optional, Tuple
import threading
from .discovery import get_disco_organizations, get_disco_servers
@@ -88,21 +88,22 @@ class EduVPN(object):
raise Exception(register_err)
def get_disco_servers(self) -> str:
- servers = self.go_function_custom_decode(
- lib.GetDiscoServers, decode_func=get_disco_servers
+ servers, servers_err = self.go_function_custom_decode(
+ lib.GetDiscoServers, decode_func=lambda x: get_data_error(x, get_disco_servers)
)
- # if servers_err:
- # raise Exception(servers_err)
+ if servers_err:
+ raise Exception(servers_err)
return servers
def get_disco_organizations(self) -> str:
- organizations = self.go_function_custom_decode(
- lib.GetDiscoOrganizations, decode_func=get_disco_organizations
+ organizations, organizations_err = self.go_function_custom_decode(
+ lib.GetDiscoOrganizations, decode_func=lambda x: get_data_error(x, get_disco_organizations)
)
- # if organizations_err:
- # raise Exception(organizations_err)
+
+ if organizations_err:
+ raise Exception(organizations_err)
return organizations
@@ -253,5 +254,5 @@ class EduVPN(object):
def get_saved_servers(self) -> str:
return self.go_function_custom_decode(
- lib.GetSavedServers, decode_func=get_servers
+ lib.GetSavedServers, decode_func=lambda x: get_data_error(x, get_servers)
)