Skip to content

Commit

Permalink
(v1.0.4) Automated packaging of release by CapsuleCD
Browse files Browse the repository at this point in the history
  • Loading branch information
CapsuleCD committed Apr 21, 2018
1 parent 15e46bf commit 39a9e99
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 37 deletions.
4 changes: 2 additions & 2 deletions cmd/drawbridge/drawbridge.go
Expand Up @@ -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
Expand Down
25 changes: 11 additions & 14 deletions 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 {
Expand Down Expand Up @@ -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")
Expand All @@ -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) {
Expand Down Expand Up @@ -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
})

Expand Down
1 change: 0 additions & 1 deletion pkg/actions/create.go
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions 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 {
Expand Down Expand Up @@ -51,4 +51,4 @@ func configTemplatePrefix(answerData map[string]interface{}) string {
}
prefix += "\n"
return prefix
}
}
9 changes: 4 additions & 5 deletions pkg/config/template/file_template.go
@@ -1,20 +1,19 @@
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 {
Template `mapstructure:",squash"`
FilePath string `mapstructure:"filepath"`
}


func (t *FileTemplate) WriteTemplate(answerData map[string]interface{}) error {
templatedFilePath, err := utils.PopulateTemplate(t.FilePath, answerData)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/template/template.go
@@ -1,5 +1,5 @@
package template

type Template struct {
Content string `mapstructure:"content"`
Content string `mapstructure:"content"`
}
7 changes: 1 addition & 6 deletions pkg/errors/errors.go
Expand Up @@ -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))
}
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions pkg/utils/stdin.go
Expand Up @@ -2,8 +2,8 @@ package utils

import (
"bufio"
"os"
"fmt"
"os"
"strings"
)

Expand All @@ -15,4 +15,4 @@ func StdinQuery(question string) string {
fmt.Println(text)
text = strings.TrimSpace(text)
return text
}
}
2 changes: 1 addition & 1 deletion pkg/version/version.go
Expand Up @@ -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"

0 comments on commit 39a9e99

Please sign in to comment.