cmd

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2021 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BootstrapCmd = &cobra.Command{
	Use:   "bootstrap",
	Short: "Bootstrap a new Truss deployment.",
	RunE: func(cmd *cobra.Command, args []string) error {
		set, err := cmd.Flags().GetStringToString("set")
		if err != nil {
			return err
		}
		config, err := cmd.Flags().GetString("config")
		if err != nil {
			return err
		}

		c, err := truss.LoadBootstrapConfig(config)
		if err != nil {
			return err
		}
		b, err := c.GetBootstrapper()
		defer b.Cleanup()
		if err != nil {
			return err
		}

		m := b.GetTemplateManifest()
		if m == nil {
			return errors.New("unable to load template manifest")
		}

		p := &truss.BootstrapParams{}
		p.LoadFromConfig(c)
		p.LoadFromFlags(set)

		if errs, err := p.Validate(m); err != nil {
			for _, err := range errs {
				fmt.Println(err)
			}
			return err
		}

		return b.Bootstrap(p)
	},
}

BootstrapCmd represents the bootstrap command

View Source
var BootstrapListTemplatesCmd = &cobra.Command{
	Use:   "list-templates",
	Short: "List available templates for the bootstrap command.",
	RunE: func(cmd *cobra.Command, args []string) error {
		config, _ := cmd.Flags().GetString("config")
		c, err := truss.LoadBootstrapConfig(config)
		if err != nil {
			return err
		}
		ts, err := c.GetTemplateSource()
		if err != nil {
			return err
		}
		defer ts.Cleanup()

		t, err := ts.ListTemplates()
		if err != nil {
			return err
		}

		for _, t := range t {
			fmt.Println(t)
		}

		return nil
	},
}

BootstrapListTemplatesCmd represents the bootstrap list-templates command

View Source
var EnvCmd = &cobra.Command{
	Use:   "env",
	Short: "Display the commands to set up the shell environment for truss",
	RunE: func(cmd *cobra.Command, args []string) error {
		env, err := cmd.Flags().GetString("env")
		if err != nil {
			return err
		}
		kubeconfigs := viper.GetStringMap("environments")
		kubeDir, err := getKubeDir()
		if err != nil {
			return err
		}
		input := &truss.EnvInput{
			Env:         env,
			Kubeconfigs: kubeconfigs,
			KubeDir:     kubeDir,
		}
		environmentVars, err := truss.Env(input)
		if err != nil {
			return err
		}

		output := environmentVars.BashFormat(env)

		fmt.Fprintln(cmd.OutOrStdout(), output)
		return nil
	},
}

EnvCmd represents the env command

View Source
var Version = "development"

Version is the program version, filled in from git during build process via ldflags

View Source
var VpnCmd = &cobra.Command{
	Use:   "vpn",
	Short: "Manage VPN and Network Tunnels for accessing Truss",
	Long: `
Connects to the VPN and configures network routing for accessing Truss clusters using Cisco Anyconnect or sshuttle. This command requires openconnect and optionally sshuttle.

If network traffic doesn't route as you'd expect it to, try adding the -s flag.

Cisco Anyconnect:
During the connection process, the openconnect process will re-invoke the CLI to initialize the connection. This creates the required environment variables for the standard vpnc-script for traffic forwarding.

There is no teardown process when using this method.

sshuttle:
After the connection is established, sshuttle will run as a daemon to forward traffic.

The "truss vpn stop" command will kill this sshuttle process by pid.

By default, all Kubernetes clusters defined in your ~/.truss.yaml will be routed through the VPN. You can specify vpn.forwardHosts and vpn.forwardIPs to add additional static routes as well.
`,
}

VpnCmd manages VPN Connections

View Source
var VpnOpenConnectVpncCmd = &cobra.Command{
	Use:    "openconnect-vpnc",
	Short:  "Used by the NetworkRouteProvider to initialize the VPN Connection",
	Hidden: true,
	RunE: func(cmd *cobra.Command, args []string) error {
		splitinc := os.Getenv("CISCO_SPLIT_INC")
		inc, err := strconv.Atoi(splitinc)
		if err != nil {
			inc = 0
		}

		c := exec.Command(vpncScript)
		c.Stdout = os.Stdout
		c.Stdin = os.Stdin
		c.Stderr = os.Stderr
		c.Env = os.Environ()

		for _, r := range getRoutes(cmd) {
			c.Env = append(c.Env,
				fmt.Sprintf("CISCO_SPLIT_INC_%d_ADDR=%s", inc, r),
				fmt.Sprintf("CISCO_SPLIT_INC_%d_MASK=%s", inc, "255.255.255.255"),
				fmt.Sprintf("CISCO_SPLIT_INC_%d_MASKLEN=%s", inc, "32"),
			)
			inc++
		}
		c.Env = append(c.Env, fmt.Sprintf("CISCO_SPLIT_INC=%d", inc))

		return c.Run()
	},
}

VpnOpenConnectVpncCmd does openconnect things for routes!

View Source
var VpnStartCmd = &cobra.Command{
	Use:   "start",
	Short: "Starts a Truss VPN and Network Tunnel",
	RunE: func(cmd *cobra.Command, args []string) error {
		oc := getOC(cmd)
		return oc.Start()
	},
}

VpnStartCmd starts a VPN connection

View Source
var VpnStopCmd = &cobra.Command{
	Use:   "stop",
	Short: "Stops a Truss VPN and Network Tunnel",
	RunE: func(cmd *cobra.Command, args []string) error {
		oc := getOC(cmd)
		return oc.Stop()
	},
}

VpnStopCmd starts a VPN connection

Functions

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

Types

This section is empty.

Jump to

Keyboard shortcuts

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