From 5cf5e453559097211d373b7388d68db3a5fadd27 Mon Sep 17 00:00:00 2001 From: Joshua Marsh Date: Wed, 16 Oct 2019 17:03:59 -0500 Subject: [PATCH] Cleaner command output --- cmd/system.go | 10 ---------- internal/util/api.go | 1 - pkg/service/accounts.go | 24 +++++++++++------------- pkg/service/deploy.go | 8 ++++---- pkg/service/init.go | 6 +++--- pkg/service/leases.go | 23 +++++++++++++---------- 6 files changed, 31 insertions(+), 41 deletions(-) diff --git a/cmd/system.go b/cmd/system.go index a077332..b0dfc18 100644 --- a/cmd/system.go +++ b/cmd/system.go @@ -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) - // }, } /* diff --git a/internal/util/api.go b/internal/util/api.go index 0455301..ba87c61 100644 --- a/internal/util/api.go +++ b/internal/util/api.go @@ -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") diff --git a/pkg/service/accounts.go b/pkg/service/accounts.go index ee5047d..8a08fc2 100644 --- a/pkg/service/accounts.go +++ b/pkg/service/accounts.go @@ -1,8 +1,7 @@ package service import ( - "fmt" - "io/ioutil" + "log" "github.com/Optum/dce-cli/configs" "github.com/Optum/dce-cli/internal/util" @@ -23,9 +22,6 @@ 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, @@ -33,22 +29,24 @@ func (s *AccountsService) AddAccount(accountID, adminRoleARN string) { 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) + } } diff --git a/pkg/service/deploy.go b/pkg/service/deploy.go index 2f7db06..7a60042 100644 --- a/pkg/service/deploy.go +++ b/pkg/service/deploy.go @@ -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") @@ -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 { @@ -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) diff --git a/pkg/service/init.go b/pkg/service/init.go index 0c6a91b..7e27dc7 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -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 } diff --git a/pkg/service/leases.go b/pkg/service/leases.go index d226b5b..4d6cc83 100644 --- a/pkg/service/leases.go +++ b/pkg/service/leases.go @@ -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", @@ -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) { @@ -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", @@ -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) {