Skip to content

Commit

Permalink
working on dynamically specifying pem_filepath.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogJ committed Apr 20, 2018
1 parent 6fd3cbf commit 57338c3
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README.md
Expand Up @@ -83,4 +83,13 @@
- https://stackoverflow.com/questions/12484398/global-template-data
- https://stackoverflow.com/questions/35612456/how-to-use-golang-template-missingkey-option
- https://medium.com/@dgryski/consistent-hashing-algorithmic-tradeoffs-ef6b8e2fcae8
- https://github.com/mitchellh/go-homedir
- https://github.com/mitchellh/go-homedir
- https://gobyexample.com/execing-processes
- https://groob.io/posts/golang-execve/
- https://www.digitalocean.com/community/tutorials/how-to-configure-custom-connection-options-for-your-ssh-client

- https://github.com/zalando/go-keyring
- https://github.com/tmc/keyring
- https://github.com/jaraco/keyring
- https://github.com/99designs/keyring
- https://unix.stackexchange.com/questions/64795/must-i-store-a-private-key-in-a-file
16 changes: 15 additions & 1 deletion pkg/config/config.go
Expand Up @@ -34,6 +34,8 @@ func (c *configuration) Init() error {
c.SetDefault("options.config_dir", "~/.ssh/drawbridge")
c.SetDefault("options.pem_dir", "~/.ssh")
c.SetDefault("options.active_config_template", "default")
c.SetDefault("options.active_pem_template", "default")

c.SetDefault("options.active_extra_templates", []string{})
c.SetDefault("options.ui_group_priority", []string{"environment", "username"})
c.SetDefault("options.ui_question_hidden", []string{})
Expand Down Expand Up @@ -75,6 +77,10 @@ func (c *configuration) Init() error {
})
c.SetDefault("answers", []map[string]interface{}{})



c.SetDefault("pem_templates.default", "{{pem_dir}}/{{.environment}}-{{.username}}-pem")

c.SetDefault("config_templates.default.filepath", "{{.environment}}-{{.username}}-config")
c.SetDefault("config_templates.default.content", utils.StripIndent(
`
Expand All @@ -87,7 +93,7 @@ func (c *configuration) Init() error {
Host bastion
Hostname bastion.example.com
User {{.username}}
IdentityFile {{.pem_dir}}/{{.pem_filename}}
IdentityFile {{.pem_filepath}}
LocalForward localhost:{{uniquePort .}} localhost:8080
UserKnownHostsFile=/dev/null
StrictHostKeyChecking=no
Expand Down Expand Up @@ -303,6 +309,14 @@ func (c *configuration) ValidateConfigFile(configFilePath string) error {
}
}
},
"pem_templates":{
"type": "object",
"patternProperties": {
"^[a-z0-9]*$":{
"type":"string"
}
}
},
"extra_templates":{
"type": "object",
"patternProperties": {
Expand Down
6 changes: 4 additions & 2 deletions pkg/connect/connect.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"path/filepath"
"syscall"
"os"
)

type ConnectEngine struct {
Expand All @@ -30,11 +31,12 @@ func (e *ConnectEngine) Start(answerData map[string]interface{}) error {
}
//Print the lines we're running.
//Check that the bastion host is accessible.

//https://gobyexample.com/execing-processes
//https://groob.io/posts/golang-execve/

return syscall.Exec("/bin/bash", []string{"-c",
fmt.Sprintf("ssh bastion -F %v",
//filepath.Join(e.Config.GetString("options.pem_dir"), e.Config.GetString("options.pem_filename")),
tmplConfigFilepath),
}, []string{})
}, os.Environ())
}

0 comments on commit 57338c3

Please sign in to comment.