mirror of
https://github.com/sosedoff/pgweb.git
synced 2024-12-14 10:23:02 +03:00
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]
|
||||
|
||||
Application Options:
|
||||
-v, --version Print version
|
||||
-d, --debug Enable debugging mode (false)
|
||||
--url= Database connection string
|
||||
--host= Server hostname or IP (localhost)
|
||||
--port= Server port (5432)
|
||||
--user= Database user (postgres)
|
||||
--pass= Password for user
|
||||
--db= Database name (postgres)
|
||||
--ssl= SSL option (disable)
|
||||
--listen= HTTP server listen port (8080)
|
||||
-v, --version Print version
|
||||
-d, --debug Enable debugging mode (false)
|
||||
--url= Database connection string
|
||||
--host= Server hostname or IP (localhost)
|
||||
--port= Server port (5432)
|
||||
--user= Database user (postgres)
|
||||
--pass= Password for user
|
||||
--db= Database name (postgres)
|
||||
--ssl= SSL option (disable)
|
||||
--listen= HTTP server listen port (8080)
|
||||
--auth-user= HTTP basic auth user
|
||||
--auth-pass= HTTP basic auth password
|
||||
```
|
||||
|
||||
## 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"`
|
||||
Ssl string `long:"ssl" description:"SSL option" default:"disable"`
|
||||
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
|
||||
@ -96,6 +98,12 @@ func initOptions() {
|
||||
func startServer() {
|
||||
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("/databases", API_GetDatabases)
|
||||
router.GET("/info", API_Info)
|
||||
|
Loading…
Reference in New Issue
Block a user