mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-23 00:32:55 +01:00
* Use a "/v2" in the module path to match the git version tag which lead with a 2. Change all mention of the module as dependency internally as well.
67 lines
1.5 KiB
Go
67 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 implements the csaf_provider.
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"net/http/cgi"
|
|
"os"
|
|
|
|
"github.com/csaf-poc/csaf_distribution/v2/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)
|
|
}
|
|
}
|