drop toml dependency

This commit is contained in:
Denis Lehmann 2022-04-26 02:59:33 +02:00
parent 30fb726342
commit 4227e5e7f0
8 changed files with 40 additions and 32 deletions

View file

@ -23,11 +23,11 @@
├── alice
│   ├── big_buck_bunny.mkv
│   ├── elephants_dream.mkv
│   ├── rc.toml
│   ├── rc.conf
│   └── the_daily_dweebs.mkv
└── inbox
├── logo.svg
└── rc.toml
└── rc.conf
#+end_example
Then the following two routes exist:
@ -35,8 +35,8 @@
- =https://cloud.example.com/alice=
- =https://cloud.example.com/inbox=
This is determined by the presence of a =rc.toml= file in subdirectories in which the individual permissions for the routes can be set.
The configuration options can be [[#rctoml][seen below]].
This is determined by the presence of a =rc.conf= file in subdirectories in which the individual permissions for the routes can be set.
The configuration options can be [[#rcconf][seen below]].
All other routes, including =http://cloud.example.com=, return =404 Not Found=.
This repository contains the above listed =public= directory for testing /raincloud/ locally.
@ -45,7 +45,7 @@
: $ pip install -r requirements.txt
: $ ./run.py
Play around with the =rc.toml= files and create new directories to see how /raincloud/ behaves.
Play around with the =rc.conf= files and create new directories to see how /raincloud/ behaves.
No restarting is needed.
The password for the =alice= directory is =movie_night!=.
@ -100,20 +100,22 @@
Set them for example like this:
: >>> app = raincloud.create_app(base_path='/home/alice/public', secret_key='super_secret', cloud_name='myCloud')
*** =rc.toml=
*** =rc.conf=
:properties:
:custom_id: rctoml
:custom_id: rcconf
:end:
A =rc.toml= file can contain up to three configuration parameters:
A =rc.conf= file can contain up to three configuration parameters:
#+begin_src conf
[raincloud]
#+begin_src toml
# Insert a password hash to enable password protection for this directory
# Use one of the following commands to create a hash:
# mkpasswd -m sha-256
# mkpasswd -m sha-512
#
#hashed_password = ""
#hashed_password =
# Set this to 'true' to allow file downloads from this directory
download = false

View file

@ -16,7 +16,6 @@
flask = nixpkgs.legacyPackages.${system}.python3Packages.flask;
gunicorn = nixpkgs.legacyPackages.${system}.python3Packages.gunicorn;
raincloud = self.packages.${system}.raincloud;
toml = nixpkgs.legacyPackages.${system}.python3Packages.toml;
cfg = config.services.raincloud;
@ -80,7 +79,7 @@
environment =
let
penv = python.buildEnv.override {
extraLibs = [ flask raincloud toml ];
extraLibs = [ flask raincloud ];
};
in
{
@ -131,7 +130,6 @@
src = self;
propagatedBuildInputs = with pkgs; [
python3Packages.flask
python3Packages.toml
];
};
defaultPackage = self.packages.${system}.raincloud;
@ -142,7 +140,6 @@
python3
python3Packages.flask
python3Packages.gunicorn
python3Packages.toml
];
};
}

View file

@ -1,9 +1,11 @@
[raincloud]
# Insert a password hash to enable password protection for this directory
# Use one of the following commands to create a hash:
# mkpasswd -m sha-256
# mkpasswd -m sha-512
#
hashed_password = "$5$s9bLebSgS9O4CPDR$xQF4/bWQqv5rqaq3Or2oTpXBW4TZdjFtBeH9CwZiw72" # movie_night!
hashed_password = $5$s9bLebSgS9O4CPDR$xQF4/bWQqv5rqaq3Or2oTpXBW4TZdjFtBeH9CwZiw72
# Set this to 'true' to allow file downloads from this directory
download = true

View file

@ -1,9 +1,11 @@
[raincloud]
# Insert a password hash to enable password protection for this directory
# Use one of the following commands to create a hash:
# mkpasswd -m sha-256
# mkpasswd -m sha-512
#
#hashed_password = ""
#hashed_password =
# Set this to 'true' to allow file downloads from this directory
download = false

View file

@ -1,6 +1,6 @@
from datetime import datetime
from pathlib import Path
import toml
import configparser
class RaincloudIOException(Exception):
@ -16,31 +16,37 @@ class DirectoryHandler:
)
def get_config(self, directory):
"""Load a 'rc.toml' file from given directory.
"""Load a 'rc.conf' file from given directory.
Parameters:
directory - basepath of 'rc.toml'
directory - basepath of 'rc.conf'
Returns: Dictionary of config parameters
"""
path = self.base_path / directory / "rc.toml"
path = self.base_path / directory / "rc.conf"
if path.exists():
config = {}
config["directory"] = directory
parsed_config = toml.load(path)
config_parser = configparser.ConfigParser()
config_parser.read(path)
parsed_config = dict(config_parser["raincloud"])
config["hashed_password"] = (
parsed_config["hashed_password"]
if "hashed_password" in parsed_config
else None
)
config["download"] = (
parsed_config["download"] if "download" in parsed_config else False
)
config["upload"] = (
parsed_config["upload"] if "upload" in parsed_config else False
)
config["download"] = False
if (
"download" in parsed_config
and parsed_config["download"].lower() == "true"
):
config["download"] = True
config["upload"] = False
if "upload" in parsed_config and parsed_config["upload"].lower() == "true":
config["upload"] = True
return config
else:
@ -52,7 +58,7 @@ class DirectoryHandler:
file_paths = [f for f in path.glob("*") if f.is_file()]
files = []
for p in file_paths:
if p.name != "rc.toml":
if p.name != "rc.conf":
files.append(p.name)
return files

View file

@ -82,7 +82,7 @@ def create_app(base_path, secret_key, cloud_name="raincloud"):
# Download
else:
if config["download"] and filename != "rc.toml":
if config["download"] and filename != "rc.conf":
return send_from_directory(
dh.get_absolute_path(directory), filename
)
@ -94,7 +94,7 @@ def create_app(base_path, secret_key, cloud_name="raincloud"):
if config["upload"]:
f = request.files["file"]
filename = secure_filename(f.filename)
if filename != "rc.toml":
if filename != "rc.conf":
dh.save_to_directory(f, directory, filename)
# Reload

View file

@ -1,2 +1 @@
flask
toml

View file

@ -6,5 +6,5 @@ setup(
packages=find_packages(),
include_package_data=True,
zip_safe=False,
install_requires=["flask", "toml"],
install_requires=["flask"],
)