add protection flag to api status (#260)

This commit is contained in:
Marc Brugger 2023-12-22 21:03:46 +01:00 committed by GitHub
parent cc13b9318d
commit 215ee946dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -128,8 +128,9 @@ type syncStatus struct {
}
type replicaStatus struct {
Host string `json:"host"`
URL string `json:"url"`
Status string `json:"status"`
Error string `json:"error"`
Host string `json:"host"`
URL string `json:"url"`
Status string `json:"status"`
Error string `json:"error,omitempty"`
ProtectionEnabled *bool `json:"protection_enabled"`
}

View file

@ -119,7 +119,7 @@ func (w *worker) getStatus(inst types.AdGuardInstance) replicaStatus {
return replicaStatus{Host: oc.Host(), URL: inst.URL, Error: err.Error(), Status: "danger"}
}
sl := l.With("from", oc.Host())
_, err = oc.Status()
st, err := oc.Status()
if err != nil {
if errors.Is(err, client.ErrSetupNeeded) {
return replicaStatus{Host: oc.Host(), URL: inst.URL, Error: err.Error(), Status: "warning"}
@ -127,8 +127,12 @@ func (w *worker) getStatus(inst types.AdGuardInstance) replicaStatus {
sl.With("error", err).Error("Error getting origin status")
return replicaStatus{Host: oc.Host(), URL: inst.URL, Error: err.Error(), Status: "danger"}
}
st := replicaStatus{Host: oc.Host(), URL: inst.URL, Status: "success"}
return st
return replicaStatus{
Host: oc.Host(),
URL: inst.URL,
Status: "success",
ProtectionEnabled: utils.Ptr(st.ProtectionEnabled),
}
}
func (w *worker) sync() {