Browse Source

setup a pem key if required for builds

pull/78/head
Chris Mague 6 years ago
parent
commit
bb61be4abf
  1. 14
      plugin.go
  2. 8
      terraform.go

14
plugin.go

@ -59,6 +59,20 @@ type (
// Exec executes the plugin // Exec executes the plugin
func (p Plugin) Exec() error { func (p Plugin) Exec() error {
// Install a extra PEM key if required
if len(os.Getenv("PEM_NAME")) > 0 {
value, exists := os.LookupEnv("PEM_CONTENTS")
if !exists {
value = "-----BEGIN RSA PRIVATE KEY-----\n\n-----END RSA PRIVATE KEY-----\n"
}
err := installExtraPem(os.Getenv("PEM_NAME"), value)
if err != nil {
return err
}
}
// Install a Github SSH key // Install a Github SSH key
if len(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) > 0 { if len(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) > 0 {
sshconfErr := installGithubSsh(os.Getenv("GITHUB_PRIVATE_SSH_KEY")) sshconfErr := installGithubSsh(os.Getenv("GITHUB_PRIVATE_SSH_KEY"))

8
terraform.go

@ -17,6 +17,14 @@ type (
} }
) )
func installExtraPem(pemName string, pemContents string) error {
err := ioutil.WriteFile(os.Getenv("HOME")+"/.ssh/"+pemName, []byte(pemContents), 0600)
if err != nil {
return err
}
return nil
}
func installGithubSsh(githubSshPrivate string) error { func installGithubSsh(githubSshPrivate string) error {
os.Mkdir(os.Getenv("HOME")+"/.aws", 0700) os.Mkdir(os.Getenv("HOME")+"/.aws", 0700)
myconf := []byte("Host github.com\n StrictHostKeyChecking no\n UserKnownHostsFile=/dev/null\n") myconf := []byte("Host github.com\n StrictHostKeyChecking no\n UserKnownHostsFile=/dev/null\n")

Loading…
Cancel
Save