From 215ee946dd075e5fa3fcca560c1549e46cbc0f19 Mon Sep 17 00:00:00 2001 From: Marc Brugger Date: Fri, 22 Dec 2023 21:03:46 +0100 Subject: [PATCH] add protection flag to api status (#260) --- pkg/sync/http.go | 9 +++++---- pkg/sync/sync.go | 10 +++++++--- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/pkg/sync/http.go b/pkg/sync/http.go index 0ce8158..2df421d 100644 --- a/pkg/sync/http.go +++ b/pkg/sync/http.go @@ -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"` } diff --git a/pkg/sync/sync.go b/pkg/sync/sync.go index 832edcd..d2fe508 100644 --- a/pkg/sync/sync.go +++ b/pkg/sync/sync.go @@ -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() {