Implement HTTP basic authentication
This commit is contained in:
parent
ad0bc43eeb
commit
44b429b459
22
README.md
22
README.md
@ -68,16 +68,18 @@ Usage:
|
|||||||
pgweb [OPTIONS]
|
pgweb [OPTIONS]
|
||||||
|
|
||||||
Application Options:
|
Application Options:
|
||||||
-v, --version Print version
|
-v, --version Print version
|
||||||
-d, --debug Enable debugging mode (false)
|
-d, --debug Enable debugging mode (false)
|
||||||
--url= Database connection string
|
--url= Database connection string
|
||||||
--host= Server hostname or IP (localhost)
|
--host= Server hostname or IP (localhost)
|
||||||
--port= Server port (5432)
|
--port= Server port (5432)
|
||||||
--user= Database user (postgres)
|
--user= Database user (postgres)
|
||||||
--pass= Password for user
|
--pass= Password for user
|
||||||
--db= Database name (postgres)
|
--db= Database name (postgres)
|
||||||
--ssl= SSL option (disable)
|
--ssl= SSL option (disable)
|
||||||
--listen= HTTP server listen port (8080)
|
--listen= HTTP server listen port (8080)
|
||||||
|
--auth-user= HTTP basic auth user
|
||||||
|
--auth-pass= HTTP basic auth password
|
||||||
```
|
```
|
||||||
|
|
||||||
## Compile from source
|
## Compile from source
|
||||||
|
8
main.go
8
main.go
@ -23,6 +23,8 @@ var options struct {
|
|||||||
DbName string `long:"db" description:"Database name" default:"postgres"`
|
DbName string `long:"db" description:"Database name" default:"postgres"`
|
||||||
Ssl string `long:"ssl" description:"SSL option" default:"disable"`
|
Ssl string `long:"ssl" description:"SSL option" default:"disable"`
|
||||||
HttpPort uint `long:"listen" description:"HTTP server listen port" default:"8080"`
|
HttpPort uint `long:"listen" description:"HTTP server listen port" default:"8080"`
|
||||||
|
AuthUser string `long:"auth-user" description:"HTTP basic auth user"`
|
||||||
|
AuthPass string `long:"auth-pass" description:"HTTP basic auth password"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var dbClient *Client
|
var dbClient *Client
|
||||||
@ -96,6 +98,12 @@ func initOptions() {
|
|||||||
func startServer() {
|
func startServer() {
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
|
||||||
|
// Enable HTTP basic authentication only if both user and password are set
|
||||||
|
if options.AuthUser != "" && options.AuthPass != "" {
|
||||||
|
auth := map[string]string{options.AuthUser: options.AuthPass}
|
||||||
|
router.Use(gin.BasicAuth(auth))
|
||||||
|
}
|
||||||
|
|
||||||
router.GET("/", API_Home)
|
router.GET("/", API_Home)
|
||||||
router.GET("/databases", API_GetDatabases)
|
router.GET("/databases", API_GetDatabases)
|
||||||
router.GET("/info", API_Info)
|
router.GET("/info", API_Info)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user