Commit 1585b736 authored by ale's avatar ale

Allow setting command-line options from the environment

parent 60e3cbb2
Pipeline #1134 passed with stages
in 48 seconds
......@@ -10,6 +10,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"git.autistici.org/ai3/go-common/serverutil"
assetfs "github.com/elazarl/go-bindata-assetfs"
......@@ -18,15 +19,22 @@ import (
)
var (
addr = flag.String("addr", ":3000", "tcp `address` to listen on")
configPath = flag.String("config", "/etc/float/dashboard.yml", "dashboard config `file`")
floatServicesPath = flag.String("services", "/etc/float/services.json", "float services `file`")
addr = flag.String("addr", getenv("ADDR", ":3000"), "tcp `address` to listen on")
configPath = flag.String("config", getenv("CONFIG", "/etc/float/dashboard.yml"), "dashboard config `file`")
floatServicesPath = flag.String("services", getenv("SERVICES", "/etc/float/services.json"), "float services `file`")
tpl *template.Template
config *Config
services ServiceMap
)
func getenv(k, dflt string) string {
if s := os.Getenv(k); s != "" {
return s
}
return dflt
}
// Config for the application.
type Config struct {
Domain string `yaml:"domain"`
......@@ -36,7 +44,7 @@ type Config struct {
}
func readYAML(path string, obj interface{}) error {
data, err := ioutil.ReadFile(path)
data, err := ioutil.ReadFile(path) // nolint: gosec
if err != nil {
return err
}
......
......@@ -74,22 +74,24 @@ var sriMap = map[string]string{
}
io.WriteString(w, `}
// SRIScript returns a <script> tag with resource integrity attributes.
func SRIScript(uri string) template.HTML {
s := fmt.Sprintf("<script src=\"%s\"", uri)
if sri, ok := sriMap[uri]; ok {
s += fmt.Sprintf(" crossorigin=\"\" integrity=\"%s\"", sri)
}
s += "></script>"
return template.HTML(s)
return template.HTML(s) // nolint: gosec
}
// SRIStylesheet returns a <link> tag with resource integrity attributes.
func SRIStylesheet(uri string) template.HTML {
s := fmt.Sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"", uri)
if sri, ok := sriMap[uri]; ok {
s += fmt.Sprintf(" integrity=\"%s\"", sri)
}
s += ">"
return template.HTML(s)
return template.HTML(s) // nolint: gosec
}
`)
......
......@@ -6,28 +6,30 @@ import (
)
var sriMap = map[string]string{
"/static/css/style.css": "sha384-OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb",
"/static/js/bootstrap.bundle.min.js": "sha384-CS0nxkpPy+xUkNGhObAISrkg/xjb3USVCwy+0/NMzd5VxgY4CMCyTkItmy5n0voC",
"/static/js/jquery.slim.min.js": "sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo",
"/static/css/bootstrap.min.css": "sha384-Smlep5jCw/wG7hdkwQ/Z5nLIefveQRIY9nfy6xoR1uRYBtpZgI6339F5dgvm/e9B",
"/static/css/open-iconic-bootstrap.min.css": "sha384-wWci3BOzr88l+HNsAtr3+e5bk9qh5KfjU6gl/rbzfTYdsAVHBEbxB33veLYmFg/a",
"/static/css/style.css": "sha384-OLBgp1GsljhM2TJ+sbHjaiH9txEUvgdDTAzHv2P24donTt6/529l+9Ua0vFImLlb",
"/static/js/bootstrap.bundle.min.js": "sha384-CS0nxkpPy+xUkNGhObAISrkg/xjb3USVCwy+0/NMzd5VxgY4CMCyTkItmy5n0voC",
}
// SRIScript returns a <script> tag with resource integrity attributes.
func SRIScript(uri string) template.HTML {
s := fmt.Sprintf("<script src=\"%s\"", uri)
if sri, ok := sriMap[uri]; ok {
s += fmt.Sprintf(" crossorigin=\"\" integrity=\"%s\"", sri)
}
s += "></script>"
return template.HTML(s)
return template.HTML(s) // nolint: gosec
}
// SRIStylesheet returns a <link> tag with resource integrity attributes.
func SRIStylesheet(uri string) template.HTML {
s := fmt.Sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\"", uri)
if sri, ok := sriMap[uri]; ok {
s += fmt.Sprintf(" integrity=\"%s\"", sri)
}
s += ">"
return template.HTML(s)
return template.HTML(s) // nolint: gosec
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment