81 lines
2.0 KiB
Go
81 lines
2.0 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
|
|
laravel "go.laravel.com"
|
|
"go.laravel.com/auth"
|
|
"go.laravel.com/auth/social"
|
|
"go.laravel.com/config"
|
|
"go.laravel.com/db"
|
|
"go.laravel.com/db/postgres"
|
|
"go.laravel.com/inertia"
|
|
"go.laravel.com/web"
|
|
|
|
"app/commands"
|
|
"app/database/migrations"
|
|
"app/database/schema"
|
|
"app/database/seeders"
|
|
"app/jobs"
|
|
"app/listeners"
|
|
"app/models"
|
|
"app/resources"
|
|
"app/routes"
|
|
"app/services"
|
|
)
|
|
|
|
const dexProvider social.Provider = "dex"
|
|
|
|
func Options() laravel.Options {
|
|
issuer := strings.TrimRight(os.Getenv("OPSPROOF_DEX_ISSUER"), "/")
|
|
return laravel.Options{
|
|
Routes: laravel.Routes{
|
|
Web: routes.Web,
|
|
API: routes.API,
|
|
Channels: routes.Channels,
|
|
Health: "/up",
|
|
},
|
|
Middleware: func(m *laravel.Middleware, cfg *config.Config) {
|
|
m.Web.Append(auth.Session[models.User]{})
|
|
m.Web.Append(inertia.Middleware{Share: share, ErrorPage: "Error"})
|
|
},
|
|
Views: resources.Views,
|
|
|
|
Drivers: []db.Driver{postgres.Driver},
|
|
Migrations: migrations.All,
|
|
Schema: schema.Dumps,
|
|
Seeders: seeders.All,
|
|
|
|
Commands: commands.All,
|
|
Schedule: commands.Schedule,
|
|
Listeners: listeners.All,
|
|
Jobs: jobs.All,
|
|
|
|
SocialProviders: map[social.Provider]social.OAuth2{
|
|
dexProvider: {
|
|
AuthorizeURL: issuer + "/auth",
|
|
TokenURL: issuer + "/token",
|
|
Scopes: []string{"openid", "profile", "email"},
|
|
ClientID: "opsproof",
|
|
ClientSecret: os.Getenv("OPSPROOF_DEX_CLIENT_SECRET"),
|
|
RedirectURI: os.Getenv("OPSPROOF_DEX_REDIRECT_URL"),
|
|
User: social.UserInfo(issuer + "/userinfo"),
|
|
},
|
|
},
|
|
Services: laravel.BuildServices(services.New),
|
|
}
|
|
}
|
|
|
|
func share(r *web.Request) (inertia.Props, error) {
|
|
operator := inertia.Props{"authenticated": false}
|
|
if user := models.CurrentUser(r); user != nil {
|
|
operator = inertia.Props{"authenticated": true, "name": user.Name, "email": user.Email, "role": "operator"}
|
|
}
|
|
return inertia.Props{
|
|
"name": config.From(r).App.Name,
|
|
"status": r.Session().Get("status"),
|
|
"operator": operator,
|
|
}, nil
|
|
}
|