Skip to content

Commit

Permalink
Updated the custom variable checker methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Kotowick committed Mar 29, 2017
1 parent 913cd17 commit d792539
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 27 deletions.
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM alpine:latest

RUN apk --update add ca-certificates

COPY ./bin/go-deploy /usr/local/bin/go-deploy/

COPY ./run.sh /
Expand Down
Binary file modified bin/go-deploy
Binary file not shown.
Binary file modified bin/go-deploy-1.0.3
Binary file not shown.
32 changes: 20 additions & 12 deletions lib/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,32 @@ func ShellOut(message string, p ShellOutParams) {

// VerifyParamatersWithOr returns true if any of the paramaters in args[] are empty.
// This checks to see if required variables are set or not
func VerifyParamatersWithOr(args map[string]string) bool {
for k, v := range args {
if v == "" {
log.Fatal(fmt.Sprintf("%s is not set.", k))
return false
func VerifyParamatersWithOr(required bool, args map[string]string) bool {
for _, v := range args {
if v != "" {
return true
}
}
return true

if required {
log.Fatal("VerifyParamatersWithOr failed: all of the paramaters returned empty\n")
}

return false
}

// VerifyParamatersWithAnd returns true if any of the paramaters in args[] are not empty.
// This checks to see if required variables are set or not
func VerifyParamatersWithAnd(args map[string]string) bool {
for _, v := range args {
if v != "" {
return true
func VerifyParamatersWithAnd(required bool, args map[string]string) bool {
for k, v := range args {
if v == "" {
if required {
log.Fatal(fmt.Sprintf("%s is not set\n", k))
} else {
fmt.Printf("%s is not set\n", k)
}
return false
}
}
log.Fatal("VerifyParamatersWithOr failed: all of the paramaters returns empty")
return false
return true
}
22 changes: 11 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func listFunction(listMethod string, awsConfig config.Config, ebService elasticb
case "list applications":
ebService.ListApplications(*verbose, true)
case "list environments":
if utils.VerifyParamatersWithOr(map[string]string{"Application Name": *environmentApplicationNameArg}) {
if utils.VerifyParamatersWithAnd(true, map[string]string{"Application Name": *environmentApplicationNameArg}) {
ebService.ListEnvironments(*verbose, true, *environmentApplicationNameArg, *environmentNameArg)
}
default:
Expand All @@ -127,15 +127,15 @@ func listFunction(listMethod string, awsConfig config.Config, ebService elasticb
func createFunction(createMethod string, awsConfig config.Config, ebService elasticbeanstalk.ElasticBeanstalk, s3Service s3.S3) {
bucketInfo := s3Service.ParseS3Bucket(*environmentS3Arg)

if !utils.VerifyParamatersWithOr(map[string]string{"Application Name": *environmentApplicationNameArg}) {
if !utils.VerifyParamatersWithAnd(true, map[string]string{"Application Name": *environmentApplicationNameArg}) {
return
}

switch createMethod {
case "create application":
ebService.CreateApplication(*environmentApplicationNameArg)
case "create environment":
if !utils.VerifyParamatersWithOr(map[string]string{"Local File Path": *environmentLocalFilePathArg, "Environment Name": *environmentNameArg, "Tier": *environmentTierArg, "Configuration File": *environmentConfigArg, "S3 Bucket/path": *environmentS3Arg, "Version": *environmentVersionArg}) {
if !utils.VerifyParamatersWithAnd(true, map[string]string{"Local File Path": *environmentLocalFilePathArg, "Environment Name": *environmentNameArg, "Tier": *environmentTierArg, "Configuration File": *environmentConfigArg, "S3 Bucket/path": *environmentS3Arg, "Version": *environmentVersionArg}) {
return
}

Expand Down Expand Up @@ -176,11 +176,11 @@ func createFunction(createMethod string, awsConfig config.Config, ebService elas
func deleteFunction(deleteMethod string, awsConfig config.Config, ebService elasticbeanstalk.ElasticBeanstalk) {
switch deleteMethod {
case "delete application":
if utils.VerifyParamatersWithOr(map[string]string{"Application Name": *environmentApplicationNameArg}) {
if utils.VerifyParamatersWithAnd(true, map[string]string{"Application Name": *environmentApplicationNameArg}) {
ebService.DeleteApplication(*environmentApplicationNameArg)
}
case "delete environment":
if utils.VerifyParamatersWithOr(map[string]string{"Application Name": *environmentApplicationNameArg, "Environment Name": *environmentNameArg, "Tier": *environmentTierArg}) {
if utils.VerifyParamatersWithAnd(true, map[string]string{"Application Name": *environmentApplicationNameArg, "Environment Name": *environmentNameArg, "Tier": *environmentTierArg}) {
cfServcie := cloudformation.New(awsConfig)
cfServcie.DeleteStack(fmt.Sprintf("%s-%s-%s", *environmentApplicationNameArg, *environmentNameArg, *environmentTierArg))
}
Expand All @@ -203,11 +203,11 @@ func updateFunction(updateMethod string, awsConfig config.Config, ebService elas

switch updateMethod {
case "update environment":
if !utils.VerifyParamatersWithOr(map[string]string{"Application Name": *environmentApplicationNameArg, "Environment Name": *environmentNameArg, "Tier": *environmentTierArg}) {
if !utils.VerifyParamatersWithAnd(true, map[string]string{"Application Name": *environmentApplicationNameArg, "Environment Name": *environmentNameArg, "Tier": *environmentTierArg}) {
return
}

if !utils.VerifyParamatersWithAnd(map[string]string{"Configuration File": *environmentConfigArg, "Version": *environmentVersionArg}) {
if !utils.VerifyParamatersWithOr(false, map[string]string{"Configuration File": *environmentConfigArg, "Version": *environmentVersionArg}) {
return
}

Expand Down Expand Up @@ -248,14 +248,14 @@ func updateFunction(updateMethod string, awsConfig config.Config, ebService elas

func upsertFunction(updateMethod string, awsConfig config.Config, ebService elasticbeanstalk.ElasticBeanstalk, s3Service s3.S3) {
if !ebService.ApplicationExists() {
fmt.Println("App DOES NOT exists")
fmt.Println("App DOES NOT exist.. creating")
createFunction("create application", awsConfig, ebService, s3Service)
}

if ebService.EnvironmentExists() {
updateFunction("update environment", awsConfig, ebService, s3Service)
} else {
fmt.Println("Env DOES NOT exists")
fmt.Println("Env DOES NOT exist..creating")
createFunction("create environment", awsConfig, ebService, s3Service)
}
}
Expand All @@ -266,11 +266,11 @@ func main() {

parsedArg := kingpin.Parse()

if !utils.VerifyParamatersWithOr(map[string]string{"AWS Region": *awsRegion}) {
if !utils.VerifyParamatersWithAnd(true, map[string]string{"AWS Region": *awsRegion}) {
return
}

if !utils.VerifyParamatersWithOr(map[string]string{"Aws Profile": *awsProfile}) && !utils.VerifyParamatersWithAnd(map[string]string{"AWS Access Key ID": *awsAccessKeyID, "Aws Secret Access Key": *awsSecretAccessKey}) {
if !utils.VerifyParamatersWithOr(false, map[string]string{"Aws Profile": *awsProfile}) && !utils.VerifyParamatersWithAnd(false, map[string]string{"AWS Access Key ID": *awsAccessKeyID, "Aws Secret Access Key": *awsSecretAccessKey}) {
return
}

Expand Down
9 changes: 5 additions & 4 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

if [ -n "$VOLUME_PATH" ]; then
echo "Sourcing any .env files in $VOLUME_PATH"
source $VOLUME_PATH/*.env
if ls $VOLUME_PATH/*.env > /dev/null 2>&1; then
echo "Sourcing any .env files in $VOLUME_PATH"
source $VOLUME_PATH/*.env
fi
fi

go-deploy -v upsert environment
go-deploy -v upsert

0 comments on commit d792539

Please sign in to comment.