sshctl

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Feb 23, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyConfig       = errors.New("Invalid config")
	ErrEmptyHost         = errors.New("Can't be blank Host")
	ErrEmptyHostName     = errors.New("Can't be blank HostName")
	ErrEmptyUser         = errors.New("Can't be blank User")
	ErrEmptyIdentityFile = errors.New("Can't be blank IdentityFile")
	ErrEmptyPath         = errors.New("Can't be blank config path")
)
View Source
var (
	MakeChoiceAddQuestion func() []*survey.Question = func() []*survey.Question {
		return []*survey.Question{
			{
				Name: "",
				Prompt: &survey.Select{
					Message: "select input format: ",
					Options: []string{
						"0: input from ssh command (ex: ssh -i xxx.pem -p 22 ec2-user@xxx)",
						"1: input from interactive",
					},
				},
				Validate: survey.Required,
			},
		}
	}

	MakeAddQuestionByCommandLine func() []*survey.Question = func() []*survey.Question {
		return []*survey.Question{
			{
				Name: "Command",
				Prompt: &survey.Input{
					Message: "Input ssh command: ",
					Help:    "Available options are -p -i",
				},
				Validate: sshValidator,
			},
			{
				Name: "Host",
				Prompt: &survey.Input{
					Message: "unique label as host: ",
				},
				Validate: survey.Required,
			},
		}
	}

	MakeAddQuestionByInteractive func() []*survey.Question = func() []*survey.Question {
		return []*survey.Question{
			{
				Name: "HOST",
				Prompt: &survey.Input{
					Message: "Enter Unique Name to represent specific endpoint:",
				},
				Validate: survey.Required,
			},
			{
				Name: "HostName",
				Prompt: &survey.Input{
					Message: "Enter HostName that represents the connection destination:",
					Help:    "Please type ip address for example 35.190.247.0",
				},
				Validate: survey.Required,
			},
			{
				Name: "User",
				Prompt: &survey.Input{
					Message: "Enter user name: ",
					Default: "ec2-user",
				},
			},
			{
				Name: "IdentityFile",
				Prompt: &survey.Input{
					Message: "Enter IdentityFile path: ",
					Help:    "That is key file. ssh -i xxx. Commonly used extensions are pem or rsa. If you define $IDENTITY_KEY, use it as default value",
					Default: os.Getenv("IDENTITY_KEY"),
				},
				Validate: survey.Required,
			},
			{
				Name: "ProxyCommand",
				Prompt: &survey.Input{
					Message: "Enter ProxyCommand: ",
					Help:    "ex) ssh -W %h:%p test",
				},
			},
		}
	}

	MakeUpdateQuestion func(c *Config) []*survey.Question = func(c *Config) []*survey.Question {
		return []*survey.Question{
			{
				Name: "HOST",
				Prompt: &survey.Input{
					Message: "Enter Unique Name to represent specific endpoint:",
					Default: c.Host,
				},
				Validate: survey.Required,
			},
			{
				Name: "HostName",
				Prompt: &survey.Input{
					Message: "Enter HostName that represents the connection destination:",
					Help:    "Please type ip address for example 35.190.247.0",
					Default: c.HostName,
				},
				Validate: survey.Required,
			},
			{
				Name: "User",
				Prompt: &survey.Input{
					Message: "Enter user name: ",
					Default: c.User,
				},
			},
			{
				Name: "IdentityFile",
				Prompt: &survey.Input{
					Message: "Enter IdentityFile path: ",
					Help:    "That is key file. ssh -i xxx. Commonly used extensions are pem or rsa. If you define $IDENTITY_KEY, use it as default value",
					Default: c.IdentityFile,
				},
				Validate: survey.Required,
			},
		}
	}
)
View Source
var (
	Stdout = colorable.NewColorableStdout() // add a colorable std out
	Stderr = colorable.NewColorableStderr() // add a colorable std err
)
View Source
var InitData = `
HOST init
	HostName 54.238.176.202
	User ec2-user
	identityFile /key.pem
`
View Source
var InitDataConfig = Config{
	Host:         InitDataMap[0]["HOST"],
	HostName:     InitDataMap[0]["HostName"],
	User:         InitDataMap[0]["User"],
	IdentityFile: InitDataMap[0]["identityFile"],
	ProxyCommand: InitDataMap[0]["ProxyCommand"],
}
View Source
var InitDataMap = []map[string]string{
	{
		"HOST":         "init",
		"HostName":     "54.238.176.202",
		"User":         "ec2-user",
		"identityFile": "/key.pem",
	},
}

Functions

func CreateTestConfigFile

func CreateTestConfigFile(t *testing.T) (string, func())

func Decode

func Decode(r io.Reader) ([]map[string]string, error)

func ShowError

func ShowError(text string) error

func ShowMessage

func ShowMessage(level, text string, startWithNewLine, endWithNewLine bool)

Types

type Client

type Client struct {
	Path          string
	ContentLength string
}

func NewClient

func NewClient(src string) *Client

func (*Client) List

func (c *Client) List() ([]string, error)

func (*Client) Put

func (c *Client) Put(config *Config) (int, error)

func (*Client) ReadAll

func (c *Client) ReadAll() ([]Config, error)

func (*Client) Update

func (c *Client) Update(index int, config Config) error

一覧撮ってきて_configに書き込むのが良いかな データ消えるの怖いからbackupとして残すのもいいかもね

type Config

type Config struct {
	Command      string
	Host         string
	HostName     string
	Port         string
	User         string
	IdentityFile string
	ProxyCommand string
}

func NewConfig

func NewConfig() *Config

func (*Config) DumpFormattedString

func (c *Config) DumpFormattedString() string

func (*Config) Valid

func (c *Config) Valid() error

Jump to

Keyboard shortcuts

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