man-group / arctic

High performance datastore for time series and tick data
https://arctic.readthedocs.io/en/latest/
GNU Lesser General Public License v2.1
3.06k stars 583 forks source link

Setting up user/password authorization guide? #563

Closed derekwong9 closed 6 years ago

derekwong9 commented 6 years ago

Arctic Version

# arctic==1.66.0

Arctic Store

# TICK_STORE

Platform and version

Ubuntu 18.04 LTS

Description of problem and/or code sample that reproduces the issue

I am trying to set up a user name and password authentication with the mongo for Arctic. I have tried using arctic.Auth.authenticate as in this post here https://github.com/manahl/arctic/issues/405 getting an error as shown below.

from arctic.auth import Credential, authenticate
 auth = authenticate( "arctic",
                     "USER",
                     "PWD")

Traceback (most recent call last):
  File "/home/gcdb1/arctic/arctic/coinapi/coinapi_tickstore.py", line 166, in <module>
    securities_master=securities_master)
  File "/home/gcdb1/arctic/arctic/coinapi/coinapi_tickstore.py", line 52, in __init__
    "GCrocks$$$")
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/auth.py", line 16, in authenticate
    return db.authenticate(user, password)
AttributeError: 'str' object has no attribute 'authenticate'

I have also tried this hooked version as described here https://github.com/manahl/arctic/issues/327

from arctic.auth import Credential, authenticate

register_get_auth_hook(self.arctic_auth_hook(mongo_host=mongo_address,
                                                     app = "storage_writer",
                                                     database="arctic"))

    def arctic_auth_hook(self, mongo_host, app, database='arctic'):
        return Credential(
            database=database,
            user="user",
            password="pwd",
        )

Traceback (most recent call last):
  File "/home/gcdb1/arctic/arctic/coinapi/coinapi_tickstore.py", line 166, in <module>
    securities_master=securities_master)
  File "/home/gcdb1/arctic/arctic/coinapi/coinapi_tickstore.py", line 55, in __init__
    self.library = self.store[arctic_library]
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/arctic.py", line 285, in __getitem__
    return self.get_library(key)
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/arctic.py", line 263, in get_library
    l = ArcticLibraryBinding(self, library)
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/arctic.py", line 412, in __init__
    self._curr_conn = self.arctic._conn
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/decorators.py", line 50, in f_retry
    return f(*args, **kwargs)
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/arctic.py", line 136, in _conn
    auth = get_auth(self.mongo_host, self._application_name, 'admin')
  File "/home/gcdb1/anaconda3/lib/python3.6/site-packages/arctic/auth.py", line 30, in get_auth
    return _get_auth_hook(host, app_name, database_name)
TypeError: 'MongoCredentials' object is not callable

I am wondering if there is a guide or post on how to set up username and password authentication using arctic in a step by step manner? I know these are non-repeatable examples and can create some, however I think that mostly an instructional tutorial would be great.

bmoscon commented 6 years ago

I think you can just use this:

https://github.com/manahl/arctic/blob/master/arctic/scripts/utils.py#L10

example of use:

https://github.com/manahl/arctic/blob/master/arctic/scripts/arctic_create_user.py#L32

bmoscon commented 6 years ago

@derekwong9 did either of those help?

bmoscon commented 6 years ago

never heard back - closing

firoozye commented 5 years ago

mongodb authorisation issue gives a decent example of how to set it up. From my limited experience, using do_db_auth is so much more complicated than mere mortals need in order to get up and running.