The vanity Netlify function was depending on micromdm.io/v2/pkg/log for
logging, creating an unnecessary circular dependency with the main
repository. Replace it with stdlib log.Logger to break this dependency.
Verified:
```shell
$ cd website && go build ./netlify-functions/vanity/
```
Added internal/frontend/account to implement account management code.
Added user registration templates and handlers.
Set up a sqlite and postgres database in package main.
The frontend server now runs a CSRF middleware on all paths except
/assets/. To enable CSRF the -csrf_key flag must be set. Instead of
enforcing the flag is set, I opted to log that CSRF is disabled. Not
running CSRF means I can test with curl.
In the future I might enforce that the flag must be set in release builds.
Moved directly into the root command struct. For clarity, since it's not
used anywhere else. Might consider something else if there are
sub-commands with shared options.
Also added `MICROMDM` as the env var prefix.
Added tests to validate the process receiving signals:
- SIGTERM and SIGINT exit.
- SIGUSR2 swaps logs
Removed the empty Fprintln in main. Turns out stderr isn't thread safe
to write from multiple locations. The logger, which is otherwise the
only stderr writing goroutine creates a sync writer. But the stderr in
main remains unsafe. This is something to fix later?
There are also races happening with the swap log test, but only when the
test runs in parallel. I'm not sure what's happening there... added a
flag to make this test synchronous for now.
Tests that depend on signals don't run on windows. That's a big todo.
I moved SIGUSR2 behind build tags, so the binary will at least compile.
- cmd/micromdm now has a simple test.
- changed flagset defaults to support testing and remove default side
effects. Go flags write to os.Stderr and call os.Exit(2) when parsing
usage.
- Added the concept of a "trace id", a unique ID which gets associated
with every log/request by default. Will eventually use
opentelemetry/opentracing, or perhaps something better... Still very
alpha quality + lots of dependencies/API surface to bring in. For the
purpose of MicroMDM, a unique identifier per request is fine.
- Added HTTP logging middleware.
internal/ is too limiting, and by using pkg/ we can use the libraries in
our own projects elsewhere. The netlify-functions/vanity service uses
pkg/log already.