Skip to content

Commit

Permalink
Merge 1cfb743 into d8734fe
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Jun 28, 2018
2 parents d8734fe + 1cfb743 commit 2609d56
Show file tree
Hide file tree
Showing 14 changed files with 674 additions and 7 deletions.
54 changes: 53 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@
[[constraint]]
name = "github.com/gorilla/websocket"
version = "1.2.0"

[[constraint]]
name = "github.com/aws/aws-sdk-go"
version = "1.14.10"
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ dev-deps:

# Install Inertia with release version
.PHONY: cli
inertia:
cli:
go install -ldflags "-X main.Version=$(RELEASE)"

# Install Inertia with git tag as release version
.PHONY: cli-tagged
inertia-tagged:
cli-tagged:
go install -ldflags "-X main.Version=$(TAG)"

# Remove Inertia binaries
Expand Down
6 changes: 3 additions & 3 deletions client/internal/compiled.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion client/scripts/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@ set -e
DOCKER_SOURCE=get.docker.com
DOCKER_DEST='/tmp/get-docker.sh'

startDockerd() {
# Start dockerd if it is not online
if ! sudo docker stats --no-stream ; then
sudo service docker start
# Poll until dockerd is running
while ! sudo docker stats --no-stream ; do
echo "Waiting for dockerd to launch..."
sleep 1
done
fi
}

# Skip installation if Docker is already installed.
if hash docker 2>/dev/null; then
startDockerd
exit 0
fi;

Expand Down Expand Up @@ -40,4 +53,4 @@ else
fi
fi

sudo service docker start
startDockerd
18 changes: 18 additions & 0 deletions common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"io"
"os"
"path/filepath"
"strconv"
"time"
)

// GetFullPath returns the absolute path of the config file.
Expand Down Expand Up @@ -70,3 +72,19 @@ func RemoveContents(directory string) error {
}
return nil
}

// ParseDate parses a date in format "2006-01-02T15:04:05.000Z"
func ParseDate(dateString string) *time.Time {
layout := "2006-01-02T15:04:05.000Z"
t, _ := time.Parse(layout, dateString)
return &t
}

// ParseInt64 parses a string into an int64 value
func ParseInt64(value string) (int64, error) {
i, err := strconv.ParseInt(value, 10, 64)
if err != nil {
return 0, err
}
return i, nil
}
13 changes: 13 additions & 0 deletions common/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,16 @@ func TestExtract(t *testing.T) {
repoNameWithMixed := ExtractRepository("git@github.com:ubclaunchpad/inertia-deploy.test.git")
assert.Equal(t, "ubclaunchpad/inertia-deploy.test", repoNameWithMixed)
}

func TestParseDate(t *testing.T) {
assert.NotNil(t, ParseDate("2006-01-02T15:04:05.000Z"))
}

func TestParseInt64(t *testing.T) {
parsed, err := ParseInt64("10")
assert.Nil(t, err)
assert.Equal(t, int64(10), parsed)

_, err = ParseInt64("")
assert.NotNil(t, err)
}
48 changes: 48 additions & 0 deletions input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
)

var (
errInvalidInput = errors.New("invalid input")

errInvalidUser = errors.New("invalid user")
errInvalidAddress = errors.New("invalid IP address")
errInvalidBuildType = errors.New("invalid build type")
Expand Down Expand Up @@ -114,3 +116,49 @@ func addProjectWalkthrough(in io.Reader) (buildType string, buildFilePath string
}
return
}

func enterEC2CredentialsWalkthrough(in io.Reader) (id, key string, err error) {
print(`To get your credentials:
1. Open the IAM console (https://console.aws.amazon.com/iam/home?#home).
2. In the navigation pane of the console, choose Users. You may have to create a user.
3. Choose your IAM user name (not the check box).
4. Choose the Security credentials tab and then choose Create access key.
5. To see the new access key, choose Show. Your credentials will look something like this:
Access key ID: AKIAIOSFODNN7EXAMPLE
Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
`)

var response string

print("\nKey ID: ")
_, err = fmt.Fscanln(in, &response)
if err != nil {
return
}
id = response

print("\nAccess Key: ")
_, err = fmt.Fscanln(in, &response)
if err != nil {
return
}
key = response
return
}

func chooseFromListWalkthrough(in io.Reader, optionName string, options []string) (string, error) {
fmt.Printf("Available %ss:\n", optionName)
for _, o := range options {
println(" > " + o)
}
fmt.Printf("Please enter your desired %s: ", optionName)

var response string
_, err := fmt.Fscanln(in, &response)
if err != nil {
return "", errInvalidInput
}

return response, nil
}
5 changes: 5 additions & 0 deletions local/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ func GetClient(name, relPath string, cmd ...*cobra.Command) (*client.Client, err

return client, nil
}

// SaveKey writes a key to given path
func SaveKey(keyMaterial string, path string) error {
return ioutil.WriteFile(path, []byte(keyMaterial), 0644)
}
47 changes: 47 additions & 0 deletions local/storage_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package local

import (
"io/ioutil"
"os"
"path"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -72,3 +74,48 @@ func TestConfigCreateAndWriteAndRead(t *testing.T) {
err = os.Remove(configPath)
assert.Nil(t, err)
}

func TestSaveKey(t *testing.T) {
keyMaterial := `-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEAw+14SQTAidfYPDizCYPv0gWq4+wFeInCrZGo4BFbMcP7xhH+
htmm0qx7ctYbCS0tQmCvCnt4W5jwhqH9v65/b1PWv1qQbXbJq0iyeSspgpaB8xq+
AkWoBkUOT8iaUzESDgJfEpC9q1s7dAUpmRDD0JMVzdsv1VQqpR22VWtnpcFtAkNk
3CIXiKFYJ5677dVSrc45dhO4R67LguSPxpXNRcg26/cFKWQO+y2StnYVEEUtvoWN
z2tGQu2hftJtjzzCFXckH8VTJ8EgX0+3Co5jXEbm1idFGFgcAP1WT3xuGh+wpCXM
LYVdF18VxGzZe0bxStZ/+bhsaYfFLyU8qL7RnQIDAQABAoIBAFELWLczjQU30I1Q
ktZ7yebhS0gOa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tml86lm4FrfZlLEfwb6TaR/Unsh0
XF56ZdrKh0nbOW/125RSc8STCv5klDGnBCD56Qzbin9+W6j1TWyJFMdNeaxjWK+U
lq07qdr3cY+O1F4otlDitNuhLE88dtGJM5lEyumokiH1yXwhbBtZ4w==
-----END RSA PRIVATE KEY-----`
cwd, _ := os.Getwd()
testKeyPath := path.Join(cwd, "test_key_save")

// Write
err := SaveKey(keyMaterial, testKeyPath)
assert.Nil(t, err)

// Read
bytes, err := ioutil.ReadFile(testKeyPath)
assert.Nil(t, err)
assert.Equal(t, keyMaterial, string(bytes))

// Test config remove
err = os.Remove(testKeyPath)
assert.Nil(t, err)
}
Loading

0 comments on commit 2609d56

Please sign in to comment.