Support for systemd credentials
Hi!
It'd be nice for webmentiond to support the concept of "[credentials](https://systemd.io/CREDENTIALS/)" introduced by systemd. In short, it's a safer alternative to environment variables for configuring services :)
The way it works from the point of view of webmentiond is that instead of reading stuff from the environment it reads it from files located in a directory pointed by the `CREDENTIALS_DIRECTORY` environment variable (automatically set up by systemd or whatever other service manager).
Here's a simple example of how it could be implemented (note that credential names are namespaced by default):
```go
var credentialsDirectory string = os.Getenv("CREDENTIALS_DIRECTORY")
func getCredential(name string) string {
name = "org.webmentiond." + name
credential, err := os.ReadFile(path.Join(credentialsDirectory, name))
if err != nil {
log.Fatal(err)
}
return strings.TrimSpace(string(credential))
}
func main() {
if credentialsDirectory == "" {
log.Fatal("You must specify the CREDENTIALS_DIRECTORY environment variable")
}
mailHost := getCredential("mail.host")
mailUser := getCredential("mail.user")
mailPassword := getCredential("mail.password")
// ...
}
```
Bye!
1 条评论