cmd

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetCmd = &cobra.Command{
	Use:     "get [flags] resource",
	Short:   "Retrieve a Kapow! resource",
	Long:    "Retrieve a Kapow! resource for the current request",
	Args:    cobra.ExactArgs(1),
	PreRunE: handlerIDRequired,
	Run: func(cmd *cobra.Command, args []string) {
		dataURL, _ := cmd.Flags().GetString("data-url")
		handler, _ := cmd.Flags().GetString("handler")

		err := client.GetData(dataURL, handler, args[0], os.Stdout)
		if err != nil {
			logger.L.Fatal(err)
		}
	},
}

GetCmd is the command line interface for get kapow data operation

View Source
var RouteCmd = &cobra.Command{
	Use: "route [action]",
}

RouteCmd is the command line interface for kapow route handling

View Source
var ServerCmd = &cobra.Command{
	Use:   "server [optional flags] [optional init program(s)]",
	Short: "Start a kapow server",
	Long: `Start a Kapow server with a client interface, a data interface	and an
	admin interface`,
	PreRunE: validateServerCommandArguments,
	Run: func(cmd *cobra.Command, args []string) {
		var sConf server.ServerConfig = server.ServerConfig{}
		sConf.UserBindAddr, _ = cmd.Flags().GetString("bind")
		sConf.ControlBindAddr, _ = cmd.Flags().GetString("control-bind")
		sConf.DataBindAddr, _ = cmd.Flags().GetString("data-bind")

		controlReachableAddr, _ := cmd.Flags().GetString("control-reachable-addr")

		sConf.CertFile, _ = cmd.Flags().GetString("certfile")
		sConf.KeyFile, _ = cmd.Flags().GetString("keyfile")

		sConf.ClientAuth, _ = cmd.Flags().GetBool("clientauth")
		sConf.ClientCaFile, _ = cmd.Flags().GetString("clientcafile")
		sConf.Debug, _ = cmd.Flags().GetBool("debug")

		sConf.ControlServerCert = certs.GenCert("control_server", extractHost(controlReachableAddr), true)
		sConf.ControlClientCert = certs.GenCert("control_client", "", false)

		if _, exist := os.LookupEnv("KAPOW_DATA_URL"); !exist {
			os.Setenv("KAPOW_DATA_URL", "http://"+sConf.DataBindAddr)
		}
		if _, exist := os.LookupEnv("KAPOW_CONTROL_URL"); !exist {
			os.Setenv("KAPOW_CONTROL_URL", "https://"+controlReachableAddr)
		}
		banner()

		server.StartServer(sConf)

		for _, path := range args {
			go Run(
				path,
				sConf.Debug,
				sConf.ControlServerCert.SignedCertPEMBytes(),
				sConf.ControlClientCert.SignedCertPEMBytes(),
				sConf.ControlClientCert.PrivateKeyPEMBytes(),
			)
		}

		select {}
	},
}

ServerCmd is the command line interface for kapow server

View Source
var SetCmd = &cobra.Command{
	Use:     "set [flags] resource [value]",
	Short:   "Set a Kapow! resource value",
	Long:    "Set a Kapow! resource value for the current request",
	Args:    cobra.RangeArgs(1, 2),
	PreRunE: handlerIDRequired,
	Run: func(cmd *cobra.Command, args []string) {
		var r io.Reader
		dataURL, _ := cmd.Flags().GetString("data-url")
		handler, _ := cmd.Flags().GetString("handler")
		path, args := args[0], args[1:]

		if len(args) == 1 {
			r = strings.NewReader(args[0])
		} else {
			r = os.Stdin
		}

		if err := client.SetData(dataURL, handler, path, r); err != nil {
			logger.L.Fatal(err)
		}
	},
}

SetCmd is the command line interface for set kapow data operation

Functions

func BuildCmd added in v0.7.0

func BuildCmd(path string) *exec.Cmd

func Run added in v0.7.0

func Run(
	path string,
	debug bool,
	controlServerCertPEM,
	controlClientCertPEM,
	controlClientCertPrivKeyPEM []byte,
)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL