@@ -10,10 +10,20 @@ import (
10
10
11
11
type unitStatusHandler struct {
12
12
conn * dbus.Conn
13
+ cfg * Config
13
14
}
14
15
15
16
func (h unitStatusHandler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
16
17
name := r .URL .Path [len ("/unit/status/" ):]
18
+
19
+ // check if unit in config
20
+ unitCfg , err := h .cfg .getUnit (name )
21
+ if err != nil {
22
+ log .Printf ("[ERROR] %s" , err )
23
+ w .WriteHeader (http .StatusForbidden )
24
+ return
25
+ }
26
+
17
27
log .Printf ("[INFO] get unit status %v" , name )
18
28
19
29
units , err := h .conn .ListUnits ()
@@ -25,11 +35,12 @@ func (h unitStatusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
25
35
26
36
for _ , unit := range units {
27
37
if unit .Name == name {
28
- fmt .Fprintf (w , "Name: %+v\n " , unit .Name )
29
- fmt .Fprintf (w , "Description: %+v\n " , unit .Description )
30
- fmt .Fprintf (w , "LoadState: %+v\n " , unit .LoadState )
31
- fmt .Fprintf (w , "ActiveState: %+v\n " , unit .ActiveState )
32
- fmt .Fprintf (w , "SubState: %+v\n " , unit .ActiveState )
38
+ fmt .Fprintf (w , "Name %v\n " , unit .Name )
39
+ fmt .Fprintf (w , "Description %v\n " , unit .Description )
40
+ fmt .Fprintf (w , "LoadState %v\n " , unit .LoadState )
41
+ fmt .Fprintf (w , "ActiveState %v\n " , unit .ActiveState )
42
+ fmt .Fprintf (w , "SubState %v\n " , unit .ActiveState )
43
+ fmt .Fprintf (w , "BlockedBy %v\n " , unitCfg .BlockedBy )
33
44
return
34
45
}
35
46
}
0 commit comments