From 2e41913f648ad0ba93004abbd3e28436424041ae Mon Sep 17 00:00:00 2001 From: Marius Kriegerowski Date: Tue, 16 Jan 2018 11:08:48 +0100 Subject: [PATCH 1/6] readme: cosmetics --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f1990412..b1f1827c 100644 --- a/README.rst +++ b/README.rst @@ -70,7 +70,7 @@ Documentation ============= PyOTA's documentation is available on `ReadTheDocs`_. -If you are :ref:`installing from source `, you +If you are [installing from source](#installing-from-source), you can also build the documentation locally: #. Install extra dependencies (you only have to do this once):: From ab4533507901fd5a8a1eea5ea0d53345cfd73bbb Mon Sep 17 00:00:00 2001 From: Marius Kriegerowski Date: Tue, 16 Jan 2018 11:10:56 +0100 Subject: [PATCH 2/6] docs/adapters: basic auth, timeout --- docs/adapters.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/adapters.rst b/docs/adapters.rst index 7551d729..98d30f6f 100644 --- a/docs/adapters.rst +++ b/docs/adapters.rst @@ -44,6 +44,14 @@ HttpAdapter api = Iota('https://service.iotasupport.com:14265') api = Iota(HttpAdapter('https://service.iotasupport.com:14265')) + # Use HTTPS with basic authentication and 60 seconds timeout: + api = Iota('https://USERNAME:MYIRIPASSWORD@service.iotasupport.com:14265', + timeout=60) + api = Iota( + HttpAdapter( + 'https://USERNAME:MYIRIPASSWORD@service.iotasupport.com:14265', + timeout=60)) + ``HttpAdapter`` uses the HTTP protocol to send requests to the node. To configure an ``Iota`` instance to use ``HttpAdapter``, specify an From 81382bb30e69865016266e5cb7e0208b91fe26ca Mon Sep 17 00:00:00 2001 From: Marius Kriegerowski Date: Wed, 17 Jan 2018 21:53:12 +0100 Subject: [PATCH 3/6] Revert "readme: cosmetics" This reverts commit 2e41913f648ad0ba93004abbd3e28436424041ae. --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b1f1827c..f1990412 100644 --- a/README.rst +++ b/README.rst @@ -70,7 +70,7 @@ Documentation ============= PyOTA's documentation is available on `ReadTheDocs`_. -If you are [installing from source](#installing-from-source), you +If you are :ref:`installing from source `, you can also build the documentation locally: #. Install extra dependencies (you only have to do this once):: From d48083a4fdc9d9ee1ca174d487c0f4c991b958a7 Mon Sep 17 00:00:00 2001 From: Marius Kriegerowski Date: Sat, 20 Jan 2018 20:22:16 +0100 Subject: [PATCH 4/6] fix adapter doc --- docs/adapters.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/adapters.rst b/docs/adapters.rst index 98d30f6f..d54cebd7 100644 --- a/docs/adapters.rst +++ b/docs/adapters.rst @@ -45,11 +45,10 @@ HttpAdapter api = Iota(HttpAdapter('https://service.iotasupport.com:14265')) # Use HTTPS with basic authentication and 60 seconds timeout: - api = Iota('https://USERNAME:MYIRIPASSWORD@service.iotasupport.com:14265', - timeout=60) api = Iota( HttpAdapter( - 'https://USERNAME:MYIRIPASSWORD@service.iotasupport.com:14265', + 'https://service.iotasupport.com:14265', + auth=('myusername', 'mypassword'), timeout=60)) ``HttpAdapter`` uses the HTTP protocol to send requests to the node. From d66908058e7ebf6c66f84a4c1c539d4d41fc2b21 Mon Sep 17 00:00:00 2001 From: Marius Kriegerowski Date: Sat, 20 Jan 2018 20:22:39 +0100 Subject: [PATCH 5/6] HttpAdapter basic auth via requests module --- iota/adapter/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/iota/adapter/__init__.py b/iota/adapter/__init__.py index 0559e1b2..63f8e2ea 100644 --- a/iota/adapter/__init__.py +++ b/iota/adapter/__init__.py @@ -10,7 +10,7 @@ from socket import getdefaulttimeout as get_default_timeout from typing import Container, Dict, List, Optional, Text, Tuple, Union -from requests import Response, codes, request +from requests import Response, codes, request, auth from six import PY2, binary_type, iteritems, moves as compat, text_type, \ with_metaclass @@ -223,11 +223,12 @@ class HttpAdapter(BaseAdapter): in the ``headers`` kwarg. """ - def __init__(self, uri, timeout=None): + def __init__(self, uri, timeout=None, authentication=None): # type: (Union[Text, SplitResult], Optional[int]) -> None super(HttpAdapter, self).__init__() self.timeout = timeout + self.authentication = authentication if isinstance(uri, text_type): uri = compat.urllib_parse.urlsplit(uri) # type: SplitResult @@ -313,6 +314,8 @@ def _send_http_request(self, url, payload, method='post', **kwargs): default_timeout = self.timeout if self.timeout else get_default_timeout() kwargs.setdefault('timeout', default_timeout) + if self.authentication: + kwargs.setdefault('auth', auth.HTTPBasicAuth(*self.authentication)) self._log( level = DEBUG, From f1b5185a14ba752e018b810161710b7c2288b5b4 Mon Sep 17 00:00:00 2001 From: Marius Kriegerowski Date: Sat, 20 Jan 2018 20:24:52 +0100 Subject: [PATCH 6/6] docs/adapters: fix doc string --- docs/adapters.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/adapters.rst b/docs/adapters.rst index d54cebd7..be52b471 100644 --- a/docs/adapters.rst +++ b/docs/adapters.rst @@ -48,7 +48,7 @@ HttpAdapter api = Iota( HttpAdapter( 'https://service.iotasupport.com:14265', - auth=('myusername', 'mypassword'), + authentication=('myusername', 'mypassword'), timeout=60)) ``HttpAdapter`` uses the HTTP protocol to send requests to the node.