diff --git a/README.org b/README.org index 7064ea4..524e71b 100644 --- a/README.org +++ b/README.org @@ -52,7 +52,7 @@ A WSGI server like [[https://gunicorn.org/][Gunicorn]] can then be used to serve the app for example like this: - : $ gunicorn "raincloud:app()" + : $ gunicorn "raincloud:create_app(base_path='public', secret_key='i_am_a_key')" *Note* that currently only one worker is supported due to server side session caching. @@ -66,33 +66,32 @@ services.raincloud = { enable = true; basePath = "/var/lib/raincloud"; + secretKey = "i_am_a_key"; }; } #+end_src All configuration options are: - | Option | Description | Type | Default value | - |-----------+-----------------------------------+-------+---------------| - | address | Bind address of the server | =str= | =127.0.0.1= | - | port | Port on which the server listens | =int= | =8000= | - | user | User under which the server runs | =str= | =raincloud= | - | group | Group under which the server runs | =str= | =raincloud= | - | cloudName | Name of the raincloud | =str= | =raincloud= | - | basePath | Base path of the raincloud | =str= | | - | secretKey | Flask secret key | =str= | | + | Option | Description | Type | Default value | + |-----------+-----------------------------------+--------+---------------| + | address | Bind address of the server | =str= | =127.0.0.1= | + | port | Port on which the server listens | =int= | =8000= | + | user | User under which the server runs | =str= | =raincloud= | + | group | Group under which the server runs | =str= | =raincloud= | + | cloudName | Name of the raincloud | =str= | =raincloud= | + | basePath | Base path of the raincloud | =path= | | + | secretKey | Flask secret key | =str= | | ** Configuration - /raincloud/ provides two configuration options: + /raincloud/ provides three configuration options which can be passed to =raincloud.create_app()=: - - CLOUD_NAME :: Name of the raincloud - - SECRET_KEY :: Flask secret key - - BASE_PATH :: Base path of the raincloud + - =base_path= :: Base path of the raincloud + - =secret_key= :: Flask secret key + - =cloud_name= :: Cloud name (default: =raincloud=) - Those can e.g. be stored in a =raincloud_settings.py= file. - The filepath can directly be passed to =raincloud.app(/path/to/raincloud_settings.py)= or stored in an environment variable =$RAINCLOUD_SETTINGS=. - Look at the file =raincloud/default_settings.py= to see how to define them. + Look at the file =run.py= to see how to set them. *** =rc.toml= diff --git a/flake.nix b/flake.nix index 9d5bb2f..044814d 100644 --- a/flake.nix +++ b/flake.nix @@ -20,11 +20,6 @@ cfg = config.services.raincloud; - raincloud_config = nixpkgs.legacyPackages.${system}.writeText "raincloud_config.py" '' - CLOUD_NAME = "${cfg.cloudName}" - SECRET_KEY = "${cfg.secretKey}" - BASE_PATH = "${cfg.basePath}" - ''; in { options.services.raincloud = { @@ -64,7 +59,7 @@ }; basePath = mkOption { - type = types.str; + type = types.path; description = "Base path of the raincloud"; }; @@ -101,7 +96,7 @@ PermissionsStartOnly = true; ExecStart = '' - ${gunicorn}/bin/gunicorn "raincloud:app('${raincloud_config}')" \ + ${gunicorn}/bin/gunicorn "raincloud:create_app('${cfg.basePath}', '${cfg.secretKey}', '${cfg.cloudName}')" \ --bind=${cfg.address}:${toString cfg.port} ''; }; diff --git a/raincloud/__init__.py b/raincloud/__init__.py index e58bd62..a3a18c4 100755 --- a/raincloud/__init__.py +++ b/raincloud/__init__.py @@ -18,24 +18,14 @@ import crypt import werkzeug -def app(settings_file=None): +def create_app(base_path, secret_key, cloud_name="raincloud"): # Create app app = Flask(__name__) - - # Load config - app.config.from_object("raincloud.default_settings") - if settings_file: - app.config.from_pyfile(settings_file) - else: - app.config.from_envvar("RAINCLOUD_SETTINGS", silent=True) - - if not app.config["BASE_PATH"] or app.config["BASE_PATH"] == "": - print("No BASE_PATH defined") - exit(1) + app.config["SECRET_KEY"] = secret_key # Create handlers - dh = DirectoryHandler(app.config["BASE_PATH"]) + dh = DirectoryHandler(base_path) sh = SessionHandler() @app.route("/", methods=["GET", "POST"]) @@ -77,7 +67,7 @@ def app(settings_file=None): else: return render_template( "authenticate.html", - cloud_name=app.config["CLOUD_NAME"], + cloud_name=cloud_name, config=config, ) @@ -87,7 +77,7 @@ def app(settings_file=None): files = dh.get_files(directory) return render_template( "directory.html", - cloud_name=app.config["CLOUD_NAME"], + cloud_name=cloud_name, config=config, files=files, ) diff --git a/raincloud/default_settings.py b/raincloud/default_settings.py deleted file mode 100644 index a189dae..0000000 --- a/raincloud/default_settings.py +++ /dev/null @@ -1,3 +0,0 @@ -CLOUD_NAME = "raincloud" -SECRET_KEY = "dev" -BASE_PATH = "public" diff --git a/run.py b/run.py index 26ca89f..d886faf 100755 --- a/run.py +++ b/run.py @@ -3,5 +3,5 @@ import raincloud if __name__ == "__main__": - app = raincloud.app() + app = raincloud.create_app("public", "dev") app.run()