229a53fa0a
changes authentication to no longer use a refresh token & access token for accessing protected endpoints. Instead only an auth token is used. Before the login flow was: Login -> get refresh (stored as HttpOnly cookie) + access token (stored in memory) -> protected endpoint request (attach access token as Authorization header) -> access token expires in 15 minutes, so use refresh token to obtain new one when that happens now it looks like this: Login -> get auth token (stored as HttpOnly cookie) -> make protected endpont request (token sent) the reasoning for using the refresh + access token was to reduce DB calls, but in the end I don't think its worth the hassle.
92 lines
2.4 KiB
Go
92 lines
2.4 KiB
Go
package commands
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/jordanknott/taskcafe/internal/utils"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
const mainDescription = `Taskcafé is an open soure project management
|
|
system written in Golang & React.`
|
|
|
|
func VersionTemplate() string {
|
|
info := utils.Version()
|
|
return fmt.Sprintf(`Version: %s
|
|
Commit: %s
|
|
Built: %s`, info.Version, info.CommitHash, info.BuildDate+"\n")
|
|
}
|
|
|
|
var cfgFile string
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "taskcafe",
|
|
Long: mainDescription,
|
|
Version: VersionTemplate(),
|
|
}
|
|
|
|
var migration http.FileSystem
|
|
|
|
func init() {
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file path")
|
|
migration = http.Dir("./migrations")
|
|
}
|
|
|
|
func initConfig() {
|
|
if cfgFile != "" {
|
|
// Use config file from the flag.
|
|
viper.SetConfigFile(cfgFile)
|
|
} else {
|
|
// Search config in home directory with name ".cobra" (without extension).
|
|
viper.AddConfigPath("./conf")
|
|
viper.AddConfigPath(".")
|
|
viper.AddConfigPath("/etc/taskcafe")
|
|
viper.SetConfigName("taskcafe")
|
|
}
|
|
|
|
viper.SetEnvPrefix("TASKCAFE")
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
viper.AutomaticEnv()
|
|
|
|
err := viper.ReadInConfig()
|
|
if err == nil {
|
|
return
|
|
}
|
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
|
panic(err)
|
|
}
|
|
|
|
viper.SetDefault("server.hostname", "0.0.0.0:3333")
|
|
viper.SetDefault("database.host", "127.0.0.1")
|
|
viper.SetDefault("database.name", "taskcafe")
|
|
viper.SetDefault("database.user", "taskcafe")
|
|
viper.SetDefault("database.password", "taskcafe_test")
|
|
|
|
viper.SetDefault("queue.broker", "amqp://guest:guest@localhost:5672/")
|
|
viper.SetDefault("queue.store", "memcache://localhost:11211")
|
|
|
|
}
|
|
|
|
// Execute the root cobra command
|
|
func Execute() {
|
|
viper.SetDefault("server.hostname", "0.0.0.0:3333")
|
|
viper.SetDefault("database.host", "127.0.0.1")
|
|
viper.SetDefault("database.name", "taskcafe")
|
|
viper.SetDefault("database.user", "taskcafe")
|
|
viper.SetDefault("database.password", "taskcafe_test")
|
|
viper.SetDefault("database.port", "5432")
|
|
viper.SetDefault("security.token_expiration", "15m")
|
|
|
|
viper.SetDefault("queue.broker", "amqp://guest:guest@localhost:5672/")
|
|
viper.SetDefault("queue.store", "memcache://localhost:11211")
|
|
|
|
rootCmd.SetVersionTemplate(VersionTemplate())
|
|
rootCmd.AddCommand(newWebCmd(), newMigrateCmd(), newWorkerCmd(), newResetPasswordCmd(), newSeedCmd())
|
|
rootCmd.Execute()
|
|
}
|