Add /dbg certs command

This commit is contained in:
Alex Kursell 2019-02-25 11:29:52 -05:00
parent 50ca26a89a
commit c96eae3015
3 changed files with 101 additions and 7 deletions

View file

@ -28,6 +28,7 @@ import (
const (
backendsPath = "/configuration/backends"
generalPath = "/configuration/general"
certsPath = "/configuration/certs"
)
func main() {
@ -70,6 +71,24 @@ func main() {
}
backendsCmd.AddCommand(backendsGetCmd)
certCmd := &cobra.Command{
Use: "certs",
Short: "Inspect dynamic SSL certificates",
}
certGetCmd := &cobra.Command{
Use: "get [hostname]",
Short: "Get the dynamically-loaded certificate information for the given hostname",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
certGet(args[0])
return nil
},
}
certCmd.AddCommand(certGetCmd)
rootCmd.AddCommand(certCmd)
generalCmd := &cobra.Command{
Use: "general",
Short: "Output the general dynamic lua state",
@ -102,7 +121,7 @@ func backendsAll() {
return
}
if statusCode != 200 {
fmt.Printf("Nginx returned code %v", statusCode)
fmt.Printf("Nginx returned code %v\n", statusCode)
return
}
@ -123,7 +142,7 @@ func backendsList() {
return
}
if statusCode != 200 {
fmt.Printf("Nginx returned code %v", statusCode)
fmt.Printf("Nginx returned code %v\n", statusCode)
return
}
@ -148,7 +167,7 @@ func backendsGet(name string) {
return
}
if statusCode != 200 {
fmt.Printf("Nginx returned code %v", statusCode)
fmt.Printf("Nginx returned code %v\n", statusCode)
return
}
@ -171,6 +190,25 @@ func backendsGet(name string) {
fmt.Println("A backend of this name was not found.")
}
func certGet(host string) {
statusCode, body, requestErr := nginx.NewGetStatusRequest(certsPath + "?hostname=" + host)
if requestErr != nil {
fmt.Println(requestErr)
return
}
if statusCode == 200 {
fmt.Print(string(body))
return
} else if statusCode != 404 {
fmt.Printf("Nginx returned code %v\n", statusCode)
fmt.Println(string(body))
return
}
fmt.Printf("No cert found for host %v\n", host)
}
func general() {
statusCode, body, requestErr := nginx.NewGetStatusRequest(generalPath)
if requestErr != nil {
@ -178,7 +216,7 @@ func general() {
return
}
if statusCode != 200 {
fmt.Printf("Nginx returned code %v", statusCode)
fmt.Printf("Nginx returned code %v\n", statusCode)
return
}