Skip to content

Commit

Permalink
add fix for upload
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun committed Sep 4, 2024
1 parent ee6ee64 commit fe2cca8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion internal/exec/describe_affected.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func ExecuteDescribeAffectedCmd(cmd *cobra.Command, args []string) error {
}
}

a.Logger.Trace(fmt.Sprintf("\nAffected components and stacks: \n"))
a.Logger.Trace("\nAffected components and stacks: \n")

err = printOrWriteToFile(a.Format, a.OutputFile, affected)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/exec/describe_affected_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func ExecuteDescribeAffectedWithTargetRefCheckout(
return nil, nil, nil, "", err
}

return affected, localRepoHead, remoteRepoHead, localRepoInfo.LocalRepoPath, nil
return affected, localRepoHead, remoteRepoHead, localRepoInfo.RepoUrl, nil
}

// ExecuteDescribeAffectedWithTargetRepoPath uses `repo-path` to access the target repo, and processes stack configs
Expand Down
17 changes: 9 additions & 8 deletions pkg/pro/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

cfg "github.com/cloudposse/atmos/pkg/config"
"github.com/cloudposse/atmos/pkg/logger"
"github.com/cloudposse/atmos/pkg/utils"
)

// AtmosProAPIClient represents the client to interact with the AtmosPro API
Expand Down Expand Up @@ -69,12 +70,12 @@ func getAuthenticatedRequest(c *AtmosProAPIClient, method, url string, body io.R
func (c *AtmosProAPIClient) UploadAffectedStacks(dto AffectedStacksUploadRequest) error {
url := fmt.Sprintf("%s/%s/affected-stacks", c.BaseURL, c.BaseAPIEndpoint)

data, err := json.Marshal(dto)
data, err := utils.ConvertToJSON(dto)
if err != nil {
return fmt.Errorf("failed to marshal payload: %w", err)
}

req, err := getAuthenticatedRequest(c, "POST", url, bytes.NewBuffer(data))
req, err := getAuthenticatedRequest(c, "POST", url, bytes.NewBuffer([]byte(data)))
if err != nil {
return fmt.Errorf("failed to create authenticated request: %w", err)
}
Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *AtmosProAPIClient) LockStack(dto LockStackRequest) (LockStackResponse,

body, err := io.ReadAll(resp.Body)
if err != nil {
return LockStackResponse{}, fmt.Errorf("Error reading response body: %s", err)
return LockStackResponse{}, fmt.Errorf("error reading response body: %s", err)
}

// Create an instance of the struct
Expand All @@ -127,7 +128,7 @@ func (c *AtmosProAPIClient) LockStack(dto LockStackRequest) (LockStackResponse,
// Unmarshal the JSON response into the struct
err = json.Unmarshal(body, &responseData)
if err != nil {
return LockStackResponse{}, fmt.Errorf("Error unmarshaling JSON: %s", err)
return LockStackResponse{}, fmt.Errorf("error unmarshaling JSON: %s", err)
}

if !responseData.Success {
Expand All @@ -136,7 +137,7 @@ func (c *AtmosProAPIClient) LockStack(dto LockStackRequest) (LockStackResponse,
context += fmt.Sprintf(" %s: %v\n", key, value)
}

return LockStackResponse{}, fmt.Errorf("An error occurred while attempting to lock stack.\n\nError: %s\nContext:\n%s", responseData.ErrorMessage, context)
return LockStackResponse{}, fmt.Errorf("an error occurred while attempting to lock stack.\n\nError: %s\nContext:\n%s", responseData.ErrorMessage, context)
}

return responseData, nil
Expand Down Expand Up @@ -165,7 +166,7 @@ func (c *AtmosProAPIClient) UnlockStack(dto UnlockStackRequest) (UnlockStackResp

body, err := io.ReadAll(resp.Body)
if err != nil {
return UnlockStackResponse{}, fmt.Errorf("Error reading response body: %s", err)
return UnlockStackResponse{}, fmt.Errorf("error reading response body: %s", err)
}

// Create an instance of the struct
Expand All @@ -175,7 +176,7 @@ func (c *AtmosProAPIClient) UnlockStack(dto UnlockStackRequest) (UnlockStackResp
err = json.Unmarshal(body, &responseData)

if err != nil {
return UnlockStackResponse{}, fmt.Errorf("Error unmarshaling JSON: %s", err)
return UnlockStackResponse{}, fmt.Errorf("error unmarshaling JSON: %s", err)
}

if !responseData.Success {
Expand All @@ -184,7 +185,7 @@ func (c *AtmosProAPIClient) UnlockStack(dto UnlockStackRequest) (UnlockStackResp
context += fmt.Sprintf(" %s: %v\n", key, value)
}

return UnlockStackResponse{}, fmt.Errorf("An error occurred while attempting to lock stack.\n\nError: %s\nContext:\n%s", responseData.ErrorMessage, context)
return UnlockStackResponse{}, fmt.Errorf("an error occurred while attempting to unlock stack.\n\nError: %s\nContext:\n%s", responseData.ErrorMessage, context)
}

return responseData, nil
Expand Down
10 changes: 9 additions & 1 deletion pkg/utils/json_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package utils

import (
"bytes"
"encoding/json"
"os"
"strings"
Expand All @@ -16,7 +17,14 @@ func PrintAsJSON(data any) error {
if err != nil {
return err
}
PrintMessage(j)

var prettyJSON bytes.Buffer
err = json.Indent(&prettyJSON, []byte(j), "", " ")
if err != nil {
return err
}

PrintMessage(prettyJSON.String())
return nil
}

Expand Down
8 changes: 1 addition & 7 deletions pkg/utils/log_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,7 @@ func LogError(err error) {
}

// Print stack trace
stackTrace := debug.Stack()
_, stackErr := c.Fprintln(color.Error, "Stack trace:\n"+string(stackTrace))
if stackErr != nil {
color.Red("Error printing stack trace:")
color.Red("%s\n", stackErr)
}

debug.PrintStack()
}
}

Expand Down

0 comments on commit fe2cca8

Please sign in to comment.