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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,2 +1 @@
flask flask
toml

View file

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