/
delete_temp_users.go
48 lines (39 loc) · 1.06 KB
/
delete_temp_users.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cmd
import (
"fmt"
"os"
_ "github.com/go-sql-driver/mysql" // use to force database/sql to use mysql
"github.com/spf13/cobra"
"github.com/France-ioi/AlgoreaBackend/app"
"github.com/France-ioi/AlgoreaBackend/app/appenv"
"github.com/France-ioi/AlgoreaBackend/app/database"
)
// nolint:gosec
func init() { //nolint:gochecknoinits,gocyclo
deleteTempUsersCmd := &cobra.Command{
Use: "delete-temp-users [environment]",
Short: "delete all temporary users with expired sessions",
Run: func(cmd *cobra.Command, args []string) {
// if arg given, replace the env
if len(args) > 0 {
appenv.SetEnv(args[0])
}
appenv.SetDefaultEnv("dev")
var application *app.Application
var err error
application, err = app.New()
if err != nil {
fmt.Println("Fatal error: ", err)
os.Exit(1)
}
err = database.NewDataStore(application.Database).Users().DeleteTemporaryWithTraps()
if err != nil {
fmt.Println("Fatal error: ", err)
os.Exit(1)
}
// Success
fmt.Println("DONE")
},
}
rootCmd.AddCommand(deleteTempUsersCmd)
}