Skip to content

Commit

Permalink
Add extra metadata to catalog
Browse files Browse the repository at this point in the history
Adding the pack size to the catalog metadata to allow the information to be showed on the API response
  • Loading branch information
cjlapao committed Sep 10, 2024
1 parent 04d4743 commit 0c9b759
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/catalog/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ func (s *CatalogManifestService) GenerateManifestContent(ctx basecontext.ApiCont
}

manifest.Size = fileInfo.Size()
manifest.PackSize = fileInfo.Size()

ctx.LogInfof("Getting manifest package checksum for %v", r.CatalogId)
checksum, err := helpers.GetFileMD5Checksum(packFilePath)
Expand Down
1 change: 1 addition & 0 deletions src/catalog/models/pull_catalog_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ type PullCatalogManifestResponse struct {
LocalPath string `json:"local_path,omitempty"`
MachineName string `json:"machine_name,omitempty"`
Manifest *VirtualMachineCatalogManifest `json:"manifest,omitempty"`
LocalCachePath string `json:"local_cache_path,omitempty"`
CleanupRequest *cleanupservice.CleanupRequest `json:"-"`
Errors []error `json:"-"`
}
Expand Down
1 change: 1 addition & 0 deletions src/catalog/models/push_catalog_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type PushCatalogManifestRequest struct {
RequiredClaims []string `json:"required_claims,omitempty"`
Tags []string `json:"tags,omitempty"`
MinimumSpecRequirements MinimumSpecRequirement `json:"minimum_requirements,omitempty"`
PackSize int64 `json:"pack_size,omitempty"`
ProgressChannel chan int `json:"-"`
FileNameChannel chan string `json:"-"`
StepChannel chan string `json:"-"`
Expand Down
1 change: 1 addition & 0 deletions src/catalog/models/virtual_machine_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ type VirtualMachineCatalogManifest struct {
CompressedChecksum string `json:"compressed_checksum"`
VirtualMachineContents []VirtualMachineManifestContentItem `json:"virtual_machine_contents"`
PackContents []VirtualMachineManifestContentItem `json:"pack_contents"`
PackSize int64 `json:"pack_size,omitempty"`
Tainted bool `json:"tainted"`
TaintedBy string `json:"tainted_by"`
TaintedAt string `json:"tainted_at"`
Expand Down
4 changes: 4 additions & 0 deletions src/catalog/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,10 @@ func (s *CatalogManifestService) Pull(ctx basecontext.ApiContext, r *models.Pull
}
}

if cfg.IsCatalogCachingEnable() {
response.LocalCachePath = filepath.Join(destinationFolder, cacheMachineName)
}

systemSrv := serviceProvider.System
if r.Owner != "" && r.Owner != "root" {
if err := systemSrv.ChangeFileUserOwner(ctx, r.Owner, r.LocalMachineFolder); err != nil {
Expand Down
1 change: 1 addition & 0 deletions src/data/models/catalog_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type CatalogManifest struct {
DownloadCount int `json:"download_count"`
VirtualMachineContents []CatalogManifestContentItem `json:"virtual_machine_contents"`
PackContents []CatalogManifestContentItem `json:"pack_contents"`
PackSize int64 `json:"pack_size,omitempty"`
MinimumSpecRequirements *MinimumSpecRequirement `json:"minimum_requirements,omitempty"`
Tainted bool `json:"tainted"`
TaintedBy string `json:"tainted_by"`
Expand Down
5 changes: 5 additions & 0 deletions src/mappers/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func CatalogManifestToDto(m catalog_models.VirtualMachineCatalogManifest) data_m
LastDownloadedUser: m.LastDownloadedUser,
VirtualMachineContents: CatalogManifestContentItemsToDto(m.VirtualMachineContents),
PackContents: CatalogManifestContentItemsToDto(m.PackContents),
PackSize: m.PackSize,
Size: m.Size,
Tainted: m.Tainted,
TaintedBy: m.TaintedBy,
Expand Down Expand Up @@ -96,6 +97,7 @@ func DtoCatalogManifestToBase(m data_models.CatalogManifest) catalog_models.Virt
Size: m.Size,
VirtualMachineContents: DtoCatalogManifestContentItemsToBase(m.VirtualMachineContents),
PackContents: DtoCatalogManifestContentItemsToBase(m.PackContents),
PackSize: m.PackSize,
Tainted: m.Tainted,
TaintedBy: m.TaintedBy,
TaintedAt: m.TaintedAt,
Expand Down Expand Up @@ -224,6 +226,7 @@ func ApiCatalogManifestToDto(m models.CatalogManifest) data_models.CatalogManife
Revoked: m.Revoked,
RevokedAt: m.RevokedAt,
RevokedBy: m.RevokedBy,
PackSize: m.PackSize,
DownloadCount: m.DownloadCount,
}

Expand Down Expand Up @@ -271,6 +274,7 @@ func DtoCatalogManifestToApi(m data_models.CatalogManifest) models.CatalogManife
Revoked: m.Revoked,
RevokedAt: m.RevokedAt,
RevokedBy: m.RevokedBy,
PackSize: m.PackSize,
DownloadCount: m.DownloadCount,
}

Expand Down Expand Up @@ -364,6 +368,7 @@ func ApiCatalogManifestToCatalogManifest(m models.CatalogManifest) catalog_model
RevokedAt: m.RevokedAt,
RevokedBy: m.RevokedBy,
DownloadCount: m.DownloadCount,
PackSize: m.PackSize,
}

if m.Provider != nil {
Expand Down
1 change: 1 addition & 0 deletions src/models/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type CatalogManifest struct {
RevokedAt string `json:"revoked_at,omitempty" yaml:"revoked_at,omitempty"`
RevokedBy string `json:"revoked_by,omitempty" yaml:"revoked_by,omitempty"`
PackContents []CatalogManifestPackItem `json:"pack_contents,omitempty" yaml:"pack_contents,omitempty"`
PackSize int64 `json:"pack_size,omitempty" yaml:"pack_size,omitempty"`
MinimumSpecRequirements *MinimumSpecRequirement `json:"minimum_requirements,omitempty" yaml:"minimum_requirements,omitempty"`
}

Expand Down
13 changes: 7 additions & 6 deletions src/pdfile/models/pull_response.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package models

type PullResponse struct {
MachineId string `json:"machine_id,omitempty" yaml:"machine_id,omitempty"`
MachineName string `json:"machine_name,omitempty" yaml:"machine_name,omitempty"`
CatalogId string `json:"catalog_id,omitempty" yaml:"catalog_id,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Architecture string `json:"architecture,omitempty" yaml:"architecture,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
MachineId string `json:"machine_id,omitempty" yaml:"machine_id,omitempty"`
MachineName string `json:"machine_name,omitempty" yaml:"machine_name,omitempty"`
CatalogId string `json:"catalog_id,omitempty" yaml:"catalog_id,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Architecture string `json:"architecture,omitempty" yaml:"architecture,omitempty"`
LocalCachePath string `json:"local_cache_path,omitempty" yaml:"local_cache_path,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
}
13 changes: 7 additions & 6 deletions src/pdfile/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,12 +272,13 @@ func (p *PDFileService) runPull(ctx basecontext.ApiContext) (interface{}, *diagn

fmt.Printf("\rFinished pulling manifest\n")
response := models.PullResponse{
MachineId: resultManifest.ID,
MachineName: resultManifest.MachineName,
CatalogId: resultManifest.Manifest.CatalogId,
Version: resultManifest.Manifest.Version,
Architecture: resultManifest.Manifest.Architecture,
Type: resultManifest.Manifest.Type,
MachineId: resultManifest.ID,
MachineName: resultManifest.MachineName,
CatalogId: resultManifest.Manifest.CatalogId,
Version: resultManifest.Manifest.Version,
Architecture: resultManifest.Manifest.Architecture,
LocalCachePath: resultManifest.LocalCachePath,
Type: resultManifest.Manifest.Type,
}

if p.pdfile.Clone {
Expand Down

0 comments on commit 0c9b759

Please sign in to comment.