Skip to content

Commit

Permalink
refactor: skip install when the account is invalid.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitxeno committed Oct 25, 2024
1 parent 0e0689d commit 3dd890b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ require (
github.com/creasty/defaults v1.5.2
github.com/electricbubble/gidevice v0.6.2
github.com/fatih/color v1.9.0
github.com/ggwhite/go-masker/v2 v2.1.0
github.com/glebarez/sqlite v1.11.0
github.com/go-errors/errors v1.5.1
github.com/go-resty/resty/v2 v2.6.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMo
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/ggwhite/go-masker/v2 v2.1.0 h1:tmpVa2dWjgzdmlLDFBBWlJ/KkzdT3snd2QmFcR9qk+c=
github.com/ggwhite/go-masker/v2 v2.1.0/go.mod h1:Xky8hDSkBwV7pwCJvFsJaiFVwU9GCt0yIAx6yuAc6xY=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/glebarez/go-sqlite v1.21.2 h1:3a6LFC4sKahUunAmynQKLZceZCOzUthkRkEAl9gAXWo=
github.com/glebarez/go-sqlite v1.21.2/go.mod h1:sfxdZyhQjTM2Wry3gVYWaW072Ri1WMdWJi0k6+3382k=
Expand Down
8 changes: 6 additions & 2 deletions internal/manager/install_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,12 @@ func (t *InstallManager) OutputLog() string {
return t.outputStdout.String()
}

func (t *InstallManager) WriteLog(id uint) {
data := t.OutputLog()
func (t *InstallManager) WriteLog(msg string) {
t.outputStdout.Write([]byte(msg))

Check failure on line 143 in internal/manager/install_manager.go

View workflow job for this annotation

GitHub Actions / build (1.21.x)

Error return value of `t.outputStdout.Write` is not checked (errcheck)
}

func (t *InstallManager) SaveLog(id uint) {
data := t.OutputLog() + t.ErrorLog()

// Hide log password string
// data = strings.Replace(data, v.Password, "******", -1)
Expand Down
6 changes: 6 additions & 0 deletions internal/model/installed_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"time"

masker "github.com/ggwhite/go-masker/v2"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -37,3 +38,8 @@ func (t InstalledApp) MarshalJSON() ([]byte, error) {
Password: "",
})
}

func (t InstalledApp) MaskAccount() string {
m := masker.EmailMasker{}
return m.Marshal("*", t.Account)
}
2 changes: 1 addition & 1 deletion internal/service/websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func runInstallMessage(mgr *manager.WebsocketManager, installMgr *manager.Instal
mgr.WriteMessage(msg)
return
} else {
installMgr.WriteLog(app.ID)
installMgr.SaveLog(app.ID)
}
}

Expand Down
22 changes: 18 additions & 4 deletions internal/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Task struct {
InstallingApps sync.Map
InstallAppQueue chan model.InstalledApp
chExitQueue chan bool
InvalidAccounts map[string]bool
}

func new() *Task {
Expand Down Expand Up @@ -68,6 +69,7 @@ func (t *Task) Stop() {
}

func (t *Task) Run() {
t.InvalidAccounts = make(map[string]bool)
installedApps, err := service.GetEnableAppList()
if err != nil {
log.Err(err).Msg("Failed to get the installation list")
Expand Down Expand Up @@ -156,22 +158,34 @@ func (t *Task) tryInstallApp(v model.InstalledApp) {
}

func (t *Task) runInternal(v model.InstalledApp) error {
installMgr := manager.NewInstallManager()
defer func() {
installMgr.SaveLog(v.ID)
installMgr.Close()
}()

if v.Account == "" || v.Password == "" || v.UDID == "" {
log.Info("account or password or UDID is empty")
installMgr.WriteLog("account or password or UDID is empty")
return fmt.Errorf("%s", "account or password or UDID is empty")
}

installMgr := manager.NewInstallManager()
defer installMgr.Close()
if _, ok := t.InvalidAccounts[v.Account]; ok {
installMgr.WriteLog(fmt.Sprintf("The install account (%s) is invalid, skip install.", v.MaskAccount()))
return fmt.Errorf("The install account (%s) is invalid, skip install.", v.MaskAccount())
}

err := installMgr.TryStart(context.Background(), v.UDID, v.Account, v.Password, v.IpaPath)
installMgr.WriteLog(v.ID)
if err != nil {
log.Err(err).Msgf("Error executing installation script. %s", installMgr.ErrorLog())
installMgr.WriteLog(err.Error())
return err
}
if strings.Contains(installMgr.OutputLog(), "Installation Succeeded") {
return nil
} else {
if strings.Contains(installMgr.OutputLog(), "ERROR") && strings.Contains(installMgr.OutputLog(), "Can't log-in") {
t.InvalidAccounts[v.Account] = true
}
return fmt.Errorf("%s", installMgr.ErrorLog())
}
}
Expand Down

0 comments on commit 3dd890b

Please sign in to comment.