Produit minimal viable #1
4 changed files with 50 additions and 8 deletions
|
@ -15,6 +15,15 @@ type Config struct {
|
||||||
// Cannot be set using environment variables
|
// Cannot be set using environment variables
|
||||||
Bottin bottin.APIClientConfig
|
Bottin bottin.APIClientConfig
|
||||||
|
|
||||||
|
DB struct {
|
||||||
|
Database string
|
||||||
|
Host string
|
||||||
|
Password string
|
||||||
|
Port int
|
||||||
|
SSLMode string
|
||||||
|
Username string
|
||||||
|
}
|
||||||
|
|
||||||
// TLS holds options for TLS / SSL / HTTPS
|
// TLS holds options for TLS / SSL / HTTPS
|
||||||
TLS struct {
|
TLS struct {
|
||||||
// Cert holds the public certificate (or path to a file containing one) for user interface TLS
|
// Cert holds the public certificate (or path to a file containing one) for user interface TLS
|
||||||
|
|
11
main.go
11
main.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"codeberg.org/vlbeaudoin/voki/v3"
|
"codeberg.org/vlbeaudoin/voki/v3"
|
||||||
|
@ -35,7 +36,15 @@ func run(ctx context.Context, cfg Config) error {
|
||||||
)}
|
)}
|
||||||
|
|
||||||
// connect to db
|
// connect to db
|
||||||
dbPool, err := pgxpool.New(ctx, "postgres://agendas:agendas@localhost:5432/agendas")
|
dbPool, err := pgxpool.New(ctx,
|
||||||
|
fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s",
|
||||||
|
cfg.DB.Username,
|
||||||
|
cfg.DB.Password,
|
||||||
|
cfg.DB.Host,
|
||||||
|
cfg.DB.Port,
|
||||||
|
cfg.DB.Database,
|
||||||
|
cfg.DB.SSLMode,
|
||||||
|
))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
32
server.go
32
server.go
|
@ -2,7 +2,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/subtle"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
|
||||||
"git.agecem.com/bottin/agendas/ui"
|
"git.agecem.com/bottin/agendas/ui"
|
||||||
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
|
"git.agecem.com/bottin/bottin/v10/pkg/bottin"
|
||||||
|
@ -25,12 +27,36 @@ func RunServer(ctx context.Context, cfg Config, bottinClient *bottin.APIClient,
|
||||||
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
e.Renderer = ui.NewRenderer()
|
r := ui.NewRenderer()
|
||||||
|
|
||||||
|
if r == nil {
|
||||||
|
return fmt.Errorf("nil renderer")
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Renderer = r
|
||||||
|
|
||||||
e.Pre(middleware.AddTrailingSlash())
|
e.Pre(middleware.AddTrailingSlash())
|
||||||
|
|
||||||
//TODO basic auth
|
// basic auth
|
||||||
//TODO log successful basic auths username
|
if len(cfg.Credentials) == 0 {
|
||||||
|
return fmt.Errorf("UI requires at least one credential (config key `Credentials` of type map[string]string)")
|
||||||
|
}
|
||||||
|
|
||||||
|
e.Use(middleware.BasicAuth(
|
||||||
|
func(username, password string, c echo.Context) (bool, error) {
|
||||||
|
for validUser, validPass := range cfg.Credentials {
|
||||||
|
userOK := subtle.ConstantTimeCompare([]byte(username), []byte(validUser)) == 1
|
||||||
|
passOK := subtle.ConstantTimeCompare([]byte(password), []byte(validPass)) == 1
|
||||||
|
if userOK && passOK {
|
||||||
|
// log successful basic auths username
|
||||||
|
log.Println("login ok for user", username)
|
||||||
|
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, nil
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
|
||||||
e.GET("/", UIIndex(ctx, bottinClient, dbClient))
|
e.GET("/", UIIndex(ctx, bottinClient, dbClient))
|
||||||
//e.GET("/transaction/", UIReadTransaction
|
//e.GET("/transaction/", UIReadTransaction
|
||||||
|
|
|
@ -112,10 +112,8 @@ button {
|
||||||
</ul>
|
</ul>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
<!--<p class="result">{{ .Result }}</p>--!>
|
{{ if .Error }}<p class="result">Erreur: {{ .Error }}</p> {{ end }}
|
||||||
<!--<p>{{ .Error }}</p>--!>
|
<p class="result">{{ .Result }}</p>
|
||||||
<!--<details><summary>Détails de connexion au bottin</summary>{{ .BottinHealth }}</details>--!>
|
|
||||||
<p class="result">{{ . }}</p>
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue