diff --git a/pkg/cmd/deploy/deploy.go b/pkg/cmd/deploy/deploy.go index 9a69120ae..d4953eb71 100644 --- a/pkg/cmd/deploy/deploy.go +++ b/pkg/cmd/deploy/deploy.go @@ -48,7 +48,7 @@ type DeployCmd struct { VersionID func() string CallScript func(token string, id string, secret string, prefix string, name string, cmd *DeployCmd) (string, error) OpenBrowser func(f *cmdutil.Factory, urlConsoleDeploy string, cmd *DeployCmd) error - CaptureLogs func(execId string, token string, cmd *DeployCmd) (string, error) + CaptureLogs func(execId string, token string, cmd *DeployCmd) error CheckToken func(f *cmdutil.Factory) error ReadSettings func() (token.Settings, error) UploadFiles func(f *cmdutil.Factory, conf *contracts.AzionApplicationOptions, msgs *[]string, pathStatic, bucket string, cmd *DeployCmd) error @@ -221,15 +221,21 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error { return err } - url, err := cmd.CaptureLogs(id, settings.Token, cmd) + err = cmd.CaptureLogs(id, settings.Token, cmd) if err != nil { return err } + conf, err = cmd.GetAzionJsonContent(ProjectConf) + if err != nil { + logger.Debug("Failed to get Azion JSON content", zap.Error(err)) + return err + } + logger.FInfoFlags(cmd.F.IOStreams.Out, msg.DeploySuccessful, f.Format, f.Out) msgs = append(msgs, msg.DeploySuccessful) - msgfOutputDomainSuccess := fmt.Sprintf(msg.DeployOutputDomainSuccess, url) + msgfOutputDomainSuccess := fmt.Sprintf(msg.DeployOutputDomainSuccess, conf.Domain.Url) logger.FInfoFlags(cmd.F.IOStreams.Out, msgfOutputDomainSuccess, f.Format, f.Out) msgs = append(msgs, msgfOutputDomainSuccess) @@ -239,7 +245,7 @@ func (cmd *DeployCmd) Run(f *cmdutil.Factory) error { return nil } -func captureLogs(execId, token string, cmd *DeployCmd) (string, error) { +func captureLogs(execId, token string, cmd *DeployCmd) error { logsURL := fmt.Sprintf("%s/api/script-runner/executions/%s/logs", DeployURL, execId) resultsURL := fmt.Sprintf("%s/api/script-runner/executions/%s/results", DeployURL, execId) @@ -253,7 +259,7 @@ func captureLogs(execId, token string, cmd *DeployCmd) (string, error) { req, err := http.NewRequest("GET", logsURL, bytes.NewBuffer([]byte{})) if err != nil { logger.Debug("Error creating request", zap.Error(err)) - return "", err + return err } // Set headers @@ -268,19 +274,19 @@ func captureLogs(execId, token string, cmd *DeployCmd) (string, error) { resp, err := client.Do(req) if err != nil { logger.Debug("Error sending request", zap.Error(err)) - return "", err + return err } defer resp.Body.Close() // Read the response body, err := io.ReadAll(resp.Body) if err != nil { - return "", err + return err } if err := cmd.Unmarshal(body, &Logs); err != nil { logger.Debug("Error unmarshalling response", zap.Error(err)) - return "", err + return err } switch Logs.Status { @@ -292,7 +298,7 @@ func captureLogs(execId, token string, cmd *DeployCmd) (string, error) { requestResults, err := http.NewRequest("GET", resultsURL, bytes.NewBuffer([]byte{})) if err != nil { logger.Debug("Error creating request", zap.Error(err)) - return "", err + return err } // Set headers @@ -306,36 +312,36 @@ func captureLogs(execId, token string, cmd *DeployCmd) (string, error) { respResults, err := clientResults.Do(requestResults) if err != nil { logger.Debug("Error sending request", zap.Error(err)) - return "", err + return err } defer respResults.Body.Close() // Read the response body, err := io.ReadAll(respResults.Body) if err != nil { - return "", err + return err } if err := cmd.Unmarshal(body, &Result); err != nil { logger.Debug("Error unmarshalling response", zap.Error(err)) - return "", err + return err } if Result.Result.Errors != nil { - return "", errors.New(Result.Result.Errors.Stack) //TODO: add mensagem que deu ruim e é para verificar se criou algo na conta + return errors.New(Result.Result.Errors.Stack) //TODO: add mensagem que deu ruim e é para verificar se criou algo na conta } err = cmd.WriteAzionJsonContent(Result.Result.Azion, ProjectConf) if err != nil { - return "", err + return err } default: s.Stop() - return "", msg.ErrorDeployRemote + return msg.ErrorDeployRemote } s.Stop() break } - return Result.Result.Azion.Domain.Url, nil + return nil } diff --git a/pkg/cmd/deploy/deploy_test.go b/pkg/cmd/deploy/deploy_test.go index b513505ef..681876fa3 100644 --- a/pkg/cmd/deploy/deploy_test.go +++ b/pkg/cmd/deploy/deploy_test.go @@ -97,8 +97,8 @@ func MockOpenBrowser(f *cmdutil.Factory, urlConsoleDeploy string, cmd *DeployCmd } // MockCaptureLogs mocks captureLogs behavior -func MockCaptureLogs(execId string, token string, cmd *DeployCmd) (string, error) { - return "", nil +func MockCaptureLogs(execId string, token string, cmd *DeployCmd) error { + return nil } func TestDeploy_Run(t *testing.T) { @@ -269,7 +269,7 @@ func TestCaptureLogs(t *testing.T) { cmd.WriteAzionJsonContent = func(conf *contracts.AzionApplicationOptions, confConf string) error { return nil } - _, err := cmd.CaptureLogs(execID, token, cmd) + err := cmd.CaptureLogs(execID, token, cmd) // Check for expected error if tt.expectError {