Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.19"]
go: ["1.25.6"]

steps:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: "1.19.6"
go-version: "1.25.6"

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
Expand Down
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ env:
- CGO_ENABLED=0

builds:
- main: ./cmd/short-season/short-season.go
- main: ./cmd/short-season/main.go
id: "cli"
binary: short-season
goos:
Expand All @@ -25,7 +25,7 @@ builds:
- goos: darwin
goarch: arm

- main: ./cmd/long-season/long-season.go
- main: ./cmd/long-season/main.go
id: "server"
binary: long-season
goos:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.19.6-alpine
FROM golang:1.25.6-alpine

WORKDIR $GOPATH/bin

Expand Down
2 changes: 0 additions & 2 deletions cmd/long-season/long-season.go → cmd/long-season/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"os"

"github.com/cristalhq/jwt/v3"
"github.com/go-chi/cors"

"github.com/hakierspejs/long-season/pkg/services/config"
Expand Down Expand Up @@ -70,7 +69,6 @@ func main() {

jwtSession := &jojo.JWT{
Secret: []byte(config.JWTSecret),
Algorithm: jwt.HS256,
AppName: config.AppName,
CookieKey: "jwt-token",
}
Expand Down
96 changes: 48 additions & 48 deletions cmd/short-season/short-season.go → cmd/short-season/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package main
import (
"bufio"
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"os"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
bolt "go.etcd.io/bbolt"
"golang.org/x/crypto/bcrypt"

Expand Down Expand Up @@ -48,12 +49,12 @@ type body struct {
Addresses []string `json:"addresses"`
}

func usersStorage(ctx *cli.Context) (storage.Users, func(), error) {
if ctx.String("database") == "" {
func usersStorage(cmd *cli.Command) (storage.Users, func(), error) {
if cmd.String("database") == "" {
return nil, nil, fmt.Errorf("database flag is not set. see admin command.")
}

boltPath := ctx.String("database")
boltPath := cmd.String("database")
boltDB, err := bolt.Open(boltPath, 0666, nil)
if err != nil {
return nil, nil, err
Expand All @@ -70,8 +71,8 @@ func usersStorage(ctx *cli.Context) (storage.Users, func(), error) {
return factoryStorage.Users(), closer, nil
}

func app() *cli.App {
return &cli.App{
func app() *cli.Command {
return &cli.Command{
Name: "short-season",
Usage: "command line interface tool for managing long-season",
Flags: []cli.Flag{
Expand All @@ -90,9 +91,9 @@ func app() *cli.App {
{
Name: "macs",
Usage: "upload list of mac addresses to given long-season API",
Action: func(ctx *cli.Context) error {
api := ctx.String("api")
apiKey := ctx.String("api-key")
Action: func(ctx context.Context, cmd *cli.Command) error {
api := cmd.String("api")
apiKey := cmd.String("api-key")

b := new(body)

Expand Down Expand Up @@ -142,24 +143,24 @@ func app() *cli.App {
Value: "bolt",
},
},
Action: func(ctx *cli.Context) error {
return cli.ShowCommandHelp(ctx, ctx.Command.Name)
Action: func(ctx context.Context, cmd *cli.Command) error {
return cli.DefaultShowCommandHelp(ctx, cmd, cmd.Name)
},
Subcommands: []*cli.Command{
Commands: []*cli.Command{
{
Name: "export",
Usage: "export all data from database as single json object to stdout",
Action: func(ctx *cli.Context) error {
dbPath := ctx.String("database")
dbType := ctx.String("database-type")
Action: func(ctx context.Context, cmd *cli.Command) error {
dbPath := cmd.String("database")
dbType := cmd.String("database-type")

factory, closer, err := abstract.Factory(dbPath, dbType)
if err != nil {
return fmt.Errorf("abstract.Factory: %w", err)
}
defer closer()

dump, err := exim.Export(ctx.Context, exim.ExportRequest{
dump, err := exim.Export(ctx, exim.ExportRequest{
UsersStorage: factory.Users(),
DevicesStorage: factory.Devices(),
TwoFactorStorage: factory.TwoFactor(),
Expand All @@ -178,9 +179,9 @@ func app() *cli.App {
{
Name: "import",
Usage: "import data as json object from stdin into database",
Action: func(ctx *cli.Context) error {
dbPath := ctx.String("database")
dbType := ctx.String("database-type")
Action: func(ctx context.Context, cmd *cli.Command) error {
dbPath := cmd.String("database")
dbType := cmd.String("database-type")

factory, closer, err := abstract.Factory(dbPath, dbType)
if err != nil {
Expand All @@ -194,7 +195,7 @@ func app() *cli.App {
return fmt.Errorf("json.NewDecoder.Decode: %w", err)
}

err = exim.Import(ctx.Context, exim.ImportRequest{
err = exim.Import(ctx, exim.ImportRequest{
Dump: dump,
UsersStorage: factory.Users(),
DevicesStorage: factory.Devices(),
Expand All @@ -212,27 +213,26 @@ func app() *cli.App {
Usage: "show users stored in given database",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "user-id",
Aliases: []string{"id", "i"},
HasBeenSet: false,
Required: false,
Name: "user-id",
Aliases: []string{"id", "i"},
Required: false,
},
},
Action: func(ctx *cli.Context) error {
storage, closer, err := usersStorage(ctx)
Action: func(ctx context.Context, cmd *cli.Command) error {
storage, closer, err := usersStorage(cmd)
if err != nil {
return err
}
defer closer()

users, err := storage.All(ctx.Context)
users, err := storage.All(ctx)
if err != nil {
return err
}

var user *models.User = nil
if ctx.IsSet("user-id") {
target := ctx.String("user-id")
if cmd.IsSet("user-id") {
target := cmd.String("user-id")
for _, u := range users {
if u.ID == target {
user = &models.User{
Expand All @@ -257,23 +257,23 @@ func app() *cli.App {

return json.NewEncoder(os.Stdout).Encode(&users)
},
Subcommands: []*cli.Command{
Commands: []*cli.Command{
{
Name: "delete",
Aliases: []string{"d"},
Usage: "delete user with given id",
Action: func(ctx *cli.Context) error {
if !ctx.IsSet("user-id") {
Action: func(ctx context.Context, cmd *cli.Command) error {
if !cmd.IsSet("user-id") {
return fmt.Errorf("set user-id flag with users subcommand")
}

storage, closer, err := usersStorage(ctx)
storage, closer, err := usersStorage(cmd)
defer closer()
if err != nil {
return err
}

return storage.Remove(ctx.Context, ctx.String("user-id"))
return storage.Remove(ctx, cmd.String("user-id"))
},
},
{
Expand All @@ -294,15 +294,15 @@ func app() *cli.App {
Required: true,
},
},
Action: func(ctx *cli.Context) error {
if !ctx.IsSet("nickname") || !ctx.IsSet("password") {
Action: func(ctx context.Context, cmd *cli.Command) error {
if !cmd.IsSet("nickname") || !cmd.IsSet("password") {
return fmt.Errorf("please set nickname and password for new user")
}

newNickname := ctx.String("nickname")
newPassword := ctx.String("password")
newNickname := cmd.String("nickname")
newPassword := cmd.String("password")

s, closer, err := usersStorage(ctx)
s, closer, err := usersStorage(cmd)
if err != nil {
return err
}
Expand All @@ -315,7 +315,7 @@ func app() *cli.App {
return err
}

_, err = s.New(ctx.Context, storage.UserEntry{
_, err = s.New(ctx, storage.UserEntry{
Nickname: newNickname,
HashedPassword: hashedPassword,
Private: false,
Expand All @@ -341,24 +341,24 @@ func app() *cli.App {
Value: "",
},
},
Action: func(ctx *cli.Context) error {
if !ctx.IsSet("user-id") {
Action: func(ctx context.Context, cmd *cli.Command) error {
if !cmd.IsSet("user-id") {
return fmt.Errorf("set user-id flag with users subcommand")
}

s, closer, err := usersStorage(ctx)
s, closer, err := usersStorage(cmd)
defer closer()
if err != nil {
return err
}

user, err := s.Read(ctx.Context, ctx.String("user-id"))
user, err := s.Read(ctx, cmd.String("user-id"))
if err != nil {
return err
}

newHashedPassword := []byte{}
if newPassword := ctx.String("password"); newPassword != "" {
if newPassword := cmd.String("password"); newPassword != "" {
newHashedPassword, err = bcrypt.GenerateFromPassword(
[]byte(newPassword), bcrypt.DefaultCost,
)
Expand All @@ -376,12 +376,12 @@ func app() *cli.App {
Password: user.HashedPassword,
Private: user.Private,
}, &users.Changes{
Nickname: ctx.String("nickname"),
Nickname: cmd.String("nickname"),
Password: newHashedPassword,
Online: nil,
})

return s.Update(ctx.Context, newUser.ID, func(u *storage.UserEntry) error {
return s.Update(ctx, newUser.ID, func(u *storage.UserEntry) error {
u.Nickname = newUser.Nickname
u.HashedPassword = newUser.Password
return nil
Expand All @@ -397,7 +397,7 @@ func app() *cli.App {
}

func main() {
if err := app().Run(os.Args); err != nil {
if err := app().Run(context.Background(), os.Args); err != nil {
fmt.Fprintf(os.Stderr, "short-season: %s\n", err.Error())
os.Exit(1)
}
Expand Down
55 changes: 21 additions & 34 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,48 +1,35 @@
module github.com/hakierspejs/long-season

// +heroku goVersion go1.19
// +heroku goVersion go1.25.6
// +heroku install ./cmd/...

go 1.19
go 1.25.6

require (
github.com/alioygur/gores v1.2.2
github.com/cristalhq/jwt/v3 v3.1.0
github.com/go-chi/chi v4.1.2+incompatible
github.com/go-chi/cors v1.2.1
github.com/golang-migrate/migrate/v4 v4.15.2
github.com/google/uuid v1.3.0
github.com/matryer/is v1.4.0
github.com/pquerna/otp v1.4.0
github.com/go-chi/chi/v5 v5.2.4
github.com/go-chi/cors v1.2.2
github.com/golang-jwt/jwt/v5 v5.3.0
github.com/golang-migrate/migrate/v4 v4.19.1
github.com/google/uuid v1.6.0
github.com/matryer/is v1.4.1
github.com/pquerna/otp v1.5.0
github.com/thinkofher/horror v0.1.2
github.com/urfave/cli/v2 v2.24.4
go.etcd.io/bbolt v1.3.7
golang.org/x/crypto v0.17.0
modernc.org/sqlite v1.20.4
github.com/urfave/cli/v3 v3.6.2
go.etcd.io/bbolt v1.4.3
golang.org/x/crypto v0.47.0
modernc.org/sqlite v1.44.3
)

require (
github.com/boombuler/barcode v1.0.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/boombuler/barcode v1.1.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.uber.org/atomic v1.10.0 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/tools v0.6.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.40.0 // indirect
modernc.org/ccgo/v3 v3.16.13 // indirect
modernc.org/libc v1.22.2 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.1.3 // indirect
modernc.org/token v1.1.0 // indirect
golang.org/x/exp v0.0.0-20260112195511-716be5621a96 // indirect
golang.org/x/sys v0.40.0 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
)
Loading
Loading