Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Add action.Action = func(ctx context.Context) error { l := logger.WithField("func", "Add") l.Infof("adding user %s", viper.GetString(config.Keys.UserEmail)) dbClient, err := bun.New(ctx) if err != nil { l.Errorf("db: %s", err.Error()) return err } defer func() { err := dbClient.Close(ctx) if err != nil { l.Errorf("closing db: %s", err.Error()) } }() newUser := models.User{ Email: viper.GetString(config.Keys.UserEmail), } err = newUser.SetPassword(viper.GetString(config.Keys.UserPassword)) if err != nil { l.Errorf("setting password: %s", err.Error()) return err } for _, group := range viper.GetStringSlice(config.Keys.UserGroups) { groupID := models.GroupName(group) if groupID == uuid.Nil { msg := fmt.Sprintf("unknown group: %s", group) l.Errorf(msg) return errors.New(msg) } groupMem := &models.GroupMembership{ GroupID: groupID, } l.Debugf("adding group: %s", group) newUser.Groups = append(newUser.Groups, groupMem) } err = dbClient.Create(ctx, &newUser) if err != nil { l.Errorf("db: %s", err.Error()) return err } for _, g := range newUser.Groups { g.UserID = newUser.ID } if len(newUser.Groups) > 0 { err = dbClient.Create(ctx, &newUser.Groups) if err != nil { l.Errorf("db: %s", err.Error()) return err } } l.Infof("added user %s", newUser.Email) return nil }
Add adds a user from the command line
View Source
var Show action.Action = func(ctx context.Context) error { l := logger.WithField("func", "Show") l.Infof("reading user %s", viper.GetString(config.Keys.UserEmail)) dbClient, err := bun.New(ctx) if err != nil { l.Errorf("db: %s", err.Error()) return err } defer func() { err := dbClient.Close(ctx) if err != nil { l.Errorf("closing db: %s", err.Error()) } }() user, err := dbClient.ReadUserByEmail(ctx, viper.GetString(config.Keys.UserEmail)) if err != nil { l.Errorf("readng : %s", err.Error()) return err } l.Infof("ID: %s", user.ID) l.Infof("Email: %s", user.Email) groupSlice := make([]string, len(user.Groups)) for i, g := range user.Groups { groupSlice[i] = models.GroupTitle(g.GroupID) } l.Infof("Groups: %s", strings.Join(groupSlice, ", ")) return nil }
Show displays info about a user
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.