ssh

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Display = &cobra.Command{
		Use:   "print [profile]",
		Args:  cobra.ExactArgs(1),
		Short: "Print out configuration file",
		Long:  "Print out configuration file",
		Run: func(cmd *cobra.Command, args []string) {
			name := args[0]
			cfg := viper.Get(name)

			fmt.Printf("%s\n", cfg)
		},
	}
)
View Source
var (
	Load = &cobra.Command{
		Use:   "load [profile name]",
		Args:  cobra.ExactArgs(1),
		Short: "Write existing profile to current ssh configuration",
		Long:  "Write existing profile to current ssh configuration",
		Run: func(cmd *cobra.Command, args []string) {
			name := args[0]
			if err := viper.ReadInConfig(); err == nil {
				if h, err := os.UserHomeDir(); err == nil {
					config_file := filepath.Join(h, ".ssh", "config")
					profile_contents := viper.GetString(name)
					if err := ioutil.WriteFile(config_file, []byte(profile_contents), 500); err == nil {
						fmt.Println("Successfully loaded new profile!")
					} else {
						log.Fatalln(err)
					}
				} else {
					log.Fatalln(err)
				}
			} else {
				log.Fatalln(err)
			}
		},
	}
)
View Source
var (
	New = &cobra.Command{
		Use:   "save [profile]",
		Args:  cobra.ExactArgs(1),
		Short: "Save a new profile",
		Long:  "Save a new profile",
		Run: func(cmd *cobra.Command, args []string) {
			name := args[0]

			if err := viper.ReadInConfig(); err == nil {
				if debug {
					log.Println("Successfully read in existing configuration file: ", viper.ConfigFileUsed())
				}
			} else {
				log.Fatalln("Error reading viper config: ", err)
			}

			if h, err := os.UserHomeDir(); err == nil {
				config_file := filepath.Join(h, ".ssh", "config")

				if debug {
					log.Printf("Checking SSH Config at: %s\n", config_file)
				}

				if _, err := os.Stat(config_file); err == nil {
					log.Printf("File exists, creating SSH profile entry\n")

					if data, err := ioutil.ReadFile(config_file); err == nil {
						viper.Set(name, string(data))
						if err := viper.WriteConfig(); err == nil {
							log.Println("Successfully wrote new profile!")
						} else {
							log.Fatalln("Error writing to profiler: ", err)
						}
					} else {
						log.Fatalln("Error reading ssh config: ", err)
					}
				}
			} else {
				log.Fatalln("Error finding ssh directory: ", err)
			}

		},
	}
)
View Source
var (
	Ssh = &cobra.Command{
		Use:   "ssh",
		Short: "A profiling system for the SSH config file",
		Long:  "A profiling system for the SSH config file",
		Run: func(cmd *cobra.Command, args []string) {

			if len(args) == 0 {
				cmd.Help()
				os.Exit(0)
			}
		},
	}
)

Ssh is largely clerical, will link sub commands here

Functions

func Execute

func Execute()

Execute is called on by the main process

Types

This section is empty.

Jump to

Keyboard shortcuts

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