Commit 99328671 authored by jkvis's avatar jkvis

Merge branch 'cli' into 'master'

Cli

I added support for certificate checking.

See merge request !2
parents 6607e78d 8dc2947a
......@@ -3,7 +3,7 @@ This package provides functions for communication with the Restful Transfer
Server.
## Installation
Via pypi:
Via [pypi](https://pypi.python.org/pypi/transfer-client):
pip install transfer_client
......@@ -13,6 +13,15 @@ From source:
cd transfer/transfer_client
pip install .
### Server certificate
If the server uses a self-signed certificate, the administrator of the server
needs to add this certificate to the list of trusted authorities (change
`server_name` and `domain`):
openssl s_client -connect server_name.domain:443 < /dev/null | \
openssl x509 > /usr/local/share/ca-certificates/server_name.crt
update-ca-certificates
## Command line interface
Use the command `transfer_client -h` for a list of subcommands. For every
subcommand a separate help is available, e.g.,
......@@ -30,24 +39,25 @@ positional arguments:
optional arguments:
-h, --help show this help message and exit
-o OUTPUT output file
-n disable ssl certificate check
```
### Typical usage
The three high level subcommands are probably the only ones needed.
To transfer a list of files, use the `transfer` subcommand. We assume that the
server name is `server.domain` and the user ID is `xxxxxxxx`.
server name is `server_name.domain` and the user ID is `xxxxxxxx`.
transfer_client transfer server.domain xxxxxxxx *.gz
transfer_client transfer server_name.domain xxxxxxxx *.gz
If a transfer is interrupted for some reason, it can be resumed with the
`resume` subcommand.
transfer_client resume server.domain xxxxxxxx
transfer_client resume server_name.domain xxxxxxxx
To cancel an interrupted transfer, the `cancel` subcommand can be used.
transfer_client cancel server.domain xxxxxxxx
transfer_client cancel server_name.domain xxxxxxxx
## Library
The library implements an interface to the API of the Restful Transfer server.
......@@ -60,8 +70,8 @@ we can use the API endpoints.
```python
>>> from transfer_client.transfer_client import TransferClient
>>>
>>> # Create a class instance for a server running on server.domain.
>>> transfer_client = TransferClient('server.domain')
>>> # Create a class instance for a server running on server_name.domain.
>>> transfer_client = TransferClient('server_name.domain')
>>>
>>> # Get user information together with its transfers.
>>> transfer_client.users('xxxxxxxx')
......
......@@ -8,7 +8,7 @@ Copyright (c) 2016 Jeroen F.J. Laros <J.F.J.Laros@lumc.nl>
Licensed under the MIT license, see the LICENSE file.
"""
__version_info__ = ('0', '0', '2')
__version_info__ = ('0', '0', '3')
__version__ = '.'.join(__version_info__)
......
This diff is collapsed.
import json
import requests
import sys
import urllib3
class TransferClient(object):
def __init__(self, server_name):
def __init__(self, server_name, verify=True):
"""
Initialise the class.
:arg str server_name: Name or IP of the transfer server.
"""
self.server_name = server_name
self._verify = False
self._verify = verify
if not self._verify:
try:
requests.packages.urllib3.disable_warnings()
except AttributeError:
try:
urllib3.disable_warnings()
except AttributeError:
sys.stderr = open('/dev/null')
def _request(self, method, endpoint, headers=None, files=None, json=None):
"""
......@@ -25,9 +37,12 @@ class TransferClient(object):
:returns dict: JSON encoded content of the response.
"""
response = requests.request(method,
'https://{}/{}'.format(self.server_name, endpoint),
headers=headers, files=files, json=json, verify=self._verify)
try:
response = requests.request(method,
'https://{}/{}'.format(self.server_name, endpoint),
headers=headers, files=files, json=json, verify=self._verify)
except requests.exceptions.SSLError:
raise OSError('SSL error, no server certificate installed?')
if not response.ok:
raise ValueError(response.json()['error'])
return response.json()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment