Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 91 additions & 0 deletions cli/internal/config/aws-config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package config

import (
"bufio"
"os"
"sort"
"strings"

"github.com/leapfrogtechnology/shift/utils/system/exit"
)

func handle(err error) {
if err != nil {
exit.Error(err)
}
}

func closeFile(file *os.File) {
err := file.Close()
handle(err)
}

// GetProfiles gets the profiles stored in user ~/.aws/credentilas
func GetProfiles() []string {
var profiles []string

homeDir, err := os.UserHomeDir()
handle(err)

configAwsPath := homeDir + "/.aws/credentials"

file, err := os.Open(configAwsPath)
handle(err)

defer closeFile(file)

scanFile := bufio.NewScanner(file)
for scanFile.Scan() {
text := scanFile.Text()

if strings.HasPrefix(text, "[") {
profiles = append(profiles, strings.Trim(text, "[]"))
}
}
return profiles

}

func getRegionsWithCode() map[string]string {
return map[string]string{
"US East (Ohio)": "us-east-2",
"US East (N. Virginia)": "us-east-1",
"US West (N. California)": "us-west-1",
"US West (Oregon)": "us-west-2",
"Asia Pacific (Hong Kong)": "ap-east-1",
"Asia Pacific (Mumbai)": "ap-south-1",
"Asia Pacific (Osaka-Local)": "ap-northeast-3",
"Asia Pacific (Seoul)": "ap-northeast-2 ",
"Asia Pacific (Singapore)": "ap-southeast-1",
"Asia Pacific (Sydney)": "ap-southeast-2",
"Asia Pacific (Tokyo)": "ap-northeast-1",
"Canada (Central)": "ca-central-1",
"China (Beijing)": "cn-north-1",
"China (Ningxia)": "cn-northwest-1",
"EU (Frankfurt)": "eu-central-1",
"EU (Ireland)": "eu-west-1",
"EU (London)": "eu-west-2",
"EU (Paris)": "eu-west-3",
"EU (Stockholm)": "eu-north-1",
"South America (São Paulo)": "sa-east-1",
"AWS GovCloud (US-East)": "us-gov-east-1",
"AWS GovCloud (US)": "us-gov-west-1",
}
}

//GetRegions gets the list of aws region names
func GetRegions() []string {
var regions []string

for key := range getRegionsWithCode() {
regions = append(regions, key)
}

sort.Sort(sort.Reverse(sort.StringSlice(regions)))
return regions
}

// GetRegionCode returns the code of the provided AWS region.
func GetRegionCode(name string) string {
return getRegionsWithCode()[name]
}
22 changes: 22 additions & 0 deletions cli/internal/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/AlecAivazis/survey/v2"
"github.com/leapfrogtechnology/shift/cli/internal/config"
)

