Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
lsowen committed Sep 15, 2024
1 parent 5cb74be commit d1332ad
Show file tree
Hide file tree
Showing 8 changed files with 628 additions and 24 deletions.
57 changes: 57 additions & 0 deletions cmd/hooverdam/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cmd

import (
"fmt"
"os"
"strings"
"sync"

"github.com/lsowen/hoover-dam/pkg/config"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "hoover-dam",
Short: "hoover-dam is an open source authorization server for lakefs",
}

// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() {
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

var initOnce sync.Once

func newConfig() (*config.Config, error) {
cfg, err := config.NewConfig()
if err != nil {
return nil, err
}

return cfg, nil
}

func loadConfig() *config.Config {
initOnce.Do(initConfig)
cfg, err := newConfig()
if err != nil {
fmt.Println("Failed to load config file", err)
os.Exit(1)
}
return cfg
}

func initConfig() {

viper.SetEnvPrefix("LAKEFS")
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_")) // support nested config
// read in environment variables
viper.AutomaticEnv()

}
30 changes: 30 additions & 0 deletions cmd/hooverdam/cmd/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package cmd

import (
"fmt"
"net/http"
"os"

"github.com/lsowen/hoover-dam/pkg/api"
"github.com/spf13/cobra"
)

var runCmd = &cobra.Command{
Use: "run",
Short: "Run hoover-dam",
Run: func(cmd *cobra.Command, args []string) {
cfg := loadConfig()

r, err := api.Serve(cmd.Context(), *cfg)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

http.ListenAndServe(":8080", r)
},
}

func init() {
rootCmd.AddCommand(runCmd)
}
36 changes: 21 additions & 15 deletions cmd/hooverdam/main.go
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
package main

import (
"context"
"fmt"
"net/http"
"os"
// import (
// "context"
// "fmt"
// "net/http"
// "os"

"github.com/lsowen/hoover-dam/pkg/api"
)
// "github.com/lsowen/hoover-dam/pkg/api"
// )

func main() {
ctx := context.Background()
r, err := api.Serve(ctx)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
// func main() {
// ctx := context.Background()
// r, err := api.Serve(ctx)
// if err != nil {
// fmt.Println(err)
// os.Exit(1)
// }

// http.ListenAndServe(":8080", r)
// }

http.ListenAndServe(":8080", r)
import "github.com/lsowen/hoover-dam/cmd/hooverdam/cmd"

func main() {
cmd.Execute()
}
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ require (
github.com/go-chi/chi v1.5.5
github.com/go-chi/chi/v5 v5.1.0
github.com/go-chi/render v1.0.3
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.17.0
github.com/treeverse/lakefs v1.33.0
gorm.io/driver/postgres v1.5.9
gorm.io/gorm v1.25.12
Expand All @@ -26,6 +28,7 @@ require (
github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/flosch/pongo2/v4 v4.0.2 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
Expand All @@ -37,6 +40,8 @@ require (
github.com/gomarkdown/markdown v0.0.0-20230716120725-531d2d74bc12 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/iris-contrib/schema v0.0.6 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
Expand All @@ -57,18 +62,27 @@ require (
github.com/labstack/echo/v4 v4.12.0 // indirect
github.com/labstack/gommon v0.4.2 // indirect
github.com/leodido/go-urn v1.2.4 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailgun/raymond/v2 v2.0.48 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/microcosm-cc/bluemonday v1.0.25 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
github.com/rogpeppe/go-internal v1.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/schollz/closestmatch v2.1.0+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tdewolff/minify/v2 v2.12.9 // indirect
github.com/tdewolff/parse/v2 v2.6.8 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
Expand All @@ -78,8 +92,10 @@ require (
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/yosssi/ace v0.0.5 // indirect
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/exp v0.0.0-20231127185646-65229373498e // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.20.0 // indirect
Expand Down
Loading

0 comments on commit d1332ad

Please # to comment.