Skip to content

Commit

Permalink
feat(web): implement git auth and lfs
Browse files Browse the repository at this point in the history
Generate jwt tokens
Implement git-lfs-authenticate to generate tokens through ssh
Authenticate user using HTTP

fix: git lfs endpoint auth

feat: git lfs locks

Implement git lfs locks endpoints

fix: tests

fix: access tokens migration

add expires_at

fix: lint errors

fix: cleanup

Revert "fix: cleanup"

This reverts commit 728173f.

fix(db): don't drop tables
  • Loading branch information
aymanbagabas committed Aug 4, 2023
1 parent 8e68dba commit f69f064
Show file tree
Hide file tree
Showing 62 changed files with 2,333 additions and 368 deletions.
33 changes: 27 additions & 6 deletions cmd/soft/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,51 @@ import (
"bufio"
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
"os/exec"
"path/filepath"
"strings"

"github.com/charmbracelet/log"
"github.com/charmbracelet/soft-serve/server/backend"
"github.com/charmbracelet/soft-serve/server/config"
"github.com/charmbracelet/soft-serve/server/hooks"
"github.com/spf13/cobra"
)

var (
// ErrInternalServerError indicates that an internal server error occurred.
ErrInternalServerError = errors.New("internal server error")

// Deprecated: this flag is ignored.
configPath string

hookCmd = &cobra.Command{
Use: "hook",
Short: "Run git server hooks",
Long: "Handles Soft Serve git server hooks.",
Hidden: true,
PersistentPreRunE: initBackendContext,
PersistentPostRunE: closeDBContext,
Use: "hook",
Short: "Run git server hooks",
Long: "Handles Soft Serve git server hooks.",
Hidden: true,
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
logger := log.FromContext(cmd.Context())
if err := initBackendContext(cmd, args); err != nil {
logger.Error("failed to initialize backend context", "err", err)
return ErrInternalServerError
}

return nil
},
PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
logger := log.FromContext(cmd.Context())
if err := closeDBContext(cmd, args); err != nil {
logger.Error("failed to close backend", "err", err)
return ErrInternalServerError
}

return nil
},
}

// Git hooks read the config from the environment, based on
Expand Down
7 changes: 7 additions & 0 deletions cmd/soft/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"context"
"errors"
"fmt"
"io/fs"
"os"
"runtime/debug"
"strings"
Expand Down Expand Up @@ -146,6 +148,11 @@ func newDefaultLogger(cfg *config.Config) (*log.Logger, *os.File, error) {
func initBackendContext(cmd *cobra.Command, _ []string) error {
ctx := cmd.Context()
cfg := config.FromContext(ctx)
if _, err := os.Stat(cfg.DataPath); errors.Is(err, fs.ErrNotExist) {
if err := os.MkdirAll(cfg.DataPath, os.ModePerm); err != nil {
return fmt.Errorf("create data directory: %w", err)
}
}
dbx, err := db.Open(ctx, cfg.DB.Driver, cfg.DB.DataSource)
if err != nil {
return fmt.Errorf("open database: %w", err)
Expand Down
18 changes: 13 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ require (

require (
github.com/caarlos0/env/v8 v8.0.0
github.com/charmbracelet/git-lfs-transfer v0.1.1-0.20230721203144-64d90e7a36a1
github.com/charmbracelet/git-lfs-transfer v0.1.1-0.20230725143853-5dd0632f9245
github.com/charmbracelet/keygen v0.4.3
github.com/charmbracelet/log v0.2.3-0.20230713155356-557335e40e35
github.com/charmbracelet/log v0.2.3-0.20230725142510-280c4e3f1ef2
github.com/charmbracelet/ssh v0.0.0-20230720143903-5bdd92839155
github.com/go-jose/go-jose/v3 v3.0.0
github.com/gobwas/glob v0.2.3
github.com/gogs/git-module v1.8.2
github.com/golang-jwt/jwt/v5 v5.0.0
github.com/hashicorp/golang-lru/v2 v2.0.4
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.9
Expand All @@ -47,21 +49,26 @@ require (
require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be // indirect
github.com/atotto/clipboard v0.1.4 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/caarlos0/sshmarshal v0.1.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 // indirect
github.com/dlclark/regexp2 v1.4.0 // indirect
github.com/git-lfs/git-lfs/v3 v3.3.0 // indirect
github.com/git-lfs/gitobj/v2 v2.1.1 // indirect
github.com/git-lfs/pktline v0.0.0-20230103162542-ca444d533ef1 // indirect
github.com/git-lfs/wildmatch/v2 v2.0.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/leonelquinteros/gotext v1.5.2 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
github.com/mattn/go-localereader v0.0.1 // indirect
Expand All @@ -74,21 +81,22 @@ require (
github.com/muesli/mango v0.1.0 // indirect
github.com/muesli/mango-pflag v0.1.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/sahilm/fuzzy v0.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/yuin/goldmark v1.5.2 // indirect
github.com/yuin/goldmark-emoji v1.0.1 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/mod v0.10.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/tools v0.6.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
Expand Down
Loading

0 comments on commit f69f064

Please sign in to comment.