mirror of
https://github.com/openziti/zrok.git
synced 2024-11-07 16:54:23 +01:00
better deactivation (#10)
This commit is contained in:
parent
4080e219a3
commit
d82b75f3b2
@ -53,14 +53,15 @@ func (self *Store) FindServicesForAccount(accountId int, tx *sqlx.Tx) ([]*Servic
|
||||
return svcs, nil
|
||||
}
|
||||
|
||||
func (self *Store) DeactivateService(id int, tx *sqlx.Tx) error {
|
||||
stmt, err := tx.Prepare("update services set active=false where id = ?")
|
||||
func (self *Store) UpdateService(svc *Service, tx *sqlx.Tx) error {
|
||||
sql := "update services set ziti_id = ?, endpoint = ?, active = ?, updated_at = strftime('%Y-%m-%d %H:%M:%f', 'now') where id = ?"
|
||||
stmt, err := tx.Prepare(sql)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error preparing services deactivate statement")
|
||||
return errors.Wrap(err, "error preparing services update statement")
|
||||
}
|
||||
_, err = stmt.Exec(id)
|
||||
_, err = stmt.Exec(svc.ZitiId, svc.Endpoint, svc.Active, svc.Id)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error executing services deactivate statement")
|
||||
return errors.Wrap(err, "error executing services update statement")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -59,19 +59,24 @@ func untunnelHandler(params tunnel.UntunnelParams, principal *rest_model_zrok.Pr
|
||||
logrus.Errorf("error finding services for account: %v", err)
|
||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
changed := false
|
||||
for _, svc := range svcs {
|
||||
if svc.ZitiId == svcId {
|
||||
if err := str.DeactivateService(svc.Id, tx); err != nil {
|
||||
svc.Active = false
|
||||
if err := str.UpdateService(svc, tx); err != nil {
|
||||
logrus.Errorf("error deactivating service '%v': %v", svcId, err)
|
||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
if err := tx.Commit(); err != nil {
|
||||
logrus.Errorf("error committing: %v", err)
|
||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
changed = true
|
||||
logrus.Infof("deactivated service '%v'", svcId)
|
||||
}
|
||||
}
|
||||
if changed {
|
||||
if err := tx.Commit(); err != nil {
|
||||
logrus.Errorf("error committing: %v", err)
|
||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||
}
|
||||
}
|
||||
|
||||
return tunnel.NewUntunnelOK()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user