-
Notifications
You must be signed in to change notification settings - Fork 204
/
status.go
75 lines (62 loc) · 1.7 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package cmd
import (
"fmt"
"strconv"
"github.com/SpectoLabs/hoverfly/hoverctl/wrapper"
"github.com/spf13/cobra"
)
var statusCmd = &cobra.Command{
Use: "status",
Short: "Get the current status of Hoverfly",
Long: `
If Hoverfly is running, this command will show an overview
of the instance of Hoverfly. This includes reporting the
mode and middleware set.
`,
Run: func(cmd *cobra.Command, args []string) {
checkTargetAndExit(target)
middleware, err := wrapper.GetMiddleware(*target)
handleIfError(err)
hoverflyInfo, err := wrapper.GetHoverfly(*target)
handleIfError(err)
var proxyType string
if hoverflyInfo.IsWebServer {
proxyType = "reverse (webserver)"
} else {
proxyType = "forward"
}
var middlewareStatus string
if middleware.Binary == "" && middleware.Script == "" && middleware.Remote == "" {
middlewareStatus = "disabled"
} else {
middlewareStatus = "enabled"
}
var corsStatus string
if hoverflyInfo.CORSView.Enabled {
corsStatus = "enabled"
} else {
corsStatus = "disabled"
}
data := [][]string{
{"Hoverfly", "running"},
{"Admin port", strconv.Itoa(target.AdminPort)},
{"Proxy port", strconv.Itoa(target.ProxyPort)},
{"Proxy type", proxyType},
{"Mode", hoverflyInfo.Mode},
{"Middleware", middlewareStatus},
{"CORS", corsStatus},
}
drawTable(data, false)
if middlewareStatus == "enabled" {
fmt.Println("")
if middleware.Remote != "" {
fmt.Println("Hoverfly is using remote middleware:\n" + middleware.Remote)
} else {
fmt.Println("Hoverfly is using local middleware with the command " + middleware.Binary + " and the script:\n" + middleware.Script)
}
}
},
}
func init() {
RootCmd.AddCommand(statusCmd)
}