Skip to content

Commit

Permalink
bundle_logs action returns SHA512 of log tarball
Browse files Browse the repository at this point in the history
Authored-by: Chris Selzo <cselzo@vmware.com>
  • Loading branch information
selzoc committed Feb 28, 2023
1 parent aae8427 commit 046488e
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 10 deletions.
11 changes: 9 additions & 2 deletions agent/action/bundle_logs.go
Expand Up @@ -3,6 +3,7 @@ package action
import (
"errors"

boshcrypto "github.com/cloudfoundry/bosh-utils/crypto"
boshsys "github.com/cloudfoundry/bosh-utils/system"

"github.com/cloudfoundry/bosh-agent/agent/logstarprovider"
Expand All @@ -21,7 +22,8 @@ type BundleLogsRequest struct {
}

type BundleLogsResponse struct {
LogsTarPath string `json:"logs_tar_path"`
LogsTarPath string `json:"logs_tar_path"`
SHA512Digest string `json:"sha512"`
}

func NewBundleLogs(
Expand Down Expand Up @@ -58,7 +60,12 @@ func (a BundleLogsAction) Run(request BundleLogsRequest) (BundleLogsResponse, er
}
}

return BundleLogsResponse{LogsTarPath: tarball}, nil
digest, err := boshcrypto.NewMultipleDigestFromPath(tarball, a.fs, []boshcrypto.Algorithm{boshcrypto.DigestAlgorithmSHA512})
if err != nil {
return BundleLogsResponse{}, err
}

return BundleLogsResponse{LogsTarPath: tarball, SHA512Digest: digest.String()}, nil
}

func (a BundleLogsAction) Resume() (interface{}, error) {
Expand Down
5 changes: 3 additions & 2 deletions agent/action/bundle_logs_test.go
Expand Up @@ -57,14 +57,15 @@ var _ = Describe("FetchLogsAction", func() {
Expect(logsTarProvider.CleanUpCallCount()).To(BeZero())
})

It("returns the expected logs tarball path", func() {
It("returns the expected logs tarball path and sha512", func() {
logsTarProvider.GetReturns("/tmp/logsinhere.tgz", nil)

request := BundleLogsRequest{LogType: "job", Filters: []string{"foo", "bar"}}
logsPath, err := action.Run(request)
Expect(err).ToNot(HaveOccurred())

boshassert.MatchesJSONString(GinkgoT(), logsPath, `{"logs_tar_path":"/tmp/logsinhere.tgz"}`)
const emptyFileSHA512 string = "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
boshassert.MatchesJSONString(GinkgoT(), logsPath, `{"logs_tar_path":"/tmp/logsinhere.tgz","sha512":"sha512:`+emptyFileSHA512+`"}`)
})

Context("chowning", func() {
Expand Down
3 changes: 2 additions & 1 deletion agentclient/agent_client_interface.go
Expand Up @@ -51,5 +51,6 @@ type SSHResult struct {
}

type BundleLogsResult struct {
LogsTarPath string
LogsTarPath string
SHA512Digest string
}
8 changes: 5 additions & 3 deletions agentclient/http/agent_client.go
Expand Up @@ -5,12 +5,13 @@ import (
"strings"
"time"

"github.com/cloudfoundry/bosh-agent/agentclient"
"github.com/cloudfoundry/bosh-agent/agentclient/applyspec"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
"github.com/cloudfoundry/bosh-utils/httpclient"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshretry "github.com/cloudfoundry/bosh-utils/retrystrategy"

"github.com/cloudfoundry/bosh-agent/agentclient"
"github.com/cloudfoundry/bosh-agent/agentclient/applyspec"
)

type AgentClient struct {
Expand Down Expand Up @@ -204,7 +205,8 @@ func (c *AgentClient) BundleLogs(owningUser string, logType string, filters []st
}

return agentclient.BundleLogsResult{
LogsTarPath: response.Value.LogsTarPath,
LogsTarPath: response.Value.LogsTarPath,
SHA512Digest: response.Value.SHA512Digest,
}, nil
}

Expand Down
3 changes: 2 additions & 1 deletion agentclient/http/agent_client_test.go
Expand Up @@ -1203,7 +1203,7 @@ var _ = Describe("AgentClient", func() {
BeforeEach(func() {
server.AppendHandlers(ghttp.CombineHandlers(
ghttp.VerifyRequest("POST", "/agent"),
ghttp.RespondWith(200, `{"value": {"logs_tar_path":"/tmp/good-logs-here.tgz"}}`),
ghttp.RespondWith(200, `{"value": {"logs_tar_path":"/tmp/good-logs-here.tgz","sha512":"goodSHA"}}`),
ghttp.VerifyJSONRepresenting(AgentRequestMessage{
Method: "bundle_logs",
Arguments: []interface{}{
Expand All @@ -1228,6 +1228,7 @@ var _ = Describe("AgentClient", func() {
responseValue, err := agentClient.BundleLogs("bosh-user", "job", []string{"foo", "bar"})
Expect(err).ToNot(HaveOccurred())
Expect(responseValue.LogsTarPath).To(Equal("/tmp/good-logs-here.tgz"))
Expect(responseValue.SHA512Digest).To(Equal("goodSHA"))
})
})

Expand Down
3 changes: 2 additions & 1 deletion agentclient/http/agent_response.go
Expand Up @@ -203,5 +203,6 @@ func (r *BundleLogsResponse) Unmarshal(message []byte) error {
}

type BundleLogsState struct {
LogsTarPath string `json:"logs_tar_path"`
LogsTarPath string `json:"logs_tar_path"`
SHA512Digest string `json:"sha512"`
}

0 comments on commit 046488e

Please sign in to comment.