add password and apikey to user generation

master
Joshua Herring 4 weeks ago
parent de6402e289
commit 0faa0e3a5d

@ -7,6 +7,7 @@ import (
"log" "log"
"math/rand" "math/rand"
"os" "os"
"strings"
"github.com/brianvoe/gofakeit/v6" "github.com/brianvoe/gofakeit/v6"
) )
@ -485,11 +486,14 @@ var course_information = []Section{
} }
type User struct { type User struct {
UID string `json:"uid"` UID string `json:"uid"`
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
Status string `json:"status"` Status string `json:"status"`
ExamID string `json:"exam_id"` ExamID string `json:"exam_id"`
Username string `json:"username"`
APIKey string `json:"api_key"`
PasswordHash string `json:"password_hash"`
} }
type Section struct { type Section struct {
@ -526,11 +530,13 @@ func GenerateUserData(config Config) []User {
users := make([]User, config.NumberOfUsers) users := make([]User, config.NumberOfUsers)
for i := range users { for i := range users {
users[i] = User{ users[i] = User{
UID: uids[i], UID: uids[i],
FirstName: gofakeit.FirstName(), FirstName: gofakeit.FirstName(),
LastName: gofakeit.LastName(), LastName: gofakeit.LastName(),
Status: weightedStatuses[rand.Intn(len(weightedStatuses))], Status: weightedStatuses[rand.Intn(len(weightedStatuses))],
ExamID: examIDs[i], ExamID: examIDs[i],
APIKey: strings.ReplaceAll(gofakeit.UUID(), "-", ""),
PasswordHash: gofakeit.Password(true, true, true, true, false, 16),
} }
} }
@ -547,11 +553,11 @@ func SaveGeneratedUsers(users []User) {
defer f.Close() defer f.Close()
w := csv.NewWriter(f) w := csv.NewWriter(f)
if err := w.Write([]string{"uid", "first_name", "last_name", "status", "exam_id"}); err != nil { if err := w.Write([]string{"uid", "first_name", "last_name", "status", "exam_id", "api_key", "password_hash"}); err != nil {
log.Fatalf("failed to write csv header: %v", err) log.Fatalf("failed to write csv header: %v", err)
} }
for _, u := range users { for _, u := range users {
if err := w.Write([]string{u.UID, u.FirstName, u.LastName, u.Status, u.ExamID}); err != nil { if err := w.Write([]string{u.UID, u.FirstName, u.LastName, u.Status, u.ExamID, u.APIKey, u.PasswordHash}); err != nil {
log.Fatalf("failed to write csv row: %v", err) log.Fatalf("failed to write csv row: %v", err)
} }
} }

@ -0,0 +1 @@
Modify the GenerateUserData function to include the PasswordHash and APIKey fields. APIKey should be a v4 uuid with no dashes. Password should use gofaker's password generator. Modify SaveGeneratedUsers to include these columns in the csv file.

@ -12,6 +12,8 @@
"MLS": 0, "MLS": 0,
"SPEC": 5, "SPEC": 5,
"MNR": 0, "MNR": 0,
"CERT": 5 "CERT": 5,
"Admin": 0,
"Instructor": 0
} }
} }

Loading…
Cancel
Save