forked from toolshed/abra
@ -15,6 +15,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/config"
|
||||
"coopcloud.tech/abra/pkg/recipe"
|
||||
"coopcloud.tech/abra/pkg/web"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RecipeCatalogueURL is the only current recipe catalogue available.
|
||||
@ -76,6 +77,8 @@ func (r RecipeMeta) LatestVersion() string {
|
||||
version = tag
|
||||
}
|
||||
|
||||
logrus.Debugf("choosing '%s' as latest version of '%s'", version, r.Name)
|
||||
|
||||
return version
|
||||
}
|
||||
|
||||
@ -88,9 +91,11 @@ type RecipeCatalogue map[Name]RecipeMeta
|
||||
// Flatten converts AppCatalogue to slice
|
||||
func (r RecipeCatalogue) Flatten() []RecipeMeta {
|
||||
recipes := make([]RecipeMeta, 0, len(r))
|
||||
|
||||
for name := range r {
|
||||
recipes = append(recipes, r[name])
|
||||
}
|
||||
|
||||
return recipes
|
||||
}
|
||||
|
||||
@ -117,9 +122,11 @@ func recipeCatalogueFSIsLatest() (bool, error) {
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
info, err := os.Stat(config.APPS_JSON)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
logrus.Debugf("no recipe catalogue found in file system cache")
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
@ -129,9 +136,12 @@ func recipeCatalogueFSIsLatest() (bool, error) {
|
||||
remoteModifiedTime := parsed.Unix()
|
||||
|
||||
if localModifiedTime < remoteModifiedTime {
|
||||
logrus.Debug("file system cached recipe catalogue is out-of-date")
|
||||
return false, nil
|
||||
}
|
||||
|
||||
logrus.Debug("file system cached recipe catalogue is up-to-date")
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
@ -145,12 +155,14 @@ func ReadRecipeCatalogue() (RecipeCatalogue, error) {
|
||||
}
|
||||
|
||||
if !recipeFSIsLatest {
|
||||
logrus.Debugf("reading recipe catalogue from web to get latest")
|
||||
if err := readRecipeCatalogueWeb(&recipes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return recipes, nil
|
||||
}
|
||||
|
||||
logrus.Debugf("reading recipe catalogue from file system cache to get latest")
|
||||
if err := readRecipeCatalogueFS(&recipes); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -164,9 +176,13 @@ func readRecipeCatalogueFS(target interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(recipesJSONFS, &target); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("read recipe catalogue from file system cache in '%s'", config.APPS_JSON)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -185,6 +201,8 @@ func readRecipeCatalogueWeb(target interface{}) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Debugf("read recipe catalogue from web at '%s'", RecipeCatalogueURL)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -211,6 +229,8 @@ func VersionsOfService(recipe, serviceName string) ([]string, error) {
|
||||
}
|
||||
}
|
||||
|
||||
logrus.Debugf("detected versions '%s' for '%s'", strings.Join(versions, ", "), recipe)
|
||||
|
||||
return versions, nil
|
||||
}
|
||||
|
||||
@ -226,9 +246,12 @@ func GetRecipeMeta(recipeName string) (RecipeMeta, error) {
|
||||
err := fmt.Errorf("recipe '%s' does not exist?", recipeName)
|
||||
return RecipeMeta{}, err
|
||||
}
|
||||
|
||||
if err := recipe.EnsureExists(recipeName); err != nil {
|
||||
return RecipeMeta{}, err
|
||||
}
|
||||
|
||||
logrus.Debugf("recipe metadata retrieved for '%s'", recipeName)
|
||||
|
||||
return recipeMeta, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user