From 26f847fb3567e1d619a9e412bf0912705ab4a56d Mon Sep 17 00:00:00 2001 From: Pavel Abramov Date: Thu, 12 Oct 2023 09:44:46 +0200 Subject: [PATCH] PatchEnvelopes: add artifactMetaData field to binary artifacts There are two fileds describing metadata for binary artifact in patchEnvelope: artifactMetaData and fileMetadata. Former is used to describe generic information such as user information, description of binary artifact etc., latter is used to store information regarding file itself, i.e. env variables, cli arguments, etc. Signed-off-by: Pavel Abramov --- pkg/pillar/cmd/zedagent/parseconfig_test.go | 9 +++++---- pkg/pillar/cmd/zedagent/parsepatchenvelopes.go | 2 ++ pkg/pillar/cmd/zedrouter/patchenvelopes.go | 9 +++++---- pkg/pillar/types/patchenvelopestypes.go | 18 ++++++++++++------ pkg/pillar/utils/patchenvelopesutils_test.go | 11 ++++++----- 5 files changed, 30 insertions(+), 19 deletions(-) diff --git a/pkg/pillar/cmd/zedagent/parseconfig_test.go b/pkg/pillar/cmd/zedagent/parseconfig_test.go index b28e51c5bdb..46e39832f6d 100644 --- a/pkg/pillar/cmd/zedagent/parseconfig_test.go +++ b/pkg/pillar/cmd/zedagent/parseconfig_test.go @@ -1326,10 +1326,11 @@ func TestParsePatchEnvelope(t *testing.T) { AllowedApps: []string{appU1, appU2}, BinaryBlobs: []types.BinaryBlobCompleted{ { - FileName: inlineFileName, - FileSha: hex.EncodeToString(shaBytes[:]), - FileMetadata: fileMetadata, - URL: filepath.Join(persistCacheFolder, inlineFileName), + FileName: inlineFileName, + FileSha: hex.EncodeToString(shaBytes[:]), + FileMetadata: fileMetadata, + ArtifactMetadata: artiactMetadata, + URL: filepath.Join(persistCacheFolder, inlineFileName), }, }, }, diff --git a/pkg/pillar/cmd/zedagent/parsepatchenvelopes.go b/pkg/pillar/cmd/zedagent/parsepatchenvelopes.go index 9abf1d21023..7de80920af7 100644 --- a/pkg/pillar/cmd/zedagent/parsepatchenvelopes.go +++ b/pkg/pillar/cmd/zedagent/parsepatchenvelopes.go @@ -94,6 +94,7 @@ func addBinaryBlobToPatchEnvelope(pe *types.PatchEnvelopeInfo, artifact *zconfig if err != nil { return err } + volumeRef.ArtifactMetadata = artifact.GetArtifactMetaData() pe.VolumeRefs = append(pe.VolumeRefs, *volumeRef) return nil case zconfig.EVE_OPAQUE_OBJECT_CATEGORY_SECRET: @@ -106,6 +107,7 @@ func addBinaryBlobToPatchEnvelope(pe *types.PatchEnvelopeInfo, artifact *zconfig if err != nil { return err } + binaryBlob.ArtifactMetadata = artifact.GetArtifactMetaData() pe.BinaryBlobs = append(pe.BinaryBlobs, *binaryBlob) return nil } diff --git a/pkg/pillar/cmd/zedrouter/patchenvelopes.go b/pkg/pillar/cmd/zedrouter/patchenvelopes.go index 17e40145d14..a2fca2940e9 100644 --- a/pkg/pillar/cmd/zedrouter/patchenvelopes.go +++ b/pkg/pillar/cmd/zedrouter/patchenvelopes.go @@ -201,10 +201,11 @@ func blobFromVolRef(vr types.BinaryBlobVolumeRef, vs types.VolumeStatus) (*types return nil, err } return &types.BinaryBlobCompleted{ - FileName: vr.FileName, - FileMetadata: vr.FileMetadata, - FileSha: fmt.Sprintf("%x", sha), - URL: vs.FileLocation, + FileName: vr.FileName, + FileMetadata: vr.FileMetadata, + ArtifactMetadata: vr.ArtifactMetadata, + FileSha: fmt.Sprintf("%x", sha), + URL: vs.FileLocation, }, nil } diff --git a/pkg/pillar/types/patchenvelopestypes.go b/pkg/pillar/types/patchenvelopestypes.go index 9507b3cc231..17e67511d3e 100644 --- a/pkg/pillar/types/patchenvelopestypes.go +++ b/pkg/pillar/types/patchenvelopestypes.go @@ -54,10 +54,13 @@ func (pe *PatchEnvelopeInfoList) FindPatchEnvelopeByID(patchID string) *PatchEnv // BinaryBlobCompleted is representation of // binary blob ready to be downloaded by app instance type BinaryBlobCompleted struct { - FileName string `json:"fileName"` - FileSha string `json:"fileSha"` + FileName string `json:"fileName"` + FileSha string `json:"fileSha"` + // FileMetadata is related to file, i.e. env variables, cli arguments FileMetadata string `json:"fileMetaData"` - URL string `json:"url"` //nolint:var-naming + // ArtifactMetadata is generic info i.e. user info, desc etc. + ArtifactMetadata string `json:"artifactMetaData"` + URL string `json:"url"` //nolint:var-naming } // CompletedBinaryBlobIdxByName returns index of element in blobs list @@ -75,8 +78,11 @@ func CompletedBinaryBlobIdxByName(blobs []BinaryBlobCompleted, name string) int // external binary blobs, which has not yet been // downloaded type BinaryBlobVolumeRef struct { - FileName string `json:"fileName"` - ImageName string `json:"imageName"` + FileName string `json:"fileName"` + ImageName string `json:"imageName"` + // FileMetadata is related to file, i.e. env variables, cli arguments FileMetadata string `json:"fileMetaData"` - ImageID string `json:"imageId"` + // ArtifactMetadata is generic info i.e. user info, desc etc. + ArtifactMetadata string `json:"artifactMetaData"` + ImageID string `json:"imageId"` } diff --git a/pkg/pillar/utils/patchenvelopesutils_test.go b/pkg/pillar/utils/patchenvelopesutils_test.go index 33c5a406453..cddf2a0a3e9 100644 --- a/pkg/pillar/utils/patchenvelopesutils_test.go +++ b/pkg/pillar/utils/patchenvelopesutils_test.go @@ -29,17 +29,18 @@ func TestGetZipArchive(t *testing.T) { AllowedApps: []string{uuidString}, BinaryBlobs: []types.BinaryBlobCompleted{ { - FileName: "TestFileName", - FileSha: "TestFileSha", - FileMetadata: "TestFileMetadata", - URL: "./testurl", + FileName: "TestFileName", + FileSha: "TestFileSha", + ArtifactMetadata: "TestArtifactMetadata", + FileMetadata: "TestFileMetadata", + URL: "./testurl", }, }, } 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})) // Test GetZipArchive root := "./"