zrok/controller/limits/accountWarningAction.go

31 lines
958 B
Go
Raw Normal View History

2023-03-27 17:53:18 +02:00
package limits
import (
"github.com/jmoiron/sqlx"
2023-03-27 17:53:18 +02:00
"github.com/openziti/edge/rest_management_api_client"
"github.com/openziti/zrok/controller/emailUi"
2023-03-27 17:53:18 +02:00
"github.com/openziti/zrok/controller/store"
"github.com/pkg/errors"
2023-03-27 17:53:18 +02:00
"github.com/sirupsen/logrus"
)
type accountWarningAction struct {
str *store.Store
edge *rest_management_api_client.ZitiEdgeManagement
cfg *emailUi.Config
2023-03-27 17:53:18 +02:00
}
func newAccountWarningAction(cfg *emailUi.Config, str *store.Store, edge *rest_management_api_client.ZitiEdgeManagement) *accountWarningAction {
return &accountWarningAction{str, edge, cfg}
2023-03-27 17:53:18 +02:00
}
func (a *accountWarningAction) HandleAccount(acct *store.Account, rxBytes, txBytes int64, limit *BandwidthPerPeriod, trx *sqlx.Tx) error {
2023-03-27 17:53:18 +02:00
logrus.Infof("warning '%v'", acct.Email)
if err := sendLimitWarningEmail(a.cfg, acct.Email, limit, rxBytes, txBytes); err != nil {
return errors.Wrapf(err, "error sending limit warning email to '%v'", acct.Email)
}
2023-03-27 17:53:18 +02:00
return nil
}