Browse Source

add the github private key option

pull/78/head
Chris Mague 6 years ago
parent
commit
b9807b4647
  1. 10
      plugin.go
  2. 15
      terraform.go

10
plugin.go

@ -59,6 +59,16 @@ type (
// Exec executes the plugin
func (p Plugin) Exec() error {
// Install a Github SSH key
if len(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) > 0 {
sshconfErr := installGithubSsh(os.Getenv("GITHUB_PRIVATE_SSH_KEY"))
if sshconfErr != nil {
return sshconfErr
}
}
// Install an AWS profile if env var is set
if len(os.Getenv("AWS_ACCESS_KEY_ID")) > 0 {
profileErr := installProfile(os.Getenv("AWS_PROFILE"), os.Getenv("AWS_ACCESS_KEY_ID"), os.Getenv("AWS_SECRET_ACCESS_KEY"))

15
terraform.go

@ -17,6 +17,21 @@ type (
}
)
func installGithubSsh(githubSshPrivate string) error {
os.Mkdir(os.Getenv("HOME")+"/.aws", 0700)
myconf := []byte("Host github.com\n StrictHostKeyChecking no\n UserKnownHostsFile=/dev/null\n")
err := ioutil.WriteFile(os.Getenv("HOME")+"/.ssh/conf", myconf, 0644)
if err != nil {
return err
}
mykey := []byte(githubSshPrivate)
err2 := ioutil.WriteFile(os.Getenv("HOME")+"/.ssh/id_rsa", mykey, 0600)
if err2 != nil {
return err2
}
return nil
}
func installProfile(profileName string, profileKey string, profileSecret string) error {
os.Mkdir(os.Getenv("HOME")+"/.aws", 0700)
myconf := []byte("[" + profileName + "]\naws_access_key_id = " + profileKey + "\naws_secret_access_key = " + profileSecret + "\n")

Loading…
Cancel
Save