portainer-devtool/go/main.go

68 lines
1.2 KiB
Go
Raw Normal View History

2022-08-21 15:05:29 +10:00
package main
import (
"log"
2022-09-21 15:42:47 +10:00
"ocl/portainer-devtool/configs"
"ocl/portainer-devtool/tasks"
2022-08-21 15:05:29 +10:00
"ocl/portainer-devtool/utils"
2022-09-22 11:58:21 +10:00
"strconv"
2022-08-21 15:05:29 +10:00
)
func main() {
2022-09-21 15:42:47 +10:00
config, err := configs.GetConfig()
if err != nil {
log.Fatalln(err)
}
2022-08-21 15:05:29 +10:00
config.Summarize()
2022-09-21 15:42:47 +10:00
// Init tasks
2022-09-21 15:42:47 +10:00
taskItems := []tasks.Tasker{
tasks.NewGenerateJwtTokenTask(config),
2022-12-25 22:53:51 +11:00
tasks.NewCurlLookupTask(),
2022-12-25 23:10:16 +11:00
tasks.NewCodeSecurityScanTask(),
2022-12-25 22:53:51 +11:00
tasks.NewExitTask(),
2022-09-21 15:42:47 +10:00
}
2022-09-21 15:42:47 +10:00
for {
2022-08-21 15:05:29 +10:00
2022-09-21 15:42:47 +10:00
printMainMenu := func() {
2022-12-25 22:53:51 +11:00
taskNames := []string{}
for _, task := range taskItems {
taskNames = append(taskNames, task.String())
}
2022-08-21 15:05:29 +10:00
2022-12-25 22:53:51 +11:00
utils.PrintMenu("Which repository of action do you want operate:", taskNames)
2022-08-21 15:05:29 +10:00
2022-09-21 15:42:47 +10:00
// utils.MenuPrint("Which repository or action do you want to operate:", `
// 1. Portainer EE Repository
// 2. Portainer CE Repository
// 3. Portainer Agent Repository
// 4. Others
// 5. Quit`)
}
2022-08-21 15:05:29 +10:00
2022-09-22 11:58:21 +10:00
option := utils.SelectMenuItem(printMainMenu)
2022-09-21 15:42:47 +10:00
2022-09-22 11:58:21 +10:00
index, err := strconv.Atoi(option)
if err != nil {
log.Printf("please type the option number\n")
continue
}
if index < 1 || index > len(taskItems) {
log.Printf("no such option %s, please select again\n", option)
continue
}
err = taskItems[index-1].Execute()
if err != nil {
log.Fatalln(err)
}
2022-08-21 15:05:29 +10:00
}
}