Repository: kubernetes/kubernetes
File: test/images/agnhost/netexec/netexec.go (Go)

Code before:
	"net/http"
	"net/url"
	"os"
	"os/exec"
	"os/signal"
	"strconv"
	"strings"
	"sync/atomic"
	"syscall"
	"time"

	"github.com/ishidawataru/sctp"
	"github.com/spf13/cobra"

	utilnet "k8s.io/apimachinery/pkg/util/net"
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
	"k8s.io/apimachinery/pkg/util/sets"
	netutils "k8s.io/utils/net"
)

var (
	httpPort           = 8080
	udpPort            = 8081
	sctpPort           = -1
	shellPath          = "/bin/sh"
	serverReady        atomicBool
	certFile           = ""
	privKeyFile        = ""
	httpOverride       = ""
	udpListenAddresses = ""
	delayShutdown      = 0
)

const bindToAny = ""

// CmdNetexec is used by agnhost Cobra.
var CmdNetexec = &cobra.Command{
	Use:   "netexec",
	Short: "Creates HTTP(S), UDP, and (optionally) SCTP servers with various endpoints",
	Long: `Starts a HTTP(S) server on given port with the following endpoints:

- /: Returns the request's timestamp.
- /clientip: Returns the request's IP address.
- /serverport: Returns the server port.
- /header: Returns the request's header value corresponding to the key provided or the entire 
  header marshalled as json, if no form value (key) is provided.
  ("/header?key=X-Forwarded-For" or /header)
- /dial: Creates a given number of requests to the given host and port using the given protocol,
  and returns a JSON with the fields "responses" (successful request responses) and "errors" (
  failed request responses). Returns "200 OK" status code if the last request succeeded,
  "417 Expectation Failed" if it did not, or "400 Bad Request" if any of the endpoint's parameters

Review comment (suggestion):
I still think it would be better to use `atomic.Bool` and drop the custom `atomicBool`.


Code after:
	"net/http"
	"net/url"
	"os"
	"os/exec"
	"os/signal"
	"strconv"
	"strings"
	"sync/atomic"
	"syscall"
	"time"

	"github.com/ishidawataru/sctp"
	"github.com/spf13/cobra"

	utilnet "k8s.io/apimachinery/pkg/util/net"
	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
	"k8s.io/apimachinery/pkg/util/sets"
	netutils "k8s.io/utils/net"
)

var (
	httpPort           = 8080
	udpPort            = 8081
	sctpPort           = -1
	shellPath          = "/bin/sh"
	serverReady        atomic.Bool
	certFile           = ""
	privKeyFile        = ""
	httpOverride       = ""
	udpListenAddresses = ""
	delayShutdown      = 0
)

const bindToAny = ""

// CmdNetexec is used by agnhost Cobra.
var CmdNetexec = &cobra.Command{
	Use:   "netexec",
	Short: "Creates HTTP(S), UDP, and (optionally) SCTP servers with various endpoints",
	Long: `Starts a HTTP(S) server on given port with the following endpoints:

- /: Returns the request's timestamp.
- /clientip: Returns the request's IP address.
- /serverport: Returns the server port.
- /header: Returns the request's header value corresponding to the key provided or the entire 
  header marshalled as json, if no form value (key) is provided.
  ("/header?key=X-Forwarded-For" or /header)
- /dial: Creates a given number of requests to the given host and port using the given protocol,
  and returns a JSON with the fields "responses" (successful request responses) and "errors" (
  failed request responses). Returns "200 OK" status code if the last request succeeded,
  "417 Expectation Failed" if it did not, or "400 Bad Request" if any of the endpoint's parameters