diff options
| author | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-14 13:56:49 +0200 |
|---|---|---|
| committer | jwijenbergh <jeroenwijenbergh@protonmail.com> | 2022-09-14 13:56:49 +0200 |
| commit | da83f54606c9c1d2786d87074ee17ed972d2e1b2 (patch) | |
| tree | 0be57934f9f467c87576abb0b457fb54b2d25d52 /wrappers/python/main.py | |
| parent | fd34e72da8c604517050ada7e883ba982829d985 (diff) | |
Refactor: Return without json
Diffstat (limited to 'wrappers/python/main.py')
| -rw-r--r-- | wrappers/python/main.py | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/wrappers/python/main.py b/wrappers/python/main.py index 1ab29cc..0bd2502 100644 --- a/wrappers/python/main.py +++ b/wrappers/python/main.py @@ -3,6 +3,8 @@ from eduvpn_common.state import State, StateType import webbrowser import json import sys +import time +from typing import List # Asks the user for a profile index # It loops up until a valid input is given @@ -27,6 +29,11 @@ def ask_profile_input(total: int) -> int: # Sets up the callbacks using the provided class def setup_callbacks(_eduvpn: eduvpn.EduVPN) -> None: # The callback that starst OAuth + @_eduvpn.event.on(State.NO_SERVER, StateType.Enter) + def no_server(old_state: str, servers) -> None: + for server in servers: + print(type(server)) + print(server) # It needs to open the URL in the web browser @_eduvpn.event.on(State.OAUTH_STARTED, StateType.Enter) def oauth_initialized(old_state: str, url: str) -> None: @@ -34,31 +41,30 @@ def setup_callbacks(_eduvpn: eduvpn.EduVPN) -> None: webbrowser.open(url) @_eduvpn.event.on(State.ASK_LOCATION, StateType.Enter) - def ask_location(old_state: str, locations: str): - print("Locations: ", locations) - _eduvpn.set_secure_location("NL") + def ask_location(old_state: str, locations: List[str]): + _eduvpn.set_secure_location(locations[1]) - # The callback which asks the user for a profile - @_eduvpn.event.on(State.ASK_PROFILE, StateType.Enter) - def ask_profile(old_state: str, profiles: str): - print("Multiple profiles found, you need to select a profile:") + ## The callback which asks the user for a profile + #@_eduvpn.event.on(State.ASK_PROFILE, StateType.Enter) + #def ask_profile(old_state: str, profiles: str): + # print("Multiple profiles found, you need to select a profile:") - # Parse the profiles as JSON - data = json.loads(profiles) + # # Parse the profiles as JSON + # data = json.loads(profiles) - # Get a lits of profiles - profile_strings = [x["profile_id"] for x in data["info"]["profile_list"]] - total_profiles = len(profile_strings) + # # Get a lits of profiles + # profile_strings = [x["profile_id"] for x in data["info"]["profile_list"]] + # total_profiles = len(profile_strings) - # Create a list of the strings to standard output - for idx, profile in enumerate(profile_strings): - print(f"{idx+1}. {profile}") + # # Create a list of the strings to standard output + # for idx, profile in enumerate(profile_strings): + # print(f"{idx+1}. {profile}") - # Get the profile index from the user - profile_index = ask_profile_input(total_profiles) + # # Get the profile index from the user + # profile_index = ask_profile_input(total_profiles) - # Set the profile with the index - _eduvpn.set_profile(profile_strings[profile_index]) + # # Set the profile with the index + # _eduvpn.set_profile(profile_strings[profile_index]) # The main entry point @@ -72,18 +78,13 @@ if __name__ == "__main__": except Exception as e: print("Failed registering:", e) - server = input( - "Which server (Custom/Institute Access) do you want to connect to? (e.g. https://eduvpn.example.com): " - ) - - # Ensure we have a valid http prefix - if not server.startswith("http"): - # https by default - server = "https://" + server + #server = input( + # "Which server (Custom/Institute Access) do you want to connect to? (e.g. https://eduvpn.example.com): " + #) # Get a Wireguard/OpenVPN config try: - config, config_type = _eduvpn.get_config_custom_server(server) + config, config_type = _eduvpn.get_config_secure_internet("https://idp.geant.org") print(f"Got a config with type: {config_type} and contents:\n{config}") except Exception as e: print("Failed to connect:", e) |
