Пример #1
0
def refresh():
    """
    Refreshes an active configuration. The token is refreshed if expired, and a new token is obtained if the token
    is invalid.
    """
    uuid, auth_url, metadata = get_storage(check=True)
    token, token_endpoint, auth_endpoint, api_url, display_name, support_contact, profile_id, con_type, country_id, _, _ = metadata
    oauth = OAuth2Session(client_id=CLIENT_ID,
                          token=token,
                          auto_refresh_url=token_endpoint)

    try:
        token = oauth.refresh_token(token_url=token_endpoint)
    except InvalidGrantError as e:
        _logger.warning(f"token invalid: {e}")
        oauth = oauth2.run_challenge(token_endpoint, auth_endpoint)

    api_base_uri, token_endpoint, auth_endpoint = get_info(auth_url)
    client = get_client()
    try:
        cert, key = get_cert_key(client, uuid)
    except IOError:
        # probably the NM connection was deleted
        cert = None

    if not cert or not check_certificate(oauth, api_base_uri, cert):
        key, cert = create_keypair(oauth, api_base_uri)
        config = get_config(oauth, api_base_uri, profile_id)
        save_connection_with_mainloop(config, key, cert)

    update_token(token)
Пример #2
0
def status():
    uuid, current_auth_url, metadata = get_storage(check=False)

    print("\n\n# Global configuration\n")
    print(f"uuid: {uuid}")
    print(f"auth_url: {current_auth_url}")

    if nm_available():
        active_uuid, status = connection_status(get_client())
        print(f"VPN connection active: {bool(active_uuid)}")
        print(f"VPN NM status is: {status}")
        print(f"Active VPN connection is EduVPN: {bool(uuid == active_uuid)}")

    print("\n\n## Previous connection properties\n")

    for auth_url, props in get_all_metadatas().items():
        if auth_url == current_auth_url:
            print(" ** CURRENT ACTIVE CONFIGURATION **")
        print(f"auth_url {auth_url}")
        for t in [
                'api_url', 'display_name', 'support_contact', 'profile_id',
                'token_endpoint', 'authorization_endpoint', 'con_type',
                'country_id'
        ]:
            print(f"{t}: {props[t]}")
        print(f"token.token_type: {props['token']['token_type']}")
        print(f"token.expires_in: {props['token']['expires_in']}")
        print(f"token.expires_at: {props['token']['expires_at']}")
        print("\n\n")
Пример #3
0
 def test_activate_connection(self):
     get_client()
     get_uuid()
Пример #4
0
 def test_get_add_connection(self):
     client = get_client()
     ovpn = Ovpn.parse(mock_config)
     simple_connection = import_ovpn(ovpn)
     add_connection(client, simple_connection)
Пример #5
0
 def test_activate_connection(self):
     client = get_client()
     uuid = get_uuid()
Пример #6
0
 def test_get_add_connection(self):
     client = get_client()
     simple_connection = import_ovpn(mock_config, mock_key, mock_cert)
     add_connection(client, simple_connection)