Commit bb81ae0c authored by Jeroen F.J. Laros's avatar Jeroen F.J. Laros

Added support for certificate verification.

parent 2b35610b
......@@ -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.,
......@@ -36,18 +45,18 @@ optional arguments:
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 +69,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')
......
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