1
- """ArangoDB Top-Level API."""
1
+ """ArangoDB's Top-Level API."""
2
2
3
3
from arango .database import Database
4
4
from arango .api import API
5
5
from arango .exceptions import *
6
6
from arango .constants import HTTP_OK , LOG_LEVELS
7
- from arango .clients import DefaultArangoClient
7
+ from arango .clients import DefaultClient
8
8
from arango .utils import uncamelify
9
9
10
10
11
11
class Arango (object ):
12
- """Wrapper for ArangoDB's top-level API."""
12
+ """Wrapper for ArangoDB's top-level APIs:
13
+
14
+ 1. Database Management
15
+ 2. User Management
16
+ 3. Administration & Monitoring
17
+ 4. Miscellaneous Functions
18
+ """
13
19
14
20
def __init__ (self , protocol = "http" , host = "localhost" , port = 8529 ,
15
21
username = "root" , password = "" , client = None ):
@@ -26,8 +32,8 @@ def __init__(self, protocol="http", host="localhost", port=8529,
26
32
:param password: ArangoDB password (default: '')
27
33
:type password: str
28
34
:param client: HTTP client for this wrapper to use
29
- :type client: arango.clients.base.BaseArangoClient or None
30
- :raises: ArangoConnectionError
35
+ :type client: arango.clients.base.BaseClient or None
36
+ :raises: ConnectionError
31
37
"""
32
38
self .protocol = protocol
33
39
self .host = host
@@ -40,7 +46,7 @@ def __init__(self, protocol="http", host="localhost", port=8529,
40
46
self .client = client
41
47
else :
42
48
client_init_data = {"auth" : (self .username , self .password )}
43
- self .client = DefaultArangoClient (client_init_data )
49
+ self .client = DefaultClient (client_init_data )
44
50
45
51
# Initialize the ArangoDB API wrapper object
46
52
self .api = API (
@@ -55,7 +61,7 @@ def __init__(self, protocol="http", host="localhost", port=8529,
55
61
# Check the connection by requesting a header
56
62
res = self .api .head ("/_api/version" )
57
63
if res .status_code not in HTTP_OK :
58
- raise ArangoConnectionError (res )
64
+ raise ConnectionError (res )
59
65
60
66
# Cache for Database objects
61
67
self ._database_cache = {}
@@ -91,6 +97,10 @@ def _invalidate_database_cache(self):
91
97
)
92
98
)
93
99
100
+ ###########################
101
+ # Miscellaneous Functions #
102
+ ###########################
103
+
94
104
@property
95
105
def version (self ):
96
106
"""Return the version of ArangoDB.
@@ -104,9 +114,9 @@ def version(self):
104
114
raise VersionGetError (res )
105
115
return res .obj ["version" ]
106
116
107
- #############
108
- # Databases #
109
- #############
117
+ #######################
118
+ # Database Management #
119
+ #######################
110
120
111
121
@property
112
122
def databases (self ):
@@ -182,13 +192,13 @@ def delete_database(self, name, safe_delete=False):
182
192
raise DatabaseDeleteError (res )
183
193
self ._invalidate_database_cache ()
184
194
185
- #########
186
- # Users #
187
- #########
195
+ ###################
196
+ # User Management #
197
+ ###################
188
198
189
199
@property
190
200
def users (self ):
191
- """Return the details on all users.
201
+ """Return details on all users.
192
202
193
203
:returns: a dictionary mapping user names to their information
194
204
:rtype: dict
@@ -209,6 +219,26 @@ def users(self):
209
219
210
220
def create_user (self , username , password , active = None , extra = None ,
211
221
change_password = None ):
222
+ """Create a new user.
223
+
224
+ if ``change_password`` is set to true, the only operation allowed by
225
+ the user will be ``self.replace_user`` or ``self.update_user``. All
226
+ other operations executed by the user will result in an HTTP 403.
227
+
228
+ :param username: the name of the user
229
+ :type username: str
230
+ :param password: the user password
231
+ :type password: str
232
+ :param active: whether the user is active
233
+ :type active: bool or None
234
+ :param extra: any extra data about the user
235
+ :type extra: dict or None
236
+ :param change_password: whether the user must change the password
237
+ :type change_password: bool or None
238
+ :returns: the information about the new user
239
+ :rtype: dict
240
+ :raises: UserCreateError
241
+ """
212
242
data = {"user" : username , "passwd" : password }
213
243
if active is not None :
214
244
data ["active" ] = active
@@ -228,6 +258,26 @@ def create_user(self, username, password, active=None, extra=None,
228
258
229
259
def update_user (self , username , password = None , active = None , extra = None ,
230
260
change_password = None ):
261
+ """Update an existing user.
262
+
263
+ if ``change_password`` is set to true, the only operation allowed by
264
+ the user will be ``self.replace_user`` or ``self.update_user``. All
265
+ other operations executed by the user will result in an HTTP 403.
266
+
267
+ :param username: the name of the existing user
268
+ :type username: str
269
+ :param password: the user password
270
+ :type password: str
271
+ :param active: whether the user is active
272
+ :type active: bool or None
273
+ :param extra: any extra data about the user
274
+ :type extra: dict or None
275
+ :param change_password: whether the user must change the password
276
+ :type change_password: bool or None
277
+ :returns: the information about the updated user
278
+ :rtype: dict
279
+ :raises: UserUpdateError
280
+ """
231
281
data = {}
232
282
if password is not None :
233
283
data ["password" ] = password
@@ -251,6 +301,26 @@ def update_user(self, username, password=None, active=None, extra=None,
251
301
252
302
def replace_user (self , username , password , active = None , extra = None ,
253
303
change_password = None ):
304
+ """Replace an existing user.
305
+
306
+ if ``change_password`` is set to true, the only operation allowed by
307
+ the user will be ``self.replace_user`` or ``self.update_user``. All
308
+ other operations executed by the user will result in an HTTP 403.
309
+
310
+ :param username: the name of the existing user
311
+ :type username: str
312
+ :param password: the user password
313
+ :type password: str
314
+ :param active: whether the user is active
315
+ :type active: bool or None
316
+ :param extra: any extra data about the user
317
+ :type extra: dict or None
318
+ :param change_password: whether the user must change the password
319
+ :type change_password: bool or None
320
+ :returns: the information about the replaced user
321
+ :rtype: dict
322
+ :raises: UserReplaceError
323
+ """
254
324
data = {"user" : username , "password" : password }
255
325
if active is not None :
256
326
data ["active" ] = active
@@ -271,15 +341,25 @@ def replace_user(self, username, password, active=None, extra=None,
271
341
}
272
342
273
343
def delete_user (self , username , safe_delete = False ):
344
+ """Delete an existing user.
345
+
346
+ :param username: the name of the user
347
+ :type username: str
348
+ :param safe_delete: ignores HTTP 404 if set to True
349
+ :type safe_delete: bool
350
+ :returns: True if the operation succeeds
351
+ :rtype: bool
352
+ :raises: UserDeleteError
353
+ """
274
354
res = self .api .delete ("/_api/user/{user}" .format (user = username ))
275
355
if res .status_code not in HTTP_OK :
276
356
if not (res .status_code == 404 and safe_delete ):
277
357
raise UserDeleteError (res )
278
358
return True
279
359
280
- ##############
281
- # Monitoring #
282
- ##############
360
+ ###############################
361
+ # Administration & Monitoring #
362
+ ###############################
283
363
284
364
def read_log (self , upto = None , level = None , start = None , size = None ,
285
365
offset = None , search = None , sort = None ):
0 commit comments