feat: use persistent configuration file
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
package player
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"forge.cadoles.com/arcad/arcast"
|
||||
"forge.cadoles.com/arcad/arcast/pkg/browser/lorca"
|
||||
"forge.cadoles.com/arcad/arcast/pkg/selfsigned"
|
||||
"forge.cadoles.com/arcad/arcast/pkg/config"
|
||||
"forge.cadoles.com/arcad/arcast/pkg/server"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli/v2"
|
||||
@ -15,9 +17,15 @@ import (
|
||||
|
||||
func Run() *cli.Command {
|
||||
defaults := lorca.NewOptions()
|
||||
|
||||
return &cli.Command{
|
||||
Name: "run",
|
||||
Flags: []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
Name: "config",
|
||||
EnvVars: []string{"ARCAST_DESKTOP_CONFIG"},
|
||||
Value: config.DefaultConfigFile(context.Background()),
|
||||
},
|
||||
&cli.StringSliceFlag{
|
||||
Name: "additional-chrome-arg",
|
||||
EnvVars: []string{"ARCAST_DESKTOP_ADDITIONAL_CHROME_ARGS"},
|
||||
@ -34,8 +42,8 @@ func Run() *cli.Command {
|
||||
Value: ":",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "tls-address",
|
||||
EnvVars: []string{"ARCAST_DESKTOP_TLS_ADDRESS"},
|
||||
Name: "https-address",
|
||||
EnvVars: []string{"ARCAST_DESKTOP_HTTPS_ADDRESS"},
|
||||
Value: ":",
|
||||
},
|
||||
&cli.IntFlag{
|
||||
@ -55,12 +63,10 @@ func Run() *cli.Command {
|
||||
},
|
||||
},
|
||||
Action: func(ctx *cli.Context) error {
|
||||
configFile := ctx.String("config")
|
||||
windowHeight := ctx.Int("window-height")
|
||||
windowWidth := ctx.Int("window-width")
|
||||
chromeArgs := addFlagsPrefix(ctx.StringSlice("additional-chrome-arg")...)
|
||||
enableApps := ctx.Bool("apps")
|
||||
serverAddress := ctx.String("address")
|
||||
serverTLSAddress := ctx.String("tls-address")
|
||||
|
||||
browser := lorca.NewBrowser(
|
||||
lorca.WithAdditionalChromeArgs(chromeArgs...),
|
||||
@ -84,24 +90,43 @@ func Run() *cli.Command {
|
||||
}
|
||||
}()
|
||||
|
||||
instanceID := ctx.String("instance-id")
|
||||
if instanceID == "" {
|
||||
instanceID = server.NewRandomInstanceID()
|
||||
conf := config.DefaultConfig()
|
||||
|
||||
logger.Info(ctx.Context, "loading or creating configuration file", logger.F("filename", configFile))
|
||||
if err := config.LoadOrCreate(ctx.Context, configFile, conf, config.DefaultTransforms...); err != nil {
|
||||
logger.Error(ctx.Context, "could not load configuration file", logger.CapturedE(errors.WithStack(err)))
|
||||
}
|
||||
|
||||
cert, err := selfsigned.NewLANCert()
|
||||
instanceID := ctx.String("instance-id")
|
||||
if instanceID != "" {
|
||||
conf.InstanceID = instanceID
|
||||
}
|
||||
|
||||
cert, err := tls.X509KeyPair(conf.HTTPS.Cert, conf.HTTPS.Key)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "could not generate self signed certificate")
|
||||
return errors.Wrap(err, "could not parse tls cert/key pair")
|
||||
}
|
||||
|
||||
if ctx.IsSet("apps") {
|
||||
conf.Apps.Enabled = ctx.Bool("apps")
|
||||
}
|
||||
|
||||
if ctx.IsSet("address") {
|
||||
conf.HTTP.Address = ctx.String("address")
|
||||
}
|
||||
|
||||
if ctx.IsSet("https-address") {
|
||||
conf.HTTPS.Address = ctx.String("tls-address")
|
||||
}
|
||||
|
||||
server := server.New(browser,
|
||||
server.WithInstanceID(instanceID),
|
||||
server.WithAppsEnabled(enableApps),
|
||||
server.WithDefaultApp("home"),
|
||||
server.WithInstanceID(conf.InstanceID),
|
||||
server.WithAppsEnabled(conf.Apps.Enabled),
|
||||
server.WithDefaultApp(conf.Apps.DefaultApp),
|
||||
server.WithApps(arcast.DefaultApps...),
|
||||
server.WithAddress(serverAddress),
|
||||
server.WithTLSAddress(serverTLSAddress),
|
||||
server.WithTLSCertificate(cert),
|
||||
server.WithAddress(conf.HTTP.Address),
|
||||
server.WithTLSAddress(conf.HTTPS.Address),
|
||||
server.WithTLSCertificate(&cert),
|
||||
)
|
||||
|
||||
if err := server.Start(); err != nil {
|
||||
|
Reference in New Issue
Block a user