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
|
return svcs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *Store) DeactivateService(id int, tx *sqlx.Tx) error {
|
func (self *Store) UpdateService(svc *Service, tx *sqlx.Tx) error {
|
||||||
stmt, err := tx.Prepare("update services set active=false where id = ?")
|
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 {
|
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 {
|
if err != nil {
|
||||||
return errors.Wrap(err, "error executing services deactivate statement")
|
return errors.Wrap(err, "error executing services update statement")
|
||||||
}
|
}
|
||||||
return nil
|
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)
|
logrus.Errorf("error finding services for account: %v", err)
|
||||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
}
|
}
|
||||||
|
changed := false
|
||||||
for _, svc := range svcs {
|
for _, svc := range svcs {
|
||||||
if svc.ZitiId == svcId {
|
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)
|
logrus.Errorf("error deactivating service '%v': %v", svcId, err)
|
||||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
||||||
}
|
}
|
||||||
if err := tx.Commit(); err != nil {
|
changed = true
|
||||||
logrus.Errorf("error committing: %v", err)
|
|
||||||
return tunnel.NewUntunnelInternalServerError().WithPayload(rest_model_zrok.ErrorMessage(err.Error()))
|
|
||||||
}
|
|
||||||
logrus.Infof("deactivated service '%v'", svcId)
|
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()
|
return tunnel.NewUntunnelOK()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user