table of contents
JSON2FILE-GO(8) | JSON2FILE-GO(8) |
NAME¶
json2file-go - simple web server that provides entry points to store JSON files
SYNOPSIS¶
json2file-go
DESCRIPTION¶
The json2file-go(1) is a mini-application that runs as a Web server and is used to store the information sent by remote WebHooks in JSON format using the HTTP POST method.
Initially it has been used to process GitLab and Gitea WebHooks, but it can be used with other systems.
To verify that a caller has permission to store a file the program compares a JSON field or an HTTP HEADER to the secret it has configured for the given PATH. If the secret matches the program verifies that the data received is a valid JSON file and only stores it if it is.
The application is configured using environment variables and is designed to run inside a docker container or supervised with systemd if we are on a regular Linux server.
The application reads two mandatory environment variables:
The default value for this variable when using the systemd helper (see later) is /var/spool/json2file-go. If we use the application inside a container the idea is to set the value to /data (is a volume in the Dockerfile) and use a volume or mount a HOST directory there.
The variable is a string of the form: DIR1:TOKEN1;...;DIR#:TOKEN#
There is no default for this variable, it must be set.
Other optional variables include:
By default the system saves the JSON data received in the sub folder of J2F_BASEDIR that matches the requested directory name using files with names of the form TIMESTAMP.json, where the format of TIMESTAMP is YYYYmmdd-HHMMSS.MS.json.
While this program does nothing else, the files are usually processed by scripts launched by cron(8) or incrond(8).
To be able to work with systemd.socket(5) when the application launches it checks if the variable LISTEN_PID is set and in that case the J2F_HOST, J2F_PORT, J2F_BIND and J2F_SOCKET are ignored and the program listens on the first file descriptor available after stdout (the one with value 3) ignoring other descriptors if any (the daemon only listens on a file descriptor). Note that in this case the J2F_CERTFILE and J2F_KEYFILE are NOT ignored (systemd can pass us a file descriptor where we should use HTTPS).
If the program is launched without systemd and the variables J2F_HOST, J2F_PORT, J2F_BIND or J2F_SOCKET have no value the program tries to listen on 0.0.0.0:80 (or 0.0.0.0:443 if we provide a certificate and a key file).
CONFIGURATION¶
The binary does not read any configuration files by itself, but the packaged version includes a helper script (/usr/lib/json2file-go/json2file-go) to adjust environment variables when launching the program with systemd or other init systems (see the /usr/share/doc/json2file-go/examples directory for samples).
The launcher script reads files from the directory /etc/json2file-go and adjusts the variables as follows:
BUGS¶
None so far... ;)
AUTHOR¶
json2file was originally written by Sergio Talens-Oliag in Python using the Flask micro framework, later it was rewritten using FastAPI (another Python framework) and to make it lighter for container usage this third version in Go was born.
SEE ALSO¶
COPYING¶
Copyright (c) 2019-2020 Sergio Talens-Oliag. Free use of this software is granted under the terms of the Apache License Version 2.0.
2023-04-09 |