args: add arg to disable api auth (for development!)
a long flag to type out, that requires debug to be enabled and results in a prompt to confirm your action.
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
lm "github.com/hrfee/jfa-go/logmessages"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *appContext) loadArgs(firstCall bool) {
|
func (app *appContext) loadArgs(firstCall bool) {
|
||||||
@@ -28,6 +30,8 @@ func (app *appContext) loadArgs(firstCall bool) {
|
|||||||
PPROF = flag.Bool("pprof", false, "Exposes pprof profiler on /debug/pprof.")
|
PPROF = flag.Bool("pprof", false, "Exposes pprof profiler on /debug/pprof.")
|
||||||
SWAGGER = flag.Bool("swagger", false, "Enable swagger at /swagger/index.html")
|
SWAGGER = flag.Bool("swagger", false, "Enable swagger at /swagger/index.html")
|
||||||
|
|
||||||
|
flag.BoolVar(&NO_API_AUTH_DO_NOT_USE, "disable-api-auth-do-not-use", false, "Disables API authentication. DO NOT USE!")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
if *help {
|
if *help {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
@@ -45,6 +49,16 @@ func (app *appContext) loadArgs(firstCall bool) {
|
|||||||
if *_LOADBAK != "" {
|
if *_LOADBAK != "" {
|
||||||
LOADBAK = *_LOADBAK
|
LOADBAK = *_LOADBAK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if NO_API_AUTH_DO_NOT_USE && *DEBUG {
|
||||||
|
NO_API_AUTH_DO_NOT_USE = false
|
||||||
|
buf := bufio.NewReader(os.Stdin)
|
||||||
|
app.err.Print(lm.NoAPIAuthPrompt)
|
||||||
|
sentence, err := buf.ReadBytes('\n')
|
||||||
|
if err == nil && strings.ContainsRune(string(sentence), 'y') {
|
||||||
|
NO_API_AUTH_DO_NOT_USE = true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if os.Getenv("SWAGGER") == "1" {
|
if os.Getenv("SWAGGER") == "1" {
|
||||||
|
|||||||
@@ -281,6 +281,7 @@ const (
|
|||||||
External = "external"
|
External = "external"
|
||||||
RegisterPprof = "Registered pprof"
|
RegisterPprof = "Registered pprof"
|
||||||
SwaggerWarning = "Warning: Swagger should not be used on a public instance."
|
SwaggerWarning = "Warning: Swagger should not be used on a public instance."
|
||||||
|
NoAPIAuthPrompt = `Disabling API auth is dangerous, only use locally for development. Disable it? [y/n]: `
|
||||||
|
|
||||||
// storage.go
|
// storage.go
|
||||||
ConnectDB = "Connected to DB \"%s\""
|
ConnectDB = "Connected to DB \"%s\""
|
||||||
|
|||||||
@@ -15,6 +15,11 @@ import (
|
|||||||
ginSwagger "github.com/swaggo/gin-swagger"
|
ginSwagger "github.com/swaggo/gin-swagger"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
// Disables authentication for the API. Do not use!
|
||||||
|
NO_API_AUTH_DO_NOT_USE = false
|
||||||
|
)
|
||||||
|
|
||||||
// loads HTML templates. If [files]/html_templates is set, alternative files inside the directory are loaded in place of the internal templates.
|
// loads HTML templates. If [files]/html_templates is set, alternative files inside the directory are loaded in place of the internal templates.
|
||||||
func (app *appContext) loadHTML(router *gin.Engine) {
|
func (app *appContext) loadHTML(router *gin.Engine) {
|
||||||
customPath := app.config.Section("files").Key("html_templates").MustString("")
|
customPath := app.config.Section("files").Key("html_templates").MustString("")
|
||||||
@@ -182,7 +187,12 @@ func (app *appContext) loadRoutes(router *gin.Engine) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
api := router.Group("/", app.webAuth())
|
var api *gin.RouterGroup
|
||||||
|
if NO_API_AUTH_DO_NOT_USE && *DEBUG {
|
||||||
|
api = router.Group("/")
|
||||||
|
} else {
|
||||||
|
api = router.Group("/", app.webAuth())
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range routePrefixes {
|
for _, p := range routePrefixes {
|
||||||
var user *gin.RouterGroup
|
var user *gin.RouterGroup
|
||||||
|
|||||||
Reference in New Issue
Block a user