Skip to content

Commit 56af4fc

Browse files
committed
Add changes for ArangoDB 3.7
1 parent bb0f8a4 commit 56af4fc

30 files changed

+1178
-270
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,9 @@ venv.bak/
108108

109109
# PyCharm
110110
.idea/
111+
112+
# ArangoDB Starter
113+
localdata/
114+
115+
# Node Modules
116+
node_modules/

.travis.yml

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
11
sudo: false
22
language: python
3-
matrix:
4-
include:
5-
- python: 2.7
6-
- python: 3.5
7-
- python: 3.6
8-
- python: 3.7
9-
dist: xenial
10-
sudo: true
3+
python:
4+
- "2.7"
5+
- "3.5"
6+
- "3.6"
7+
- "3.7"
8+
- "3.8"
119
services:
1210
- docker
1311
before_install:
14-
- docker run --name arango -d -p 8529:8529 -e ARANGO_ROOT_PASSWORD=passwd arangodb/arangodb:3.6.1
12+
- docker create --name arango -p 8529:8529 -e ARANGO_ROOT_PASSWORD=passwd arangodb/arangodb-preview:3.7-alpha.3 --server.jwt-secret-keyfile=/tmp/keyfile
1513
- docker cp tests/static/service.zip arango:/tmp/service.zip
14+
- docker cp tests/static/keyfile arango:/tmp/keyfile
15+
- docker start arango
1616
install:
1717
- pip install flake8 mock
18-
- pip install pytest==3.5.1
19-
- pip install pytest-cov==2.5.1
20-
- pip install python-coveralls==2.9.1
18+
- pip install pytest pytest-cov coveralls
2119
- pip install sphinx sphinx_rtd_theme
2220
- pip install .
2321
script:

README.rst

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,15 @@
3434
3535
Welcome to the GitHub page for **python-arango**, a Python driver for ArangoDB_.
3636

37-
Announcements
38-
=============
39-
40-
- Python-arango version `5.0.0`_ is finally up! This release supports ArangoDB
41-
version 3.5+ only. It also breaks backward-compatibility and you must make
42-
changes in your application code. Please see the releases_ page for details.
43-
44-
Features
45-
========
46-
47-
- Pythonic interface
48-
- Lightweight
49-
- High API coverage
50-
5137
Compatibility
5238
=============
5339

54-
- Python versions 2.7, 3.5, 3.6 and 3.7 are supported
55-
- Python-arango 5.x supports ArangoDB 3.5+
56-
- Python-arango 4.x supports ArangoDB 3.3 ~ 3.4 only
57-
- Python-arango 3.x supports ArangoDB 3.0 ~ 3.2 only
58-
- Python-arango 2.x supports ArangoDB 1.x ~ 2.x only
40+
- Python versions 2.7+ and 3.5+ are supported
41+
- Python-arango 6.x supports ArangoDB 3.7+
42+
- Python-arango 5.x supports ArangoDB 3.5 ~ 3.6
43+
- Python-arango 4.x supports ArangoDB 3.3 ~ 3.4
44+
- Python-arango 3.x supports ArangoDB 3.0 ~ 3.2
45+
- Python-arango 2.x supports ArangoDB 1.x ~ 2.x
5946

6047
Installation
6148
============

arango/client.py

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66

77
__all__ = ['ArangoClient']
88

9-
from arango.connection import Connection
9+
from arango.connection import (
10+
BasicConnection,
11+
JWTConnection,
12+
JWTSuperuserConnection
13+
)
1014
from arango.database import StandardDatabase
1115
from arango.exceptions import ServerConnectionError
1216
from arango.http import DefaultHTTPClient
@@ -85,7 +89,13 @@ def version(self):
8589
"""
8690
return __version__
8791

88-
def db(self, name='_system', username='root', password='', verify=False):
92+
def db(self,
93+
name='_system',
94+
username='root',
95+
password='',
96+
verify=False,
97+
auth_method='basic',
98+
superuser_token=None):
8999
"""Connect to an ArangoDB database and return the database API wrapper.
90100
91101
:param name: Database name.
@@ -96,22 +106,58 @@ def db(self, name='_system', username='root', password='', verify=False):
96106
:type password: str | unicode
97107
:param verify: Verify the connection by sending a test request.
98108
:type verify: bool
109+
:param auth_method: HTTP authentication method. Accepted values are
110+
"basic" (default) and "jwt". If set to "jwt", the token is
111+
refreshed automatically using ArangoDB username and password. This
112+
assumes that the clocks of the server and client are synchronized.
113+
:type auth_method: str | unicode
114+
:param superuser_token: User generated token for superuser access.
115+
If set, parameters **username**, **password** and **auth_method**
116+
are ignored. This token is not refreshed automatically.
117+
:type superuser_token: str | unicode
99118
:return: Standard database API wrapper.
100119
:rtype: arango.database.StandardDatabase
101120
:raise arango.exceptions.ServerConnectionError: If **verify** was set
102121
to True and the connection fails.
103122
"""
104-
connection = Connection(
105-
hosts=self._hosts,
106-
host_resolver=self._host_resolver,
107-
sessions=self._sessions,
108-
db_name=name,
109-
username=username,
110-
password=password,
111-
http_client=self._http,
112-
serializer=self._serializer,
113-
deserializer=self._deserializer
114-
)
123+
if superuser_token is not None:
124+
connection = JWTSuperuserConnection(
125+
hosts=self._hosts,
126+
host_resolver=self._host_resolver,
127+
sessions=self._sessions,
128+
db_name=name,
129+
http_client=self._http,
130+
serializer=self._serializer,
131+
deserializer=self._deserializer,
132+
superuser_token=superuser_token
133+
)
134+
elif auth_method == 'basic':
135+
connection = BasicConnection(
136+
hosts=self._hosts,
137+
host_resolver=self._host_resolver,
138+
sessions=self._sessions,
139+
db_name=name,
140+
username=username,
141+
password=password,
142+
http_client=self._http,
143+
serializer=self._serializer,
144+
deserializer=self._deserializer,
145+
)
146+
elif auth_method == 'jwt':
147+
connection = JWTConnection(
148+
hosts=self._hosts,
149+
host_resolver=self._host_resolver,
150+
sessions=self._sessions,
151+
db_name=name,
152+
username=username,
153+
password=password,
154+
http_client=self._http,
155+
serializer=self._serializer,
156+
deserializer=self._deserializer,
157+
)
158+
else:
159+
raise ValueError('invalid auth_method: {}'.format(auth_method))
160+
115161
if verify:
116162
try:
117163
connection.ping()

arango/cluster.py

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
from arango.api import APIWrapper
66
from arango.exceptions import (
7+
ClusterEndpointsError,
78
ClusterHealthError,
89
ClusterMaintenanceModeError,
10+
ClusterServerEngineError,
911
ClusterServerIDError,
1012
ClusterServerRoleError,
11-
ClusterStatisticsError,
13+
ClusterServerStatisticsError,
14+
ClusterServerVersionError,
1215
)
1316
from arango.request import Request
1417

@@ -42,7 +45,7 @@ def server_role(self):
4245
4346
:return: Server role. Possible values are "SINGLE" (server which is
4447
not in a cluster), "COORDINATOR" (cluster coordinator), "PRIMARY",
45-
"SECONDARY", "AGENT" (Agency node in a cluster) or "UNDEFINED".
48+
"SECONDARY", "AGENT" (Agency server in a cluster) or "UNDEFINED".
4649
:rtype: str | unicode
4750
:raise arango.exceptions.ClusterServerRoleError: If retrieval fails.
4851
"""
@@ -58,25 +61,70 @@ def response_handler(resp):
5861

