def dstore(self, request, store, secret_key): if request.param == 'hash': return HashDecorator(store) elif request.param == 'uuid': return self.ustore(store) elif request.param == 'hmac': return HMACDecorator(secret_key, store) elif request.param == 'prefix': return PrefixDecorator('SaMpLe_PrEfIX', store)
from flask_app.middleware import * from flask_app.middleware.csrf import CSRFProtectionExtension load_dotenv() # get environment variables configure_logging() # configure loggers before starting app app = Flask(__name__) app.config.update(**config) # Configure Session using standard web session files, # more store types available in simplekv package # Hash Decorator provides session id session_store = HashDecorator( WebFilesystemStore(os.getenv("FLASK_SESSION_FILE_PATH"), os.getenv("FLASK_SESSION_URL_PREFIX"))) KVSessionExtension(session_store, app) # Add CSRFProtect extension to flask app # NOTE: this extends flask_wtf.CSRFProtect class; see class definition for details CSRFProtectionExtension(app) # Create Api blueprint and add resources (routes) api_blueprint = Blueprint('api', __name__) api = ElectroAPI(api_blueprint, catch_all_404s=True) # contains custom error handler api.add_resource(BillResource, "/bills", "/bills/<int:id>", endpoint="bill") api.add_resource(UserResource, "/login", "/logout", endpoint="login") # Register blueprint to app
def templated_hashstore(self, store, hashfunc, idgen_template): return HashDecorator(store, hashfunc, idgen_template)
def hashstore(self, store, hashfunc): return HashDecorator(store, hashfunc)
def setUp(self): self.store = HashDecorator(DictStore()) self.hash_regexp = r'^[0-9a-f]{%d}$' % ( self.store.hashfunc().digest_size * 2, )
def setUp(self): TestHashGen.setUp(self) self.tmpdir = tempfile.mkdtemp() self.store = HashDecorator(FilesystemStore(self.tmpdir))