No description
This repository has been archived on 2026-04-20. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
  • Python 94.6%
  • Makefile 3.3%
  • Dockerfile 2.1%
Find a file
2021-10-05 14:51:01 +01:00
.flake8 Legacy code 2021-09-21 11:12:34 +01:00
.gitignore Legacy code 2021-09-21 11:12:34 +01:00
.gitlab-ci.yml Legacy code 2021-09-21 11:12:34 +01:00
Dockerfile Legacy code 2021-09-21 11:12:34 +01:00
Makefile Legacy code 2021-09-21 11:12:34 +01:00
Pipfile Legacy code 2021-09-21 11:12:34 +01:00
Pipfile.lock Legacy code 2021-09-21 11:12:34 +01:00
pyproject.toml Legacy code 2021-09-21 11:12:34 +01:00
README.md Legacy code 2021-10-05 14:51:01 +01:00
uploader.py Legacy code 2021-10-05 14:51:01 +01:00

Watches directories and copies files to blob storage

^^ as the title said.

Needs inotify and azure-storage-blob. Expects a file config.json to be in the current working directory when the script is ran.

All keys are required. slug is used to determine the blob storage upload prefix.

Config:

{
  "watches": [
    {
      "type": "simple",
      "path": "/home/some_username/uploads",
      "dsn": "blobstoragedsn",
      "container": "blob storage container",
      "slug": "upload/slug"
    },
    {
      "type": "regex",
      "base_path": "/home/some_username/uploads2",
      "regex": "(?P<folder>.+?)/(?P<something>.+).txt",
      "dsn": "blobstoragedsn",
      "container": "blob storage container",
      "dest_path": "upload/{folder}/{filename}"
    }
  ],
  "directories": [
    "/home/some_username/uploads/test1"
  ]
}

So the simple watch type just monitors a directory and uploads the filename prefixed by the slug.

The regex one will watch a base path, and match regex's against the filepath after the base path. I.e if you are watching /home/test and a file gets uploaded to /home/test/lol/n00b.txt then the regex will be provided lol/n00b.txt. The destination path can be templated and will be provided the filename (not including any path) and any capturing groups from the matched regex. This also assumes that none of the paths nest within one another, that they are all distinct paths.

The directories list will make directories if they don't exist, and chown them to the encompasing user and chmod them to 0700. The assumption has been made that the directories will reside in /home/user/* and that user IDs are >= 4000.

Testing

Run make test to launch a container. Make a config.json in the current directory (which would be this git repo). Make any users home dirs specified in the base paths, i.e. useradd -u 4000 -m user1. Run python3 uploader.py

Then exec into the container with docker exec -it sftp bash