add FLUSH_OTP_KEY env for flushing otp key

This commit is contained in:
c9s 2022-04-17 00:35:16 +08:00
parent 63f525970f
commit ad373b95a7

View File

@ -597,7 +597,6 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types
position.StrategyInstanceID = profit.StrategyInstanceID
}
if profit != nil {
if err := environ.PositionService.Insert(position, trade, profit.Profit); err != nil {
log.WithError(err).Errorf("can not insert position record")
@ -611,7 +610,6 @@ func (environ *Environment) RecordPosition(position *types.Position, trade types
}
}
// if:
// 1) we are not using sync
// 2) and not sync-ing trades from the user data stream
@ -739,6 +737,14 @@ func (environ *Environment) setupInteraction(persistence service.PersistenceServ
var key *otp.Key
var keyURL string
var authStore = environ.getAuthStore(persistence)
if v, ok := util.GetEnvVarBool("FLUSH_OTP_KEY"); v && ok {
log.Warnf("flushing otp key...")
if err := authStore.Reset(); err != nil {
return err
}
}
if err := authStore.Load(&keyURL); err != nil {
log.Warnf("telegram session not found, generating new one-time password key for new telegram session...")