✨ Credential of administration api
All checks were successful
release-nightly / build-docker (push) Successful in 1m3s
All checks were successful
release-nightly / build-docker (push) Successful in 1m3s
This commit is contained in:
@ -4,6 +4,7 @@ import (
|
||||
roadsign "code.smartsheep.studio/goatworks/roadsign/pkg"
|
||||
"fmt"
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/basicauth"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
@ -17,6 +18,13 @@ func InitAdministration() *fiber.App {
|
||||
TrustedProxies: viper.GetStringSlice("security.administration_trusted_proxies"),
|
||||
})
|
||||
|
||||
app.Use(basicauth.New(basicauth.Config{
|
||||
Realm: fmt.Sprintf("RoadSign v%s", roadsign.AppVersion),
|
||||
Authorizer: func(_, password string) bool {
|
||||
return password == viper.GetString("security.credential")
|
||||
},
|
||||
}))
|
||||
|
||||
webhooks := app.Group("/webhooks").Name("WebHooks")
|
||||
{
|
||||
webhooks.Put("/publish/:site/:upstream", doPublish)
|
||||
|
@ -5,11 +5,13 @@ import (
|
||||
"code.smartsheep.studio/goatworks/roadsign/pkg/administration"
|
||||
"code.smartsheep.studio/goatworks/roadsign/pkg/hypertext"
|
||||
"code.smartsheep.studio/goatworks/roadsign/pkg/sign"
|
||||
"github.com/google/uuid"
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/viper"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
@ -30,6 +32,16 @@ func main() {
|
||||
log.Panic().Err(err).Msg("An error occurred when loading settings.")
|
||||
}
|
||||
|
||||
// Present settings
|
||||
if len(viper.GetString("security.credential")) <= 0 {
|
||||
credential := strings.ReplaceAll(uuid.NewString(), "-", "")
|
||||
viper.Set("security.credential", credential)
|
||||
_ = viper.WriteConfig()
|
||||
|
||||
log.Warn().Msg("There isn't any api credential configured in settings.yml, auto generated a credential for api accessing.")
|
||||
log.Warn().Msgf("RoadSign auto generated api credential is %s", credential)
|
||||
}
|
||||
|
||||
// Load & init sign
|
||||
if err := sign.ReadInConfig(viper.GetString("paths.configs")); err != nil {
|
||||
log.Panic().Err(err).Msg("An error occurred when loading configurations.")
|
||||
@ -45,7 +57,7 @@ func main() {
|
||||
viper.GetString("hypertext.certificate.pem"),
|
||||
viper.GetString("hypertext.certificate.key"),
|
||||
)
|
||||
|
||||
|
||||
// Init administration server
|
||||
hypertext.RunServer(
|
||||
administration.InitAdministration(),
|
||||
|
@ -25,6 +25,7 @@ func (v *UpstreamConfig) GetType() string {
|
||||
protocol := strings.SplitN(v.URI, "://", 2)[0]
|
||||
switch protocol {
|
||||
case "file":
|
||||
case "files":
|
||||
return UpstreamTypeFile
|
||||
case "http":
|
||||
case "https":
|
||||
|
Reference in New Issue
Block a user