Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
47 changes: 12 additions & 35 deletions cmd/fly.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ package cmd

import (
"io/fs"
"net/http"
"os"
"path/filepath"

"github.com/kindlyops/vbs/embeddy"
"github.com/labstack/echo/v5"
"github.com/muesli/coral"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
Expand Down Expand Up @@ -52,54 +50,33 @@ func flyServer(cmd *coral.Command, args []string) {
}

log.Debug().Msgf("running pocketbase with data dir %s\n", configDir)
app := pocketbase.NewWithConfig(&pocketbase.Config{
app := pocketbase.NewWithConfig(pocketbase.Config{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
pocketbase.Config is missing fields HideStartBanner, DefaultDev, DefaultEncryptionEnv, DefaultQueryTimeout, DataMaxOpenConns, DataMaxIdleConns, AuxMaxOpenConns, AuxMaxIdleConns, DBConnect (exhaustruct)

DefaultDataDir: configDir,
})

migrationsDir := "" // default to "pb_migrations" (for js) and "migrations" (for go)

// register the `migrate` command
migratecmd.MustRegister(app, app.RootCmd, &migratecmd.Options{
migratecmd.MustRegister(app, app.RootCmd, migratecmd.Config{
TemplateLang: migratecmd.TemplateLangGo, // or migratecmd.TemplateLangJS
Dir: migrationsDir,
Automigrate: true,
})

app.OnBeforeServe().Add(func(e *core.ServeEvent) error {
app.OnServe().BindFunc(func(e *core.ServeEvent) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
parameter name 'e' is too short for the scope of its usage (varnamelen)

public, err := fs.Sub(embeddy.GetNextFS(), "public")
if err != nil {
log.Fatal().Err(err).Msg("Could not access embedded public directory")
}
assetHandler := http.FileServer(http.FS(public))
e.Router.AddRoute(echo.Route{
Method: http.MethodGet,
Path: "/*",
Handler: echo.WrapHandler(assetHandler),
Middlewares: []echo.MiddlewareFunc{
apis.ActivityLogger(app),
//apis.RequireAdminAuth(),
},
})

e.Router.AddRoute(echo.Route{
Method: http.MethodPost,
Path: "/api/switcher/*",
Middlewares: []echo.MiddlewareFunc{
apis.ActivityLogger(app),
},
Handler: echo.WrapHandler(&Switcher{}),
})

e.Router.AddRoute(echo.Route{
Method: http.MethodPost,
Path: "/api/light/*",
Middlewares: []echo.MiddlewareFunc{
apis.ActivityLogger(app),
},
Handler: echo.WrapHandler(&Lighting{}),
})

return nil

// Serve static files
e.Router.GET("/*", apis.Static(public, true))

// Custom API routes
e.Router.POST("/api/switcher/*", apis.WrapStdHandler(&Switcher{}))
e.Router.POST("/api/light/*", apis.WrapStdHandler(&Lighting{}))

return e.Next()
})

if err := app.Start(); err != nil {
Expand Down
20 changes: 13 additions & 7 deletions cmd/lighting.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (

"github.com/hypebeast/go-osc/osc"
"github.com/kindlyops/vbs/embeddy"
"github.com/labstack/echo/v5"
"github.com/muesli/coral"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
Expand Down Expand Up @@ -53,14 +52,21 @@ func lightingBridge(cmd *coral.Command, args []string) {
assetHandler := http.FileServer(http.FS(public))

log.Debug().Msgf("Starting HTTP server at: http://%s\n", listenAddr)
e := echo.New()
e.GET("/*", echo.WrapHandler(assetHandler))
e.POST("/api/switcher/*", echo.WrapHandler(&Switcher{}))
e.POST("/api/light/*", echo.WrapHandler(&Lighting{}))
err = e.Start(listenAddr)

mux := http.NewServeMux()
mux.Handle("/", assetHandler)
mux.Handle("/api/switcher/", &Switcher{})
mux.Handle("/api/light/", &Lighting{})

server := &http.Server{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
G112: Potential Slowloris Attack because ReadHeaderTimeout is not configured in the http.Server (gosec)

Addr: listenAddr,
Handler: mux,
}

err = server.ListenAndServe()

if err != nil {
log.Error().Err(err).Msg("error from echo.Start")
log.Error().Err(err).Msg("error from http server")
}
}

Expand Down
16 changes: 13 additions & 3 deletions embeddy/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,26 @@ package embeddy

import (
"embed"

"github.com/labstack/echo/v5"
"fmt"
"io/fs"
)

//go:embed public
var publicDir embed.FS

// DistDirFS contains the embedded public directory files (without the "public" prefix)
var DistDirFS = echo.MustSubFS(publicDir, "public")
var DistDirFS = MustSubFS(publicDir, "public")

func GetNextFS() embed.FS {
return publicDir
}

// MustSubFS returns an fs.FS corresponding to the subtree rooted at dir.
// It panics if there's an error.
func MustSubFS(fsys fs.FS, dir string) fs.FS {
sub, err := fs.Sub(fsys, dir)
if err != nil {
panic(fmt.Errorf("failed to create sub FS: %w", err))
}
return sub
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [golangci] reported by reviewdog 🐶
return with no blank line before (nlreturn)

}
105 changes: 32 additions & 73 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/kindlyops/vbs

go 1.22.8
go 1.24.0

toolchain go1.24.13

require (
github.com/aws/aws-sdk-go v1.55.8
Expand All @@ -16,108 +18,65 @@ require (
github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/lipgloss v0.13.1
github.com/labstack/echo/v5 v5.0.0-20220201181537-ed2888cfa198
github.com/muesli/coral v1.0.0
github.com/pocketbase/pocketbase v0.16.5
github.com/pocketbase/pocketbase v0.36.2
)

require (
github.com/AlecAivazis/survey/v2 v2.3.6 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aws/aws-sdk-go-v2 v1.18.0 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.4.10 // indirect
github.com/aws/aws-sdk-go-v2/config v1.18.25 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.13.24 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.13.3 // indirect
github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.67 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.1.33 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.4.27 // indirect
github.com/aws/aws-sdk-go-v2/internal/ini v1.3.34 // indirect
github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.25 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.11 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.28 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.9.27 // indirect
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.14.2 // indirect
github.com/aws/aws-sdk-go-v2/service/s3 v1.33.1 // indirect
github.com/aws/aws-sdk-go-v2/service/sso v1.12.10 // indirect
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.14.10 // indirect
github.com/aws/aws-sdk-go-v2/service/sts v1.19.0 // indirect
github.com/aws/smithy-go v1.13.5 // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/harmonica v0.2.0 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/disintegration/imaging v1.6.2 // indirect
github.com/domodwyer/mailyak/v3 v3.6.0 // indirect
github.com/domodwyer/mailyak/v3 v3.6.2 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/ganigeorgiev/fexpr v0.3.0 // indirect
github.com/fatih/color v1.18.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
github.com/ganigeorgiev/fexpr v0.5.0 // indirect
github.com/go-ozzo/ozzo-validation/v4 v4.3.0 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/google/wire v0.5.0 // indirect
github.com/googleapis/gax-go/v2 v2.10.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/golang-jwt/jwt/v5 v5.3.1 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pocketbase/dbx v1.10.0 // indirect
github.com/pocketbase/dbx v1.11.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/afero v1.9.5 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasttemplate v1.2.2 // indirect
go.opencensus.io v0.24.0 // indirect
gocloud.dev v0.29.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/image v0.7.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.8.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.11.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.125.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230530153820-e85fd2cbaebc // indirect
google.golang.org/grpc v1.55.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/image v0.35.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/oauth2 v0.34.0 // indirect
golang.org/x/sync v0.19.0 // indirect
golang.org/x/sys v0.40.0 // indirect
golang.org/x/term v0.39.0 // indirect
golang.org/x/text v0.33.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
lukechampine.com/uint128 v1.3.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.6 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/sqlite v1.22.1 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.1.0 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.44.3 // indirect
)
Loading
Loading