Git Product home page Git Product logo

flask-cassandra-sessions's People

Contributors

d-ganchar avatar mikicaivosevic avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

d-ganchar

flask-cassandra-sessions's Issues

ModuleNotFoundError: No module named 'cassandra'

Hello.
Thanks for your package.

Your package requires cassandra-driver. I propose to add dependency to setup.py.

setup(
     install_requires=['cassandra-driver'],
     ...

Otherwise, we get the following error(and we need to install dependency manually):

  from cassandra_flask_sessions import CassandraSessionInterface
  File "../cassandra_flask_sessions/__init__.py", line 6, in <module>
    from cassandra.cluster import Cluster
ModuleNotFoundError: No module named 'cassandra'

What do you think?

ConnectionProvider

Hello.
I propose to make some modifications in package. I will try to explain why:

  1. There are no possibility to customize cassandra.cluster.Cluster settings (load_balancing_policy, connection_class etc.). Since the initialization of Cluster occurs inside flask-cassandra-sessions.
  2. Unclear access to cassandra session (app.session_interface.session). We need to have a configured connection for a whole project. Most often the connection is used not only for working with sessions.
  3. We need to process Flask context. Because we can lose the connection when run without dev server.
  4. The are no possibility to handle ConnectionException

So I propose to move initialization of Cluster out of package. Just an example of vision:

class ConnectionProvider:

     def get_connection():
         return Session

class CassandraSessionInterface(SessionInterface):

    def __init__(self, connection_profider: ConnectionProvider):
            seflf._connection_profider = connection_profider

    def open_session(self, app, request):
           self._connection_profider.get_connection().execute(...)
           # ...

In this case we will work just with configured connection. What do you think?

PERMANENT_SESSION_LIFETIME

According docs default PERMANENT_SESSION_LIFETIME = 31 day. But in our case is 1 day. This is not obvious.
Also PERMANENT_SESSION_LIFETIME from config will not work because we need to set session.permanent to True somewhere. Something like that:

@app.before_request
def make_session_permanent():
    session.permanent = True

I propose just set TTL using PERMANENT_SESSION_LIFETIME config value. Example:

    def save_session(self, app, session, response):
        cass_exp = int(app.permanent_session_lifetime.total_seconds())
        # ....

In this case we will have default Flask value + we don't need to process permanent property. What do you think?

add user and password into CassandraSessionInterface

At the moment the are no possibility to set username and password. Because CassandraSessionInterface initializes Cluster without auth_provider argument. I propose to add username and password into CassandraSessionInterface.__init__(). Example:

class CassandraSessionInterface(SessionInterface):

    def __init__(self, keyspace, cluster=None, port=9042, username=None, password=None):
            if username and password:
                   auth_provider = PlainTextAuthProvider(username, password))
            else:
                  auth_provider = None
            cluster = Cluster(cluster, port=port, auth_provider=auth_provider)
            # ....

What do you think?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.