Skip to content

Commit

Permalink
Docs - add detail to custom backend and pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Darby committed May 23, 2022
1 parent 4f0ea10 commit d888bbd
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
16 changes: 12 additions & 4 deletions docs/custom_backend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,21 @@ Another way to provide a custom backend using flask proxy could be:
import MyCustomBackend
from flask import current_app
from medallion import application_instance, set_config
from medallion import application_instance, set_config, register_blueprints
MyCustomBackend.init() # Do some setup before attaching to application... (Imagine other steps happening here)
with application_instance.app_context():
current_app.medallion_backend = MyCustomBackend
# Do some other stuff...
set_config(application_instance, {...})
set_config(application_instance, "backend", {
"backend": {
"module": "mypackage.with_backends",
"module_class": "MyCustomBackend",
}
})
register_blueprints(application_instance)
application_instance.run()
How to use a different authentication library
Expand All @@ -109,7 +115,7 @@ If you need or prefer a library different from ``Flask-HTTPAuth``, you can overr
.. code-block:: python
from flask import current_app
from medallion import application_instance, auth, set_config, init_backend
from medallion import application_instance, auth, set_config, init_backend, register_blueprints
# This is a dummy implementation of Flask Auth that always returns false
dummy_auth = class DummyAuth(object):
Expand All @@ -128,6 +134,7 @@ If you need or prefer a library different from ``Flask-HTTPAuth``, you can overr
set_config(application_instance, {...})
init_backend(application_instance, {...})
register_blueprints(application_instance)
application_instance.run()
How to use a different backend to control users
Expand All @@ -139,7 +146,7 @@ Our implementation of a users authentication system is not suitable for a produc
import MyCustomDBforUsers
from flask import current_app
from medallion import application_instance, set_config
from medallion import application_instance, set_config, register_blueprints
# This is a dummy implementation of Flask Auth that always returns false
dummy_auth = class DummyAuth(object):
Expand All @@ -163,4 +170,5 @@ Our implementation of a users authentication system is not suitable for a produc
current_app.users_config = db # This will make it available inside the Flask instance in case you decide to perform changes to the internal blueprints.
init_backend(application_instance, {...})
register_blueprints(application_instance)
application_instance.run()
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Welcome to medallion's documentation!

compatibility
custom_backend
page_size
mongodb_schema
contributing

Expand Down
30 changes: 30 additions & 0 deletions docs/page_size.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Custom Page Size
=========================

How to set pagination limits
---------------------------------

To specify a pagination limit with medallion you should call ``set_config``
when creating your application.

.. code-block:: python
from medallion import application_instance, set_config
set_config(application_instance, "taxii", {"taxii": {"max_page_size": 100}})
How to access the pagination limit
-------------------------------

From within your application, you can then access the configured pagination limit
through the ``current_app`` object.

.. code-block:: python
from medallion import current_app
page_size = current_app.taxii_config["max_page_size"]

0 comments on commit d888bbd

Please sign in to comment.