- Parse toml configuration file, see https://github.com/qdm12/gluetun-wiki/blob/main/setup/advanced/control-server.md#authentication - Retro-compatible with existing AND documented routes, until after v3.41 release - Log a warning if an unprotected-by-default route is accessed unprotected - Authentication methods: none, apikey, basic - `genkey` command to generate API keys Co-authored-by: Joe Jose <45399349+joejose97@users.noreply.github.com>
36 lines
842 B
Go
36 lines
842 B
Go
package auth
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/pelletier/go-toml/v2"
|
|
)
|
|
|
|
// Read reads the toml file specified by the filepath given.
|
|
// If the file does not exist, it returns empty settings and no error.
|
|
func Read(filepath string) (settings Settings, err error) {
|
|
file, err := os.Open(filepath)
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return Settings{}, nil
|
|
}
|
|
return settings, fmt.Errorf("opening file: %w", err)
|
|
}
|
|
decoder := toml.NewDecoder(file)
|
|
decoder.DisallowUnknownFields()
|
|
err = decoder.Decode(&settings)
|
|
if err == nil {
|
|
return settings, nil
|
|
}
|
|
|
|
strictErr := new(toml.StrictMissingError)
|
|
ok := errors.As(err, &strictErr)
|
|
if !ok {
|
|
return settings, fmt.Errorf("toml decoding file: %w", err)
|
|
}
|
|
return settings, fmt.Errorf("toml decoding file: %w:\n%s",
|
|
strictErr, strictErr.String())
|
|
}
|