type projectDetails struct {
Expand All @@ -16,6 +17,8 @@ type projectDetails struct {
type deploymentDetails struct {
DeploymentName string
CloudProvider string
Profile string
Region string
DeploymentType string
}

Expand All @@ -33,6 +36,8 @@ type backendBuildInformation struct {
type deployment struct {
Name string `json:"name"`
Platform string `json:"platform"`
Profile string `json:"profile"`
Region string `json:"region"`
Type string `json:"type"`
BuildCommand string `json:"buildCommand"`
DistFolder string `json:"distFolder"`
Expand Down Expand Up @@ -83,6 +88,20 @@ func askDeploymentDetails() *deploymentDetails {
Options: []string{"AWS", "Azure", "GCP"},
},
},
{
Name: "Profile",
Prompt: &survey.Select{
Message: "Chose Aws Profile:",
Options: config.GetProfiles(),
},
},
{
Name: "Region",
Prompt: &survey.Select{
Message: "Region:",
Options: config.GetRegions(),
},
},
{
Name: "deploymentType",
Prompt: &survey.Select{
Expand All @@ -94,6 +113,7 @@ func askDeploymentDetails() *deploymentDetails {

answers := &deploymentDetails{}
err := survey.Ask(questions, answers)
answers.Region = config.GetRegionCode(answers.Region)

if err != nil {
fmt.Println(err)
Expand Down Expand Up @@ -193,6 +213,8 @@ func Run() {
Deployment: deployment{
Name: deploymentDetails.DeploymentName,
Platform: deploymentDetails.CloudProvider,
Profile: deploymentDetails.Profile,
Region: deploymentDetails.Region,
Type: deploymentDetails.DeploymentType,
BuildCommand: frontendBuildInformation.BuildCommand,
DistFolder: frontendBuildInformation.DistFolder,
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.12

require (
github.com/AlecAivazis/survey/v2 v2.0.4
github.com/leapfrogtechnology/shift/deployment v0.0.0-20191002072505-b6271e5a3950
github.com/streadway/amqp v0.0.0-20190827072141-edfb9018d271
github.com/urfave/cli v1.22.1
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,27 @@ github.com/AlecAivazis/survey/v2 v2.0.4 h1:qzXnJSzXEvmUllWqMBWpZndvT2YfoAUzAMvZU
github.com/AlecAivazis/survey/v2 v2.0.4/go.mod h1:WYBhg6f0y/fNYUuesWQc0PKbJcEliGcYHB9sNT3Bg74=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Netflix/go-expect v0.0.0-20180615182759-c93bf25de8e8/go.mod h1:oX5x61PbNXchhh0oikYAH+4Pcfw5LKv21+Jnpr6r6Pc=
github.com/aws/aws-sdk-go v1.23.13 h1:l/NG+mgQFRGG3dsFzEj0jw9JIs/zYdtU6MXhY1WIDmM=
github.com/aws/aws-sdk-go v1.23.13/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/briandowns/spinner v1.6.1 h1:LBxHu5WLyVuVEtTD72xegiC7QJGx598LBpo3ywKTapA=
github.com/briandowns/spinner v1.6.1/go.mod h1://Zf9tMcxfRUA36V23M6YGEAv+kECGfvpnLTnb8n4XQ=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/gabriel-vasile/mimetype v0.3.18/go.mod h1:kMJbg3SlWZCsj4R73F1WDzbT9AyGCOVmUtIxxwO5pmI=
github.com/go-resty/resty/v2 v2.0.0 h1:9Nq/U+V4xsoDnDa/iTrABDWUCuk3Ne92XFHPe6dKWUc=
github.com/go-resty/resty/v2 v2.0.0/go.mod h1:dZGr0i9PLlaaTD4H/hoZIDjQ+r6xq8mgbRzHZf7f2J8=
github.com/h2non/filetype v1.0.10/go.mod h1:isekKqOuhMj+s/7r3rIeTErIRy4Rub5uBWHfvMusLMU=
github.com/hinshun/vt10x v0.0.0-20180616224451-1954e6464174/go.mod h1:DqJ97dSdRW1W22yXSB90986pcOyQ7r45iio1KN2ez1A=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af h1:pmfjZENx5imkbgOkpRUYLnmbU7UEFbjtDA2hxJ1ichM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs=
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8=
github.com/kr/pty v1.1.4/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/leapfrogtechnology/shift/deployment v0.0.0-20191002072505-b6271e5a3950 h1:RYjt5BiZYvgONzLF4CQqLLXwicMC33rTbT8YM164gJw=
github.com/leapfrogtechnology/shift/deployment v0.0.0-20191002072505-b6271e5a3950/go.mod h1:FQKoH5MsRprr0o/ANivppPjVXkRD3JqUacK9BNHuGYM=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
Expand All @@ -28,6 +42,9 @@ github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtX
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
13 changes: 13 additions & 0 deletions utils/system/exit/exit.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package exit

import (
"fmt"
"os"
)

// Error exits the application by showing the given message.
func Error(err interface{}) {
fmt.Println("Error")
fmt.Println(err)
os.Exit(1)
}