diff --git a/build/dependencies.yaml b/build/dependencies.yaml index 72c97c5e65c..e052be2d851 100644 --- a/build/dependencies.yaml +++ b/build/dependencies.yaml @@ -1,7 +1,7 @@ dependencies: # agnhost: bump this one first - name: "agnhost" - version: "2.24" + version: "2.25" refPaths: - path: test/images/agnhost/VERSION match: \d.\d diff --git a/test/images/agnhost/VERSION b/test/images/agnhost/VERSION index fd6915cc46b..8bd2249aca9 100644 --- a/test/images/agnhost/VERSION +++ b/test/images/agnhost/VERSION @@ -1 +1 @@ -2.24 +2.25 diff --git a/test/images/agnhost/agnhost.go b/test/images/agnhost/agnhost.go index 3eacfebe11d..0e9bd6986c2 100644 --- a/test/images/agnhost/agnhost.go +++ b/test/images/agnhost/agnhost.go @@ -51,7 +51,7 @@ import ( func main() { rootCmd := &cobra.Command{ Use: "app", - Version: "2.24", + Version: "2.25", } rootCmd.AddCommand(auditproxy.CmdAuditProxy) diff --git a/test/images/agnhost/porter/porter.go b/test/images/agnhost/porter/porter.go index f621e727f7e..8b9367211e0 100644 --- a/test/images/agnhost/porter/porter.go +++ b/test/images/agnhost/porter/porter.go @@ -23,6 +23,7 @@ limitations under the License. package porter import ( + "encoding/json" "fmt" "log" "net/http" @@ -55,6 +56,18 @@ To use a different cert/key, mount them into the pod and set the "CERT_FILE" and Run: main, } +// JSONResponse enables --json-response flag +var JSONResponse bool + +type jsonResponse struct { + Method string + Body string +} + +func init() { + CmdPorter.Flags().BoolVar(&JSONResponse, "json-response", false, "Responds to requests with a json response that includes the default value with the http.Request Method") +} + func main(cmd *cobra.Command, args []string) { for _, vk := range os.Environ() { // Put everything before the first = sign in parts[0], and @@ -81,10 +94,23 @@ func main(cmd *cobra.Command, args []string) { } func servePort(port, value string) { + s := &http.Server{ Addr: "0.0.0.0:" + port, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, value) + body := value + if JSONResponse { + j, err := json.Marshal(&jsonResponse{ + Method: r.Method, + Body: value}) + if err != nil { + http.Error(w, fmt.Sprintf("Internal Server Error: %v", err), 500) + return + } + w.Header().Set("Content-Type", "application/json") + body = string(j) + } + fmt.Fprint(w, body) }), } log.Printf("server on port %q failed: %v", port, s.ListenAndServe()) @@ -94,7 +120,19 @@ func serveTLSPort(port, value string) { s := &http.Server{ Addr: "0.0.0.0:" + port, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, value) + body := value + if JSONResponse { + j, err := json.Marshal(&jsonResponse{ + Method: r.Method, + Body: value}) + if err != nil { + http.Error(w, fmt.Sprintf("Internal Server Error: %v", err), 500) + return + } + w.Header().Set("Content-Type", "application/json") + body = string(j) + } + fmt.Fprint(w, body) }), } certFile := os.Getenv("CERT_FILE")