Skip to content
Snippets Groups Projects
Commit f4f91b07 authored by Josh Brooks's avatar Josh Brooks
Browse files

Improve documentation

parent f524b8da
No related branches found
No related tags found
4 merge requests!50Revert "update deps",!48Release,!42Add username field to users table for raw username,!41Xx 3692/banned users
...@@ -45,6 +45,7 @@ func InitParams(vip *viper.Viper) params.General { ...@@ -45,6 +45,7 @@ func InitParams(vip *viper.Viper) params.General {
jww.FATAL.Fatalf("Failed to read session path: %+v", err) jww.FATAL.Fatalf("Failed to read session path: %+v", err)
} }
// Load banned user CSV
bannedUserList, err := utils.ReadFile(viper.GetString("bannedUserList")) bannedUserList, err := utils.ReadFile(viper.GetString("bannedUserList"))
if err != nil { if err != nil {
jww.WARN.Printf("Failed to read banned user list: %v", err) jww.WARN.Printf("Failed to read banned user list: %v", err)
......
...@@ -44,6 +44,7 @@ var rootCmd = &cobra.Command{ ...@@ -44,6 +44,7 @@ var rootCmd = &cobra.Command{
initLog() initLog()
p := InitParams(viper.GetViper()) p := InitParams(viper.GetViper())
// Process CSV into a map
bannedUsers := make(map[string]struct{}) bannedUsers := make(map[string]struct{})
if p.BannedUserList != "" { if p.BannedUserList != "" {
bannedUserList := strings.Split(p.BannedUserList, ",") bannedUserList := strings.Split(p.BannedUserList, ",")
...@@ -52,6 +53,7 @@ var rootCmd = &cobra.Command{ ...@@ -52,6 +53,7 @@ var rootCmd = &cobra.Command{
} }
} }
// Initialize storage
storage, err := storage.NewStorage(p.DbUsername, p.DbPassword, p.DbName, p.DbAddress, p.DbPort, bannedUsers) storage, err := storage.NewStorage(p.DbUsername, p.DbPassword, p.DbName, p.DbAddress, p.DbPort, bannedUsers)
if err != nil { if err != nil {
jww.FATAL.Panicf("Failed to initialize storage interface: %+v", err) jww.FATAL.Panicf("Failed to initialize storage interface: %+v", err)
......
...@@ -32,11 +32,14 @@ func NewStorage(username, password, dbName, address, port string, bannedUserList ...@@ -32,11 +32,14 @@ func NewStorage(username, password, dbName, address, port string, bannedUserList
return storage, err return storage, err
} }
// IsBanned checks if the username is in Storage's bannedUserList.
func (s *Storage) IsBanned(username string) bool { func (s *Storage) IsBanned(username string) bool {
_, exists := s.bannedUserList[username] _, exists := s.bannedUserList[username]
return exists return exists
} }
// SetBanned is a testing only helper function which sets a username
// in Storage's bannedUserList.
func (s *Storage) SetBanned(username string, t *testing.T) { func (s *Storage) SetBanned(username string, t *testing.T) {
if t == nil { if t == nil {
jww.FATAL.Panic("Cannot use this outside of testing") jww.FATAL.Panic("Cannot use this outside of testing")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment