nir0s / ghost

A simple, server/less, single-api, multi-backend, ghostly secret-store/key-store for your passwords, ssh-keys and cloud credentials. Ghost isn't real, it's just in your head.
Apache License 2.0
45 stars 27 forks source link

Allow using other storage backends from the CLI #8

Closed nir0s closed 8 years ago

nir0s commented 8 years ago

Currently, only the TinyDB storage backend is supported in the CLI.

To solve this, we can get all storage class objects and their names. The names could be used by click via type=click.Choice(storage_names) after which if the name the user provides aligns with any of the available implementations, globals()[class.__name__](stash_path), it will be chosen.

clsmembers = inspect.getmembers(sys.modules[__name__], inspect.isclass) can return the desires class objects.

tehasdf commented 8 years ago

I can see 3 ways of getting the backend class:

So I think the middle one is much more magical than the first one (which is trivial), but it isn't much more powerful... you need to of course remember to maintain the dict, but in this case the backends only live inside ghost anyway, and there probably won't be very many of them. The third one is much more powerful of course, but not sure if it's very useful at this point.

Anyway, please note that backends might need more arguments than just a stash path (eg. the proposed consul backend, or really anything that you use over a network with optional tls), so I think there should be a way of passing additional parameters.

nir0s commented 8 years ago

Sounds reasonable. I guess we should start from the dict and see where it takes us. The reason for my suggestion was that assuming everything is exposed under ghost.py for now, it should be relatively easy. Of course, at some point, offering additional backends will complicate the package after which we need a more robust method. 3 sounds good for that.

nir0s commented 8 years ago

Now allowing to using SQLAlchemy as well while the default still uses TinyDB. I've implemented this using the first method @tehasdf suggested and we'll see how this goes when we add more backends.