Skip to content

Commit

Permalink
PatchEnvelopes: URL exposed to app instance reflects API
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Abramov <[email protected]>
  • Loading branch information
uncleDecart committed Oct 12, 2023
1 parent 8dfd714 commit 4769bf7
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 5 additions & 1 deletion pkg/pillar/cmd/zedrouter/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const SignerMaxSize = 65535
// DiagMaxSize is the max returned size for diag
const DiagMaxSize = 65535

// PatchEnvelopeHandler is route used for patch envelopes
// it is used in URL composing of patch envelopes
const PatchEnvelopeHandler = "/eve/v1/patch/"

func (z *zedrouter) makeMetadataHandler() http.Handler {
r := chi.NewRouter()

Expand Down Expand Up @@ -87,7 +91,7 @@ func (z *zedrouter) makeMetadataHandler() http.Handler {
diagHandler := &diagHandler{zedrouter: z}
r.Get("/eve/v1/diag", diagHandler.ServeHTTP)

r.Route("/eve/v1/patch/", func(r chi.Router) {
r.Route(PatchEnvelopeHandler, func(r chi.Router) {

Check warning on line 94 in pkg/pillar/cmd/zedrouter/metadata.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/zedrouter/metadata.go#L94

Added line #L94 was not covered by tests
r.Use(WithPatchEnvelopesByIP(z))

r.Get("/description.json", HandlePatchDescription(z))
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/cmd/zedrouter/metadata_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ func HandlePatchDescription(z *zedrouter) func(http.ResponseWriter, *http.Reques
// WithPatchEnvelopesByIP middleware returns envelopes which are more than 0
envelopes := r.Context().Value(patchEnvelopesContextKey).(types.PatchEnvelopeInfoList)

Check warning on line 584 in pkg/pillar/cmd/zedrouter/metadata_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/zedrouter/metadata_handlers.go#L584

Added line #L584 was not covered by tests

b, err := PatchEnvelopesJSONForAppInstance(envelopes)
b, err := patchEnvelopesJSONFOrAppInstance(envelopes)

Check warning on line 586 in pkg/pillar/cmd/zedrouter/metadata_handlers.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/zedrouter/metadata_handlers.go#L586

Added line #L586 was not covered by tests
if err != nil {
http.Error(w, err.Error(), http.StatusUnprocessableEntity)
return
Expand Down
21 changes: 18 additions & 3 deletions pkg/pillar/cmd/zedrouter/patchenvelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,30 @@ type peInfoToDisplay struct {
VolumeRefs []types.BinaryBlobVolumeRef
}

// PatchEnvelopesJSONForAppInstance returns json representation
const metadataIP = "169.254.169.254"

// patchEnvelopesJSONFOrAppInstance returns json representation
// of Patch Envelopes list which are shown to app instances
func PatchEnvelopesJSONForAppInstance(pe types.PatchEnvelopeInfoList) ([]byte, error) {
func patchEnvelopesJSONFOrAppInstance(pe types.PatchEnvelopeInfoList) ([]byte, error) {
toDisplay := make([]peInfoToDisplay, len(pe.Envelopes))

for i, envelope := range pe.Envelopes {

var binaryBlobs []types.BinaryBlobCompleted
binaryBlobs = nil
if envelope.BinaryBlobs != nil {
binaryBlobs = make([]types.BinaryBlobCompleted, len(envelope.BinaryBlobs))
copy(binaryBlobs, envelope.BinaryBlobs)
}

Check warning on line 218 in pkg/pillar/cmd/zedrouter/patchenvelopes.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/zedrouter/patchenvelopes.go#L208-L218

Added lines #L208 - L218 were not covered by tests

for j := range binaryBlobs {
url := fmt.Sprintf("http://%s%sdownload/%s/%s", metadataIP, PatchEnvelopeHandler, envelope.PatchID, binaryBlobs[j].FileName)
binaryBlobs[j].URL = url
}

Check warning on line 223 in pkg/pillar/cmd/zedrouter/patchenvelopes.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/zedrouter/patchenvelopes.go#L220-L223

Added lines #L220 - L223 were not covered by tests

toDisplay[i] = peInfoToDisplay{
PatchID: envelope.PatchID,
BinaryBlobs: envelope.BinaryBlobs,
BinaryBlobs: binaryBlobs,
VolumeRefs: envelope.VolumeRefs,
}

Check warning on line 229 in pkg/pillar/cmd/zedrouter/patchenvelopes.go

View check run for this annotation

Codecov / codecov/patch

pkg/pillar/cmd/zedrouter/patchenvelopes.go#L225-L229

Added lines #L225 - L229 were not covered by tests
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/pillar/types/patchenvelopestypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestPatchEnvelopeInfoList(t *testing.T) {

pe.Envelopes = append(pe.Envelopes, peInfo)

g.Expect(pe.Get(uuidString)).To(gomega.BeEquivalentTo([]types.PatchEnvelopeInfo{peInfo}))
g.Expect(pe.Get(uuidString).Envelopes).To(gomega.BeEquivalentTo([]types.PatchEnvelopeInfo{peInfo}))
}

func TestFindPatchEnvelopeById(t *testing.T) {
Expand Down

0 comments on commit 4769bf7

Please sign in to comment.