5962
return self._execute(request, response_handler)
6063

61-
def statistics(self, server_id):
62-
"""Return the cluster statistics for the given server.
64+
def server_version(self, server_id):
65+
"""Return the version of the given server.
6366
6467
:param server_id: Server ID.
6568
:type server_id: str | unicode
66-
:return: Cluster statistics for the given server.
69+
:return: Version of the given server.
6770
:rtype: dict
68-
:raise arango.exceptions.ClusterStatisticsError: If retrieval fails.
71+
:raise arango.exceptions.ClusterServerVersionError: If retrieval fails.
6972
"""
7073
request = Request(
7174
method='get',
72-
endpoint='/_admin/clusterStatistics',
73-
params={'DBserver': server_id}
75+
endpoint='/_admin/cluster/nodeVersion',
76+
params={'ServerID': server_id}
7477
)
7578

7679
def response_handler(resp):
7780
if resp.is_success:
7881
return resp.body
79-
raise ClusterStatisticsError(resp, request)
82+
raise ClusterServerVersionError(resp, request)
83+
84+
return self._execute(request, response_handler)
85+
86+
def server_engine(self, server_id):
87+
"""Return the engine details for the given server.
88+
89+
:param server_id: Server ID.
90+
:type server_id: str | unicode
91+
:return: Engine details of the given server.
92+
:rtype: dict
93+
:raise arango.exceptions.ClusterServerEngineError: If retrieval fails.
94+
"""
95+
request = Request(
96+
method='get',
97+
endpoint='/_admin/cluster/nodeEngine',
98+
params={'ServerID': server_id}
99+
)
100+
101+
def response_handler(resp):
102+
if resp.is_success:
103+
return resp.body
104+
raise ClusterServerEngineError(resp, request)
105+
106+
return self._execute(request, response_handler)
107+
108+
def server_statistics(self, server_id):
109+
"""Return the statistics for the given server.
110+
111+
:param server_id: Server ID.
112+
:type server_id: str | unicode
113+
:return: Statistics for the given server.
114+
:rtype: dict
115+
:raise arango.exceptions.ClusterServerStatisticsError: If retrieval
116+
fails.
117+
"""
118+
request = Request(
119+
method='get',
120+
endpoint='/_admin/cluster/nodeStatistics',
121+
params={'ServerID': server_id}
122+
)
123+
124+
def response_handler(resp):
125+
if resp.is_success:
126+
return resp.body
127+
raise ClusterServerStatisticsError(resp, request)
80128

81129
return self._execute(request, response_handler)
82130

@@ -122,3 +170,22 @@ def response_handler(resp):
122170
raise ClusterMaintenanceModeError(resp, request)
123171

124172
return self._execute(request, response_handler)
173+
174+
def endpoints(self):
175+
"""Return coordinate endpoints. This method is for clusters only.
176+
177+
:return: List of endpoints.
178+
:rtype: [str | unicode]
179+
:raise arango.exceptions.ServerEndpointsError: If retrieval fails.
180+
"""
181+
request = Request(
182+
method='get',
183+
endpoint='/_api/cluster/endpoints'
184+
)
185+
186+
def response_handler(resp):
187+
if not resp.is_success:
188+
raise ClusterEndpointsError(resp, request)
189+
return [item['endpoint'] for item in resp.body['endpoints']]
190+
191+
return self._execute(request, response_handler)

0 commit comments

Comments
 (0)