Skip to content

Commit

Permalink
Merge branch 'issue-174' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
wjhpeters authored Oct 8, 2019
2 parents f57241d + fec3769 commit 787297b
Show file tree
Hide file tree
Showing 21 changed files with 58 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ deploy:
on:
tags: true
distributions: sdist bdist_wheel
repo: wjhpeters/tmp
repo: eduvpn/python-eduvpn-client
notifications:
email:
on_fail: always
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ You can find the documentation on [http://python-eduvpn-client.readthedocs.io](h
Development
===========

[![Build Status](https://travis-ci.org/wjhpeters/tmp.svg?branch=master)](https://travis-ci.org/wjhpeters/tmp)
[![Build Status](https://travis-ci.org/eduvpn/python-eduvpn-client.svg?branch=master)](https://travis-ci.org/eduvpn/python-eduvpn-client)
3 changes: 1 addition & 2 deletions eduvpn/actions/activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import logging
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk
from eduvpn.util import error_helper, thread_helper
from eduvpn.oauth2 import oauth_from_token
Expand All @@ -20,8 +21,6 @@
from eduvpn.metadata import Metadata
from typing import Any, Union, List


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion eduvpn/actions/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
from eduvpn.steps.instance import fetch_instance_step
from eduvpn.steps.custom_url import custom_url
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion eduvpn/actions/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@

import logging
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, GLib
from eduvpn.manager import delete_provider
from eduvpn.notify import notify, init_notify
from eduvpn.util import error_helper, metadata_of_selected
from eduvpn.steps.start import refresh_start


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion eduvpn/actions/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
from eduvpn.steps.messages import fetch_messages
from eduvpn.brand import get_brand
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from eduvpn.metadata import Metadata
from typing import Optional

gi.require_version('Gtk', '3.0')

logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion eduvpn/actions/switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import logging
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk
from eduvpn.notify import notify, init_notify
from eduvpn.actions.activate import activate_connection
Expand All @@ -13,7 +14,6 @@
from eduvpn.metadata import Metadata


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion eduvpn/actions/vpn_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import logging
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gtk
from eduvpn.notify import notify, init_notify
from eduvpn.manager import list_active
from eduvpn.util import metadata_of_selected
from typing import Optional

gi.require_version('Gtk', '3.0')

logger = logging.getLogger(__name__)


Expand Down
7 changes: 6 additions & 1 deletion eduvpn/brand.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@


def get_brand(lets_connect): # type: (bool) -> Tuple[str, str]
"""Returns the name for the app currently in use."""
"""
args:
lets_connect (bool): Let's connect mode?
returns:
(str, str): logo, name
"""
if lets_connect:
return lets_connect_main_logo, lets_connect_name
else:
Expand Down
36 changes: 12 additions & 24 deletions eduvpn/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import logging
import gi
gi.require_version('Gtk', '3.0')
from os import geteuid
from sys import exit
from gi.repository import GObject, Gtk
Expand All @@ -14,7 +15,6 @@
from eduvpn import config
from typing import Tuple
from eduvpn.ui import EduVpnApp
gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)
log_format = format_ = '%(asctime)s - %(levelname)s - %(name)s - %(message)s'

Expand All @@ -23,18 +23,13 @@ def parse_args(): # type: () -> Tuple[int, str, str, str, bool]
"""
Parses command line arguments:
returns:
(logging level (int), secure internet uri (str),
institute access uri (str), verify key (str))
(logging level (int), secure internet uri (str), institute access uri (str), verify key (str))
"""
parser = ArgumentParser()
parser.add_argument('-d', '--debug', action='store_true',
help="enable debug logging")
parser.add_argument('-v', '--version', action='store_true',
help="print version and exit")
parser.add_argument('-t', '--test', action='store_true',
help="use test discovery servers")
parser.add_argument('-l', '--lets_connect', action='store_true',
help="Enable 'Let's Connect!' mode")
parser.add_argument('-d', '--debug', action='store_true', help="enable debug logging")
parser.add_argument('-v', '--version', action='store_true', help="print version and exit")
parser.add_argument('-t', '--test', action='store_true', help="use test discovery servers")
parser.add_argument('-l', '--lets_connect', action='store_true', help="Enable 'Let's Connect!' mode")
args = parser.parse_args()

if args.version:
Expand All @@ -50,23 +45,16 @@ def parse_args(): # type: () -> Tuple[int, str, str, str, bool]

if args.test:
logger.warning("using test discovery URLs")
return (level, config.secure_internet_uri_dev,
config.institute_access_uri_dev,
config.verify_key_dev,
args.lets_connect)
return (level, config.secure_internet_uri_dev, config.institute_access_uri_dev,
config.verify_key_dev, args.lets_connect)
else:
logger.debug("using production discovery URLs")
return (level, config.secure_internet_uri,
config.institute_access_uri,
config.verify_key,
args.lets_connect)
return (level, config.secure_internet_uri, config.institute_access_uri,
config.verify_key, args.lets_connect)


def init(lets_connect):
# type: (bool) -> EduVpnApp
(level, secure_internet_uri,
institute_access_uri, verify_key,
lets_connect_arg) = parse_args()
def init(lets_connect): # type: (bool) -> EduVpnApp
(level, secure_internet_uri, institute_access_uri, verify_key, lets_connect_arg) = parse_args()
lets_connect = lets_connect or lets_connect_arg
if geteuid() == 0:
logger.error("Running eduVPN client as root is not supported (yet)")
Expand Down
4 changes: 2 additions & 2 deletions eduvpn/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,8 @@ def update_config_provider(meta, config_dict): # type: (Metadata, dict) -> None
if have_dbus():
connection = NetworkManager.Settings.GetConnectionByUuid(meta.uuid) # type: ignore
old_settings = connection.GetSettings()
nm_config['vpn']['data'].update({'cert': (old_settings['vpn']['data']['cert']),
'key': (old_settings['vpn']['data']['key'])}) # type: ignore
nm_config['vpn']['data'].update({'cert': old_settings['vpn']['data']['cert'],
'key': old_settings['vpn']['data']['key']}) # type: ignore
connection.Update(nm_config)


Expand Down
24 changes: 8 additions & 16 deletions eduvpn/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
distibuted_tokens_path = os.path.join(others_path, 'distributed.json')


def get_distributed_tokens():
# type: () -> Any
def get_distributed_tokens(): # type: () -> Any
json_path = distibuted_tokens_path
try:
with open(json_path, 'r') as f:
Expand Down Expand Up @@ -51,8 +50,7 @@ def __init__(self):
self.profile_display_name = "Unknown" # type: str

@staticmethod
def from_uuid(uuid, display_name=None):
# type: (str, str) -> Metadata
def from_uuid(uuid, display_name=None): # type: (str, str) -> Metadata
metadata_path = os.path.join(providers_path, uuid + '.json')
metadata = Metadata()
try:
Expand All @@ -72,8 +70,7 @@ def from_uuid(uuid, display_name=None):
metadata.display_name = uuid
return metadata

def write(self):
# type: () -> None
def write(self): # type: () -> None
if not self.uuid:
# raise EduvpnException('uuid field not set')
logger.warning("uuid field not yet set")
Expand All @@ -90,8 +87,7 @@ def write(self):
if self.authorization_type == 'distributed':
self.write_distributed_token()

def write_distributed_token(self):
# type: () -> None
def write_distributed_token(self): # type: () -> None
tokens = get_distributed_tokens()
if self.discovery_uri in tokens:
tokens[self.discovery_uri]['token'] = self.token
Expand All @@ -106,13 +102,11 @@ def write_distributed_token(self):
distibuted_tokens_path))
f.write(serialized)

def update_token(self, token):
# type: (dict) -> None
def update_token(self, token): # type: (dict) -> None
self.token = token
self.write()

def refresh_token(self):
# type: () -> None
def refresh_token(self): # type: () -> None
if self.authorization_type == 'distributed':
tokens = get_distributed_tokens()
if self.discovery_uri in tokens:
Expand All @@ -121,16 +115,14 @@ def refresh_token(self):
self.token_endpoint = tokens[self.discovery_uri]['token_endpoint']


def get_all_metadata():
# type: () -> List[Metadata]
def get_all_metadata(): # type: () -> List[Metadata]
if not os.access(providers_path, os.X_OK):
return []
metadatas = [Metadata.from_uuid(i[:-5]) for i in os.listdir(providers_path) if i.endswith('.json')]
return metadatas


def reuse_token_from_base_uri(instance_base_uri):
# type: (str) -> Optional[dict]
def reuse_token_from_base_uri(instance_base_uri): # type: (str) -> Optional[dict]
for metadata in get_all_metadata():
if metadata.connection_type in (u'Institute Access', u'Custom Instance') and \
metadata.instance_base_uri == instance_base_uri:
Expand Down
12 changes: 4 additions & 8 deletions eduvpn/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from os import path
import gi
gi.require_version('Notify', '0.7')
gi.require_version('Gtk', '3.0')
from gi.repository import Notify, GdkPixbuf
from repoze.lru import lru_cache
from eduvpn.util import have_dbus
Expand All @@ -13,13 +15,8 @@
from gi.repository import Notify


gi.require_version('Notify', '0.7')
gi.require_version('Gtk', '3.0')


@lru_cache(maxsize=1)
def init_notify(lets_connect):
# type: (bool) -> Notify
def init_notify(lets_connect): # type: (bool) -> Notify
icon, name = get_brand(lets_connect)
Notify.init(name + " client")
image_path = path.join(icon)
Expand All @@ -30,8 +27,7 @@ def init_notify(lets_connect):
return notification


def notify(notification, msg, small_msg=None):
# type: (Notify, str, Optional[Any]) -> None
def notify(notification, msg, small_msg=None): # type: (Notify, str, Optional[Any]) -> None
notification.update(msg, small_msg)
if have_dbus():
notification.show()
10 changes: 7 additions & 3 deletions eduvpn/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@


def get_open_port(): # type: () -> int
"""Find an unused local port."""
"""
Find an unused local port.
returns:
int: an unused port number
"""
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("", 0))
s.listen(1)
Expand Down Expand Up @@ -99,8 +104,7 @@ def do_GET(self):
return parse_qs(parsed.query)


def stringify_image(logo):
# type: (str) -> str
def stringify_image(logo): # type: (str) -> str
import base64
return base64.b64encode(open(logo, 'rb').read()).decode('ascii')

Expand Down
3 changes: 1 addition & 2 deletions eduvpn/openvpn.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ def parse_ovpn(configtext): # type: (str) -> dict
"""
config = {}

def configurator(text):
# type: (str) -> Any
def configurator(text): # type: (str) -> Any
for line in text.split('\n'):
split = line.split('#')[0].strip().split()
if len(split) == 0:
Expand Down
1 change: 0 additions & 1 deletion eduvpn/steps/fetching.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#
# Copyright: 2017, The Commons Conservancy eduVPN Programme
# SPDX-License-Identifier: GPL-3.0+

import logging
from eduvpn.brand import get_brand
import gi
Expand Down
2 changes: 1 addition & 1 deletion eduvpn/steps/reauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

import logging
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from eduvpn.steps.browser import browser_step
from eduvpn.metadata import Metadata
from typing import Dict


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion eduvpn/steps/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import base64
import logging
import gi
gi.require_version('Gtk', '3.0')
from eduvpn.manager import list_providers
from eduvpn.util import bytes2pixbuf, get_pixbuf
from eduvpn.brand import get_brand
from gi.repository import Gtk


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion eduvpn/steps/totp_enroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from future.moves.urllib.parse import urlparse
import qrcode
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import GLib, Gdk, Gtk
from eduvpn.util import pil2pixbuf
from eduvpn.remote import two_factor_enroll_totp
Expand All @@ -18,7 +19,6 @@
from typing import Any, Optional


gi.require_version('Gtk', '3.0')
logger = logging.getLogger(__name__)


Expand Down
Loading

0 comments on commit 787297b

Please sign in to comment.