mikicaivosevic / flask-cassandra-sessions Goto Github PK
View Code? Open in Web Editor NEWServer side sessions with Apache Cassandra
License: MIT License
Server side sessions with Apache Cassandra
License: MIT License
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?
Hello.
I propose to make some modifications in package. I will try to explain why:
cassandra.cluster.Cluster
settings (load_balancing_policy
, connection_class
etc.). Since the initialization of Cluster
occurs inside flask-cassandra-sessions
.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.dev
server.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?
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?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.