Skip to content

Commit

Permalink
Cleaner command output
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmarsh committed Oct 16, 2019
1 parent 7414b23 commit 5cf5e45
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 41 deletions.
10 changes: 0 additions & 10 deletions cmd/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,6 @@ func init() {
var systemCmd = &cobra.Command{
Use: "system",
Short: "Deploy and configure the DCE system",
// PersistentPreRun: func(cmd *cobra.Command, args []string) {
// // Configure util for this command to use master account credentials
// var creds = credentials.NewStaticCredentials(
// *config.System.MasterAccount.Credentials.AwsAccessKeyID,
// *config.System.MasterAccount.Credentials.AwsSecretAccessKey,
// *config.System.MasterAccount.Credentials.AwsSecretAccessKey,
// )

// service.Util = utl.New(config, creds)
// },
}

/*
Expand Down
1 change: 0 additions & 1 deletion internal/util/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ func (u *APIUtil) Request(input *ApiRequestInput) *ApiResponse {
if input.Json != nil {

payload, err := json.Marshal(input.Json)
fmt.Println("Marshalled Payload: ", string(payload))

if err != nil {
fmt.Println("Error marshaling json payload")
Expand Down
24 changes: 11 additions & 13 deletions pkg/service/accounts.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package service

import (
"fmt"
"io/ioutil"
"log"

"github.com/Optum/dce-cli/configs"
"github.com/Optum/dce-cli/internal/util"
Expand All @@ -23,32 +22,31 @@ func (s *AccountsService) AddAccount(accountID, adminRoleARN string) {
}

accountsFullURL := *s.Config.API.BaseURL + accountsPath
fmt.Println("Posting to: ", accountsFullURL)
fmt.Println("Post body: ", requestBody)

response := s.Util.Request(&util.ApiRequestInput{
Method: "POST",
Url: accountsFullURL,
Region: *s.Config.Region,
Json: requestBody,
})

body, _ := ioutil.ReadAll(response.Body)
fmt.Println("Response: ", response)
fmt.Println("Response Body: ", body)
if response.StatusCode == 201 {
log.Println("Account added to DCE accounts pool")
} else {
log.Println("DCE Responded with an error: ", response)
}
}

func (s *AccountsService) RemoveAccount(accountID string) {
accountsFullURL := *s.Config.API.BaseURL + accountsPath + "/" + accountID
fmt.Println("Posting to: ", accountsFullURL)

response := s.Util.Request(&utl.ApiRequestInput{
Method: "DELETE",
Url: accountsFullURL,
Region: *s.Config.Region,
})

body, _ := ioutil.ReadAll(response.Body)
fmt.Println("Response: ", response)
fmt.Println("Response Body: ", body)
if response.StatusCode == 204 {
log.Println("Account removed from DCE accounts pool")
} else {
log.Println("DCE Responded with an error: ", response)
}
}
8 changes: 4 additions & 4 deletions pkg/service/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *DeployService) Deploy(namespace string) {
namespace = "dce-" + getRandString(6)
}

log.Println("Creating terraform remote state backend infrastructure")
// log.Println("Creating terraform remote state backend infrastructure")
stateBucket := s.createRemoteStateBackend(namespace)

log.Println("Creating DCE infrastructure")
Expand All @@ -46,7 +46,7 @@ func (s *DeployService) createRemoteStateBackend(namespace string) string {
defer os.RemoveAll(tmpDir)
defer os.Chdir(originDir)

log.Println("Creating terraform remote backend template (init.tf)")
// log.Println("Creating terraform remote backend template (init.tf)")
fileName := tmpDir + "/" + "init.tf"
err := ioutil.WriteFile(fileName, []byte(utl.RemoteBackend), 0644)
if err != nil {
Expand Down Expand Up @@ -126,12 +126,12 @@ func (s *DeployService) deployCodeAssets(deployNamespace string, artifactsBucket
}

func mvToTempDir(prefix string) (string, string) {
log.Println("Creating temporary working directory")
// log.Println("Creating temporary working directory")
destinationDir, err := ioutil.TempDir("", prefix)
if err != nil {
log.Fatalln(err)
}
log.Println(" -->" + destinationDir)
// log.Println(" -->" + destinationDir)
originDir, err := os.Getwd()
if err != nil {
log.Fatalln(err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ func promptUserForConfig() *configs.Root {

// System Config
config.System.Auth.LoginURL = promptBasic("Authentication URL (SSO)", nil)
config.System.MasterAccount.Credentials.AwsAccessKeyID = promptBasic("AWS ACCESS KEY ID of the DCE Master account (Leave blank if you are not a system admin)", nil)
config.System.MasterAccount.Credentials.AwsSecretAccessKey = promptBasic("AWS SECRET ACCESS KEY of the DCE Master account (Leave blank if you are not a system admin)", nil)
config.System.MasterAccount.Credentials.AwsAccessKeyID = promptBasic("AWS ACCESS KEY ID for the DCE Master account", nil)
config.System.MasterAccount.Credentials.AwsSecretAccessKey = promptBasic("AWS SECRET ACCESS KEY for the DCE Master account", nil)

// API Config
config.Region = promptSelect("What region is DCE deployed in?", configs.Regions)
config.API.BaseURL = promptBasic("What is the base url of the DCE API (example: https://abcde12345.execute-api.us-east-1.amazonaws.com/dev)?", nil)
config.API.Credentials.AwsAccessKeyID = promptBasic("AWS ACCESS KEY ID for accessing the DCE API. (This is usually obtained by running DCE auth. Leave blank to use AWS_ACCESS_KEY_ID env variable.)", nil)
config.API.Credentials.AwsSecretAccessKey = promptBasic("AWS SECRET ACCESS KEY for accessing the DCE API. (This is usually obtained by running DCE auth. Leave blank to use AWS_SECRET_ACCESS_KEY env variable.)", nil)
config.API.Credentials.AwsSessionToken = promptBasic("AWS SESSION TOKEN for accessing the DCE API. (This is usually obtained by running DCE auth. Leave blank to use AWS_SESSION_TOKEN env variable.)", nil)

config.GithubToken = promptBasic("Github token used to download releases from github. Leave blank to use GITHUB_TOKEN env variable.", nil)
config.Region = promptSelect("What region is DCE deployed in?", configs.Regions)
return &config
}

Expand Down
23 changes: 13 additions & 10 deletions pkg/service/leases.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ func (s *LeasesService) CreateLease(principleID string, budgetAmount float64, bu
}

leasesFullURL := *s.Config.API.BaseURL + LeasesPath
log.Println("Posting to: ", leasesFullURL)
log.Println("Post body: ", requestBody)
// log.Println("Posting to: ", leasesFullURL)
// log.Println("Post body: ", requestBody)

response := s.Util.Request(&utl.ApiRequestInput{
Method: "POST",
Expand All @@ -36,9 +36,12 @@ func (s *LeasesService) CreateLease(principleID string, budgetAmount float64, bu
Json: requestBody,
})

body, _ := ioutil.ReadAll(response.Body)
log.Println("Response: ", response)
log.Println("Response Body: ", body)
// body, _ := ioutil.ReadAll(response.Body)
if response.StatusCode == 201 {
log.Println("Lease created for jdoe99")
} else {
log.Println("DCE Responded with an error: ", response)
}
}

func (s *LeasesService) EndLease(accountID, principleID string) {
Expand All @@ -48,8 +51,6 @@ func (s *LeasesService) EndLease(accountID, principleID string) {
}

leasesFullURL := *s.Config.API.BaseURL + LeasesPath
log.Println("Posting to: ", leasesFullURL)
log.Println("Post body: ", requestBody)

response := s.Util.Request(&utl.ApiRequestInput{
Method: "DELETE",
Expand All @@ -58,9 +59,11 @@ func (s *LeasesService) EndLease(accountID, principleID string) {
Json: requestBody,
})

body, _ := ioutil.ReadAll(response.Body)
log.Println("Response: ", response)
log.Println("Response Body: ", body)
if response.StatusCode == 200 {
log.Println("Lease ended")
} else {
log.Println("DCE Responded with an error: ", response)
}
}

func (s *LeasesService) LoginToLease(loginAcctID, loginLeaseID string, loginOpenBrowser bool) {
Expand Down

0 comments on commit 5cf5e45

Please sign in to comment.