def main(): logging.basicConfig(level=logging.INFO) search_term = parse_args() verifier = make_verifier(Ed25519_PUBLIC_KEY) if isinstance(search_term, str) and search_term.lower().startswith('https://'): base_url = search_term info_url = base_url else: servers = list_servers(SERVER_URI, verifier=verifier) secure_internet = [ s for s in servers if s['server_type'] == 'secure_internet' ] institute_access = [ s for s in servers if s['server_type'] == 'institute_access' ] orgs = list_orgs(ORGANISATION_URI, verifier=verifier) choice = menu(institutes=institute_access, orgs=orgs, search_term=search_term) if not choice: exit(1) type_, base_url = choice if type_ == 'secure_internet_home': secure_internets = [ s for s in secure_internet if s['base_url'] == base_url ] info_url = secure_internet_choice(secure_internets) else: info_url = base_url exists = get_entry(base_url) if exists: token, api_base_uri, token_endpoint, authorization_endpoint = exists oauth = OAuth2Session(client_id=CLIENT_ID, token=token, auto_refresh_url=token_endpoint) else: api_base_uri, token_endpoint, auth_endpoint = get_info( info_url, verifier) oauth = get_oauth(token_endpoint, auth_endpoint) set_entry(base_url, oauth.token, api_base_uri, token_endpoint, auth_endpoint) oauth.refresh_token(token_url=token_endpoint) profiles = list_profiles(oauth, api_base_uri) profile_id = profile_choice(profiles) config = get_config(oauth, api_base_uri, profile_id) private_key, certificate = create_keypair(oauth, api_base_uri) if write_to_nm_choice(): save_connection(config, private_key, certificate) else: target = Path('eduVPN.ovpn').resolve() print(f"Writing configuration to {target}") write_config(config, private_key, certificate, target)
def get_profile(oauth: OAuth2Session, api_url: str, interactive: bool = False): profiles = list_profiles(oauth, api_url) if interactive: return profile_choice(profiles) else: return profile_choice(profiles[:1])
def test_profile_choice(self): profiles = [{'profile_id': 'internet'}] profile_choice(profiles=profiles)