1
0
Fork 0
mirror of https://github.com/gocsaf/csaf.git synced 2025-12-23 00:32:55 +01:00
gocsaf/cmd/csaf_provider/main.go
JanHoefelmeyer 46f79a9e24
Bailout unknown config (#216)
* provider now checks for undecoded config entries and returns an error if any are found

* Specific error message now in server logs, more general message for user

* Changes spaces to tabs for formatting consistency

* Further formatting

* Improved handling of undecoded TOML fields in config.

* aggregator now checks for not decoded config options

Co-authored-by: Jan Höfelmeyer <Jan Höfelmeyer jhoefelmeyer@intevation.de>
Co-authored-by: Sascha L. Teichmann <sascha.teichmann@intevation.de>
2022-07-12 14:07:12 +02:00

66 lines
1.5 KiB
Go

// This file is Free Software under the MIT License
// without warranty, see README.md and LICENSES/MIT.txt for details.
//
// SPDX-License-Identifier: MIT
//
// SPDX-FileCopyrightText: 2021 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
// Software-Engineering: 2021 Intevation GmbH <https://intevation.de>
package main
import (
"fmt"
"log"
"net/http"
"net/http/cgi"
"os"
"github.com/csaf-poc/csaf_distribution/util"
"github.com/jessevdk/go-flags"
)
type options struct {
Version bool `long:"version" description:"Display version of the binary"`
}
const cgiRequired = "The csaf_provider is a cgi binary and is designed to be served via a web server."
func ensureCGI() {
if _, ok := os.LookupEnv("REQUEST_METHOD"); !ok {
fmt.Println(cgiRequired)
fmt.Println("Version: " + util.SemVersion)
os.Exit(1)
}
}
func main() {
var opts options
parser := flags.NewParser(&opts, flags.Default)
parser.Parse()
if opts.Version {
fmt.Println(util.SemVersion)
return
}
ensureCGI()
cfg, err := loadConfig()
if err != nil {
cgi.Serve(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
http.Error(rw, "Something went wrong. Check server logs for more details",
http.StatusInternalServerError)
}))
log.Fatalf("error: %v\n", err)
}
c, err := newController(cfg)
if err != nil {
log.Fatalf("error: %v\n", err)
}
pim := newPathInfoMux()
c.bind(pim)
if err := cgi.Serve(pim); err != nil {
log.Fatalf("error: %v\n", err)
}
}