From 39a9e99630c3f8f361700773b7338393f3a473d8 Mon Sep 17 00:00:00 2001 From: CapsuleCD Date: Sat, 21 Apr 2018 01:56:46 +0000 Subject: [PATCH] (v1.0.4) Automated packaging of release by CapsuleCD --- cmd/drawbridge/drawbridge.go | 4 ++-- pkg/actions/connect.go | 25 +++++++++++-------------- pkg/actions/create.go | 1 - pkg/config/config.go | 2 +- pkg/config/template/config_template.go | 8 ++++---- pkg/config/template/file_template.go | 9 ++++----- pkg/config/template/template.go | 2 +- pkg/errors/errors.go | 7 +------ pkg/utils/stdin.go | 4 ++-- pkg/version/version.go | 2 +- 10 files changed, 27 insertions(+), 37 deletions(-) diff --git a/cmd/drawbridge/drawbridge.go b/cmd/drawbridge/drawbridge.go index 1ca7073..98df23d 100644 --- a/cmd/drawbridge/drawbridge.go +++ b/cmd/drawbridge/drawbridge.go @@ -5,13 +5,13 @@ import ( "os" "time" - "drawbridge/pkg/config" "drawbridge/pkg/actions" + "drawbridge/pkg/config" "drawbridge/pkg/utils" "drawbridge/pkg/version" "gopkg.in/urfave/cli.v2" - "strconv" "log" + "strconv" ) var goos string diff --git a/pkg/actions/connect.go b/pkg/actions/connect.go index 8b4494f..0d6a08c 100644 --- a/pkg/actions/connect.go +++ b/pkg/actions/connect.go @@ -1,20 +1,20 @@ package actions import ( + "crypto/x509" "drawbridge/pkg/config" - "drawbridge/pkg/utils" - "path/filepath" - "syscall" - "os" - "os/exec" "drawbridge/pkg/errors" - "golang.org/x/crypto/ssh/agent" - "net" - "golang.org/x/crypto/ssh" + "drawbridge/pkg/utils" "encoding/pem" "fmt" + "golang.org/x/crypto/ssh" + "golang.org/x/crypto/ssh/agent" "io/ioutil" - "crypto/x509" + "net" + "os" + "os/exec" + "path/filepath" + "syscall" ) type ConnectAction struct { @@ -51,13 +51,11 @@ func (e *ConnectAction) Start(answerData map[string]interface{}) error { //TODO: Check that the bastion host is accessible. - e.SshAgentAddPemKey(tmplPemFilepath) //https://gobyexample.com/execing-processes //https://groob.io/posts/golang-execve/ - sshBin, lookErr := exec.LookPath("ssh") if lookErr != nil { return errors.DependencyMissingError("ssh is missing") @@ -68,7 +66,6 @@ func (e *ConnectAction) Start(answerData map[string]interface{}) error { return syscall.Exec(sshBin, args, os.Environ()) } - func (e *ConnectAction) SshAgentAddPemKey(pemFilepath string) error { //first lets ensure that the pemFilepath exists if !utils.FileExists(pemFilepath) { @@ -114,8 +111,8 @@ func (e *ConnectAction) SshAgentAddPemKey(pemFilepath string) error { agentClient := agent.NewClient(conn) err = agentClient.Add(agent.AddedKey{ - PrivateKey: privateKeyData, - Comment: fmt.Sprintf("drawbridge - %v", pemFilepath), + PrivateKey: privateKeyData, + Comment: fmt.Sprintf("drawbridge - %v", pemFilepath), //LifetimeSecs: TODO: for safety we should limit this key's use for 1h }) diff --git a/pkg/actions/create.go b/pkg/actions/create.go index 2969df6..097ecfe 100644 --- a/pkg/actions/create.go +++ b/pkg/actions/create.go @@ -56,7 +56,6 @@ func (e *CreateAction) Start(cliAnswerData map[string]interface{}) error { } } - // write the config template, make sure we "fix" the config filepath activeConfigTemplate, err := e.Config.GetActiveConfigTemplate() if err != nil { diff --git a/pkg/config/config.go b/pkg/config/config.go index 214ebe2..2950670 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -2,9 +2,9 @@ package config import ( "bytes" + "drawbridge/pkg/config/template" "drawbridge/pkg/errors" "drawbridge/pkg/utils" - "drawbridge/pkg/config/template" "fmt" "github.com/spf13/viper" "github.com/xeipuuv/gojsonschema" diff --git a/pkg/config/template/config_template.go b/pkg/config/template/config_template.go index d2078f5..c67ef2c 100644 --- a/pkg/config/template/config_template.go +++ b/pkg/config/template/config_template.go @@ -1,16 +1,16 @@ package template import ( - "path" - "fmt" "drawbridge/pkg/utils" + "fmt" + "path" ) // for configs `filepath`, must be relative to config_dir //for configs `pem_filepath` must be relative to pem_dir type ConfigTemplate struct { FileTemplate `mapstructure:",squash"` - PemFilePath string `mapstructure:"pem_filepath"` + PemFilePath string `mapstructure:"pem_filepath"` } func (t *ConfigTemplate) WriteTemplate(answerData map[string]interface{}) error { @@ -51,4 +51,4 @@ func configTemplatePrefix(answerData map[string]interface{}) string { } prefix += "\n" return prefix -} \ No newline at end of file +} diff --git a/pkg/config/template/file_template.go b/pkg/config/template/file_template.go index 8c9d2d7..cf2dfd4 100644 --- a/pkg/config/template/file_template.go +++ b/pkg/config/template/file_template.go @@ -1,12 +1,12 @@ package template import ( + "drawbridge/pkg/errors" + "drawbridge/pkg/utils" + "fmt" + "log" "os" "path/filepath" - "log" - "fmt" - "drawbridge/pkg/utils" - "drawbridge/pkg/errors" ) type FileTemplate struct { @@ -14,7 +14,6 @@ type FileTemplate struct { FilePath string `mapstructure:"filepath"` } - func (t *FileTemplate) WriteTemplate(answerData map[string]interface{}) error { templatedFilePath, err := utils.PopulateTemplate(t.FilePath, answerData) if err != nil { diff --git a/pkg/config/template/template.go b/pkg/config/template/template.go index 33bc805..541007d 100644 --- a/pkg/config/template/template.go +++ b/pkg/config/template/template.go @@ -1,5 +1,5 @@ package template type Template struct { - Content string `mapstructure:"content"` + Content string `mapstructure:"content"` } diff --git a/pkg/errors/errors.go b/pkg/errors/errors.go index 029ce0c..53604e3 100644 --- a/pkg/errors/errors.go +++ b/pkg/errors/errors.go @@ -27,6 +27,7 @@ func (str DependencyMissingError) Error() string { // Raised when a SSH/pem key is not present. type PemKeyMissingError string + func (str PemKeyMissingError) Error() string { return fmt.Sprintf("PemKeyMissingError: %q", string(str)) } @@ -38,12 +39,6 @@ func (str TemplateFileExistsError) Error() string { return fmt.Sprintf("TemplateFileExistsError: %q", string(str)) } - - - - - - // Raised when Question does not exist type QuestionKeyInvalidError string diff --git a/pkg/utils/stdin.go b/pkg/utils/stdin.go index fcbcfd4..f0030f2 100644 --- a/pkg/utils/stdin.go +++ b/pkg/utils/stdin.go @@ -2,8 +2,8 @@ package utils import ( "bufio" - "os" "fmt" + "os" "strings" ) @@ -15,4 +15,4 @@ func StdinQuery(question string) string { fmt.Println(text) text = strings.TrimSpace(text) return text -} \ No newline at end of file +} diff --git a/pkg/version/version.go b/pkg/version/version.go index 4549e97..f88396e 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -2,4 +2,4 @@ package version // VERSION is the app-global version string, which will be replaced with a // new value during packaging -const VERSION = "1.0.3" +const VERSION = "1.0.4"