From 2d8ca9f60f2d6a56756bbbae05778f1e8db6c493 Mon Sep 17 00:00:00 2001 From: Abdul Hamid Date: Thu, 22 May 2014 22:44:04 +0100 Subject: [PATCH 01/10] Added basicConfig to logging and separated the use of the libraries available for opening URLs to use either PyCurl or Urllib2 and not to load both. --- arango/clients/__init__.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/arango/clients/__init__.py b/arango/clients/__init__.py index 598cb67..bdc2f8f 100644 --- a/arango/clients/__init__.py +++ b/arango/clients/__init__.py @@ -1,22 +1,29 @@ import sys import logging - -from .urllib2client import Urllib2Client - +logging.basicConfig() __all__ = ("Client",) - ISPY3 = sys.version_info >= (3, 0) -logger = logging.getLogger("arango.client") -Client = Urllib2Client - +logger = logging.getLogger("arango.clients") if ISPY3 is False: try: from .pycurlclient import PyCurlClient Client = PyCurlClient + except ImportError: + try: + logger.warning(u"PyCurl not available, trying Urllib2. %s", str(e)) + from .urllib2client import Urllib2Client + Client = Urllib2Client + except ImportError: + logger.warning(u"Urllib2 not available. %s", str(e)) except Exception as e: - logger.warning( - u"Sorry, can't import PyCurlClient. Reason: %s", str(e)) + logger.warning(u"No library available for opening URLs. %s", str(e)) +else: + try: + from .urllib2client import Urllib2Client + Client = Urllib2Client + except ImportError: + logger.warning(u"Urllib2 not available. %s", str(e)) \ No newline at end of file From 4abd543744d917393958c614023abeffc5adadf9 Mon Sep 17 00:00:00 2001 From: Abdul Hamid Date: Thu, 22 May 2014 22:50:39 +0100 Subject: [PATCH 02/10] Added basicConfig to logging and separated the use of the libraries available for opening URLs to use either PyCurl or Urllib2 and not to load both. --- arango/clients/__init__.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/arango/clients/__init__.py b/arango/clients/__init__.py index 598cb67..1f819ca 100644 --- a/arango/clients/__init__.py +++ b/arango/clients/__init__.py @@ -1,22 +1,29 @@ import sys import logging - -from .urllib2client import Urllib2Client - +logging.basicConfig() __all__ = ("Client",) - ISPY3 = sys.version_info >= (3, 0) -logger = logging.getLogger("arango.client") -Client = Urllib2Client - +logger = logging.getLogger("arango.clients") if ISPY3 is False: try: from .pycurlclient import PyCurlClient Client = PyCurlClient + except ImportError: + try: + logger.warning(u"PyCurl not available, trying Urllib2. %s", str(e)) + from .urllib2client import Urllib2Client + Client = Urllib2Client + except ImportError: + logger.warning(u"Urllib2 not available. %s", str(e)) except Exception as e: - logger.warning( - u"Sorry, can't import PyCurlClient. Reason: %s", str(e)) + logger.warning(u"No library available for opening URLs. %s", str(e)) +else: + try: + from .urllib2client import Urllib2Client + Client = Urllib2Client + except ImportError: + logger.warning(u"Urllib2 not available. %s", str(e)) From e3068463a1165ab029ccdbedcddc21354f7f6b17 Mon Sep 17 00:00:00 2001 From: Abdul Hamid Date: Thu, 22 May 2014 23:35:47 +0100 Subject: [PATCH 03/10] README.rst updated with ArangoDB authentication example --- README.rst | 41 ++++++++++++++++++++++++++++++++++++++++- setup.py | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index ddf2c3b..688d775 100644 --- a/README.rst +++ b/README.rst @@ -10,7 +10,15 @@ Installation ************ :: - pip install arango + Download from repository + + wget https://github.com/appscluster/arango-python/archive/master.zip + + 7z x master.zip ( if you don't have 7z : sudo apt-get install p7zip-full ) + + cd arango-python-master + + python setup.py install Usage @@ -39,6 +47,30 @@ To start work with **ArangoDB** try following example:: for doc in conn.test_collection.query.execute(): print doc.id +To use **ArangoDB authentication via HTTP** try following example:: + + from requests.auth import HTTPBasicAuth + from arango.clients.requestsclient import RequestsClient + from arango.core import Connection + + # Login to ArangoDB + RequestsClient.config(auth=HTTPBasicAuth('arango_user', 'password')) + + # Connect to the appropriate DB + c = Connection(db="test", client=RequestsClient) + c = c.collection + c.test_collection.create() + c.test_collection.documents.create({"key": "value"}) + + # get first document + doc = c.test_collection.documents().first + # get document body + doc.body + + # get all documents in collection + for doc in c.test_collection.query.execute(): + print doc.id + For more details please read `Documentation `_ @@ -50,12 +82,19 @@ Supported Python interpreters and versions: Supported **ArangoDB versions**: *1.4x* +Tested on **ArangoDB version**: *2.0.7* + Developed by `Maksym Klymyshyn `_ Changelog ********* +0.2.2 +~~~~~~ + + * Separated the use of the libraries available for opening URLs to use either PyCurl or Urllib2 and not to load both. + 0.2.1 ~~~~~~ diff --git a/setup.py b/setup.py index 13e59b0..03bdc34 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ os.system('python setup.py sdist upload') sys.exit() -VERSION = "0.2.1" +VERSION = "0.2.2" setup( name="arango", From 88f1fe7a23ed67222c9fff287f4a8143ce23fd38 Mon Sep 17 00:00:00 2001 From: appscluster Date: Thu, 22 May 2014 23:58:43 +0100 Subject: [PATCH 04/10] Update README.rst --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 688d775..f808e05 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Python driver for ArangoDB +Python driver for ArangoDB 0.2.2 -------------------------- Driver for **ArangoDB REST API** inrerface, `arangodb.org `_ @@ -86,6 +86,7 @@ Tested on **ArangoDB version**: *2.0.7* Developed by `Maksym Klymyshyn `_ +Forked by `Abdul Hamid `_ Changelog ********* From d2f8475e8f95b2211156b4c2c3b572c75a3df673 Mon Sep 17 00:00:00 2001 From: appscluster Date: Fri, 30 May 2014 15:44:42 +0100 Subject: [PATCH 05/10] Update README.rst Title corrected --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f808e05..7d40314 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Python driver for ArangoDB 0.2.2 +Python driver 0.2.2 for ArangoDB 2.0.7 -------------------------- Driver for **ArangoDB REST API** inrerface, `arangodb.org `_ From 73964918896a8bee82f15757c4e2a712ff38eadb Mon Sep 17 00:00:00 2001 From: appscluster Date: Tue, 3 Jun 2014 18:47:38 +0100 Subject: [PATCH 06/10] Update README.rst New instructions added for enabling authentication and changing the root account password --- README.rst | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 7d40314..71c8f9b 100644 --- a/README.rst +++ b/README.rst @@ -71,6 +71,36 @@ To use **ArangoDB authentication via HTTP** try following example:: for doc in c.test_collection.query.execute(): print doc.id +To **change or reset** arangodb **user** account **password**:: + + # In terminal run + arangosh + + # For improving security its a good idea to change the root account password + # Once in arangosh run the following commands + users = require("org/arangodb/users"); + users.update("root", "the_new_password", true); + users.reload(); + + quit + + # restart arangodb + /etc/init.d/arangodb restart + + +To enable arangodb **authentication** change the following 2 config files:: + + # 1. > /etc/arangodb/arangob.conf + [server] + disable-authentication = false + + # 2. > /etc/arangodb/arangod.conf + # disable authentication for the admin frontend + disable-authentication = no + + # restart arangodb for changes to take effect + /etc/init.d/arangodb restart + For more details please read `Documentation `_ @@ -82,7 +112,7 @@ Supported Python interpreters and versions: Supported **ArangoDB versions**: *1.4x* -Tested on **ArangoDB version**: *2.0.7* +Tested on **ArangoDB version**: *2.0.7 and 2.1.0* Developed by `Maksym Klymyshyn `_ From 8aa7e0bf321a086d070042867a6d9a19bddcc39d Mon Sep 17 00:00:00 2001 From: Abdul Hamid Date: Fri, 13 Jun 2014 23:15:56 +0100 Subject: [PATCH 07/10] 1. default initialisation temporarily disabled and used RequestsClient.config directly instead. 2. Added exception handling for status code 401 authentication failure to ArangoDB --- arango/__init__.py | 3 +++ arango/core.py | 29 +++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/arango/__init__.py b/arango/__init__.py index 6e24bc2..cdf02df 100644 --- a/arango/__init__.py +++ b/arango/__init__.py @@ -1,3 +1,5 @@ +''' +# temporarily disabled and RequestsClient.config used directly instead from arango.core import Connection @@ -10,3 +12,4 @@ def create(**kwargs): c = Connection() collection = c.collection +''' \ No newline at end of file diff --git a/arango/core.py b/arango/core.py index 45beb02..70e63e3 100644 --- a/arango/core.py +++ b/arango/core.py @@ -191,20 +191,29 @@ def __init__(self, url, response, args=None, expect_raw=False): self.message = "" self._data = None - try: - if expect_raw is False: - self.update({k: v - for k, v in - json.loads(response.text).items()}) - - except (TypeError, ValueError) as e: - msg = u"Can't parse response from ArangoDB:"\ + if (response.status_code==401): + raise Exception(401, 'Authentication Failed') + msg = u"Authentication Failed with ArangoDB:"\ u" {0} (URL: {1}, Response: {2})".format( - str(e), url, repr(response)) - + response.status_code, url, repr(response)) logger.error(msg) self.status = 500 self.message = msg + else: + try: + if expect_raw is False: + self.update({k: v + for k, v in + json.loads(response.text).items()}) + + except (TypeError, ValueError) as e: + msg = u"Can't parse response from ArangoDB:"\ + u" {0} (URL: {1}, Response: {2})".format( + str(e), url, repr(response)) + + logger.error(msg) + self.status = 500 + self.message = msg @property def data(self): From b09b991527ab20a8819eee7e7ccc2779f544ea9a Mon Sep 17 00:00:00 2001 From: Abdul Hamid Date: Fri, 13 Jun 2014 23:30:14 +0100 Subject: [PATCH 08/10] version updated --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 03bdc34..2d04f20 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ os.system('python setup.py sdist upload') sys.exit() -VERSION = "0.2.2" +VERSION = "0.2.3" setup( name="arango", @@ -21,7 +21,7 @@ description="Driver for ArangoDB", author="Maksym Klymyshyn", author_email="klymyshyn@gmail.com", - url="http://arangodb-python-driver.readthedocs.org/en/latest/", + url="https://github.com/appscluster/arango-python", packages=["arango"], long_description=open("README.rst").read(), include_package_data=True, From 605a234e9105681bb3cf367086c8349b48fd2f90 Mon Sep 17 00:00:00 2001 From: appscluster Date: Fri, 13 Jun 2014 23:31:12 +0100 Subject: [PATCH 09/10] Update README.rst Instruction updated --- README.rst | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 71c8f9b..b970308 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Python driver 0.2.2 for ArangoDB 2.0.7 +Python driver 0.2.3 for ArangoDB 2.1.1 -------------------------- Driver for **ArangoDB REST API** inrerface, `arangodb.org `_ @@ -53,13 +53,25 @@ To use **ArangoDB authentication via HTTP** try following example:: from arango.clients.requestsclient import RequestsClient from arango.core import Connection - # Login to ArangoDB - RequestsClient.config(auth=HTTPBasicAuth('arango_user', 'password')) - - # Connect to the appropriate DB - c = Connection(db="test", client=RequestsClient) + def ARDBconnect(): + try: + # Prepare Login for ArangoDB + RequestsClient.config(auth=HTTPBasicAuth('arango_user', 'password')) + # Login for ArangoDB + db = Connection(db="test", client=RequestsClient) + # Connect to the appropriate DB + arango = c.version + print 'Connected to ArangoDB version: ', arango.version + return db + except Exception, e: + print "Error %d: %s" % (e.args[0], e.args[1]) + + c = ARDBconnect() c = c.collection + + # Create a new collection c.test_collection.create() + # Add a document to the collection c.test_collection.documents.create({"key": "value"}) # get first document @@ -112,7 +124,7 @@ Supported Python interpreters and versions: Supported **ArangoDB versions**: *1.4x* -Tested on **ArangoDB version**: *2.0.7 and 2.1.0* +Tested on **ArangoDB version**: *2.0.7, 2.1.0 and 2.1.1* Developed by `Maksym Klymyshyn `_ @@ -121,6 +133,12 @@ Forked by `Abdul Hamid `_ Changelog ********* +0.2.3 +~~~~~~ + + * default initialisation temporarily disabled and used RequestsClient.config directly instead. + * Added exception handling for status code 401 authentication failure to ArangoDB + 0.2.2 ~~~~~~ From 280a6e18ebeff22e4e991acd8957d9372fffe4b5 Mon Sep 17 00:00:00 2001 From: appscluster Date: Fri, 13 Jun 2014 23:36:12 +0100 Subject: [PATCH 10/10] Update README.rst Fixed typo --- README.rst | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index b970308..531bea2 100644 --- a/README.rst +++ b/README.rst @@ -52,7 +52,8 @@ To use **ArangoDB authentication via HTTP** try following example:: from requests.auth import HTTPBasicAuth from arango.clients.requestsclient import RequestsClient from arango.core import Connection - + import sys + def ARDBconnect(): try: # Prepare Login for ArangoDB @@ -60,12 +61,14 @@ To use **ArangoDB authentication via HTTP** try following example:: # Login for ArangoDB db = Connection(db="test", client=RequestsClient) # Connect to the appropriate DB - arango = c.version + arango = db.version print 'Connected to ArangoDB version: ', arango.version return db except Exception, e: print "Error %d: %s" % (e.args[0], e.args[1]) - + sys.exit(1) + + # Create ArangoDB connection handle c = ARDBconnect() c = c.collection