Esempio n. 1
0
//ReadTemplateVersion reads the template version details
func (cat *Catalog) ReadTemplateVersion(templateID string, versionID string) (*model.Template, bool) {

	prefix, templateName := ExtractTemplatePrefixAndName(templateID)
	path := cat.CatalogID + "/" + prefix + "/" + templateName + "/" + versionID
	parentPath := cat.CatalogID + "/" + templateID
	parentMetadata, ok := cat.metadata[parentPath]

	if ok {
		newTemplate := model.Template{}
		newTemplate.Path = cat.CatalogID + "/" + templateID + "/" + versionID
		newTemplate.TemplateBase = parentMetadata.TemplateBase
		newTemplate.Id = cat.CatalogID + ":" + templateID + ":" + versionID
		newTemplate.CatalogID = cat.CatalogID
		newTemplate.DefaultVersion = parentMetadata.DefaultVersion
		newTemplate.Category = parentMetadata.Category
		newTemplate.IsSystem = parentMetadata.IsSystem
		newTemplate.Files = make(map[string]string)

		foundIcon, foundReadme, err := walkVersion(CatalogRootDir+path, &newTemplate)

		if err != nil {
			log.Errorf("Error reading template at path: %s, error: %v", path, err)
			return nil, false
		}

		if !foundIcon {
			//use the parent icon
			newTemplate.IconLink = parentMetadata.IconLink
		}

		if !foundReadme {
			//use the parent readme
			newTemplate.ReadmeLink = parentMetadata.ReadmeLink
		}

		return &newTemplate, true
	}

	return nil, false

}