MCPcopy Create free account
hub / github.com/cloudfoundry/multiapps-cli-plugin / GetMtaDescriptorFromArchive

Function GetMtaDescriptorFromArchive

util/archive_handler.go:25–51  ·  view source on GitHub ↗

GetMtaDescriptorFromArchive retrieves MTA ID from MTA archive

(mtaArchiveFilePath string)

Source from the content-addressed store, hash-verified

23
24// GetMtaDescriptorFromArchive retrieves MTA ID from MTA archive
25func GetMtaDescriptorFromArchive(mtaArchiveFilePath string) (MtaDescriptor, error) {
26 mtaArchiveReader, err := zip.OpenReader(mtaArchiveFilePath)
27 if err != nil {
28 return MtaDescriptor{}, err
29 }
30 defer mtaArchiveReader.Close()
31
32 descriptorFile := findMtaDescriptorFile(mtaArchiveReader.File)
33 if descriptorFile == nil {
34 return MtaDescriptor{}, errors.New("Could not get a valid MTA descriptor from archive")
35 }
36
37 descriptorBytes, err := readZipFile(descriptorFile)
38 if err != nil {
39 return MtaDescriptor{}, err
40 }
41
42 var descriptor MtaDescriptor
43 if err = yaml.Unmarshal(descriptorBytes, &descriptor); err != nil {
44 return MtaDescriptor{}, err
45 }
46
47 if descriptor.ID != "" {
48 return descriptor, nil
49 }
50 return MtaDescriptor{}, errors.New("Could not get a valid MTA descriptor from archive")
51}
52
53func findMtaDescriptorFile(files []*zip.File) *zip.File {
54 for _, file := range files {

Callers 2

executeInternalMethod · 0.92

Calls 3

findMtaDescriptorFileFunction · 0.85
readZipFileFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected