Skip to content

Commit

Permalink
PatchEnvelopes: add artifactMetaData field to binary artifacts
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
uncleDecart committed Oct 18, 2023
1 parent e0c530d commit 26f847f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
9 changes: 5 additions & 4 deletions pkg/pillar/cmd/zedagent/parseconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/pillar/cmd/zedagent/parsepatchenvelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
}
Expand Down
9 changes: 5 additions & 4 deletions pkg/pillar/cmd/zedrouter/patchenvelopes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 12 additions & 6 deletions pkg/pillar/types/patchenvelopestypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"`
}
11 changes: 6 additions & 5 deletions pkg/pillar/utils/patchenvelopesutils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := "./"
Expand Down

0 comments on commit 26f847f

Please sign in to comment.