forked from toolshed/abra
@ -30,26 +30,6 @@ const RecipeCatalogueURL = "https://apps.coopcloud.tech"
|
||||
// ReposMetadataURL is the recipe repository metadata
|
||||
const ReposMetadataURL = "https://git.coopcloud.tech/api/v1/orgs/coop-cloud/repos"
|
||||
|
||||
// image represents a recipe container image.
|
||||
type image struct {
|
||||
Image string `json:"image"`
|
||||
Rating string `json:"rating"`
|
||||
Source string `json:"source"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
// features represent what top-level features a recipe supports (e.g. does this
|
||||
// recipe support backups?).
|
||||
type features struct {
|
||||
Backups string `json:"backups"`
|
||||
Email string `json:"email"`
|
||||
Healthcheck string `json:"healthcheck"`
|
||||
Image image `json:"image"`
|
||||
Status int `json:"status"`
|
||||
Tests string `json:"tests"`
|
||||
SSO string `json:"sso"`
|
||||
}
|
||||
|
||||
// tag represents a git tag.
|
||||
type tag = string
|
||||
|
||||
@ -68,15 +48,15 @@ type RecipeVersions []map[tag]map[service]ServiceMeta
|
||||
|
||||
// RecipeMeta represents metadata for a recipe in the abra catalogue.
|
||||
type RecipeMeta struct {
|
||||
Category string `json:"category"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Description string `json:"description"`
|
||||
Features features `json:"features"`
|
||||
Icon string `json:"icon"`
|
||||
Name string `json:"name"`
|
||||
Repository string `json:"repository"`
|
||||
Versions RecipeVersions `json:"versions"`
|
||||
Website string `json:"website"`
|
||||
Category string `json:"category"`
|
||||
DefaultBranch string `json:"default_branch"`
|
||||
Description string `json:"description"`
|
||||
Features recipe.Features `json:"features"`
|
||||
Icon string `json:"icon"`
|
||||
Name string `json:"name"`
|
||||
Repository string `json:"repository"`
|
||||
Versions RecipeVersions `json:"versions"`
|
||||
Website string `json:"website"`
|
||||
}
|
||||
|
||||
// LatestVersion returns the latest version of a recipe.
|
||||
@ -380,131 +360,6 @@ func ReadReposMetadata() (RepoCatalogue, error) {
|
||||
return reposMeta, nil
|
||||
}
|
||||
|
||||
func GetStringInBetween(str, start, end string) (result string, err error) {
|
||||
// GetStringInBetween returns empty string if no start or end string found
|
||||
s := strings.Index(str, start)
|
||||
if s == -1 {
|
||||
return "", fmt.Errorf("marker string %s not found", start)
|
||||
}
|
||||
s += len(start)
|
||||
e := strings.Index(str[s:], end)
|
||||
if e == -1 {
|
||||
return "", fmt.Errorf("end marker %s not found", end)
|
||||
}
|
||||
return str[s : s+e], nil
|
||||
}
|
||||
|
||||
func GetImageMetadata(imageRowString, recipeName string) (image, error) {
|
||||
img := image{}
|
||||
|
||||
imgFields := strings.Split(imageRowString, ",")
|
||||
|
||||
for i, elem := range imgFields {
|
||||
imgFields[i] = strings.TrimSpace(elem)
|
||||
}
|
||||
|
||||
if len(imgFields) < 3 {
|
||||
if imageRowString != "" {
|
||||
logrus.Warnf("%s image meta has incorrect format: %s", recipeName, imageRowString)
|
||||
} else {
|
||||
logrus.Warnf("%s image meta is empty?", recipeName)
|
||||
}
|
||||
return img, nil
|
||||
}
|
||||
|
||||
img.Rating = imgFields[1]
|
||||
img.Source = imgFields[2]
|
||||
|
||||
imgString := imgFields[0]
|
||||
|
||||
imageName, err := GetStringInBetween(imgString, "[", "]")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
img.Image = strings.ReplaceAll(imageName, "`", "")
|
||||
|
||||
imageURL, err := GetStringInBetween(imgString, "(", ")")
|
||||
if err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
img.URL = imageURL
|
||||
|
||||
return img, nil
|
||||
}
|
||||
|
||||
func GetRecipeFeaturesAndCategory(recipeName string) (features, string, error) {
|
||||
feat := features{}
|
||||
|
||||
var category string
|
||||
|
||||
readmePath := path.Join(config.RECIPES_DIR, recipeName, "README.md")
|
||||
|
||||
logrus.Debugf("attempting to open %s for recipe metadata parsing", readmePath)
|
||||
|
||||
readmeFS, err := ioutil.ReadFile(readmePath)
|
||||
if err != nil {
|
||||
return feat, category, err
|
||||
}
|
||||
|
||||
readmeMetadata, err := GetStringInBetween( // Find text between delimiters
|
||||
string(readmeFS),
|
||||
"<!-- metadata -->", "<!-- endmetadata -->",
|
||||
)
|
||||
if err != nil {
|
||||
return feat, category, err
|
||||
}
|
||||
|
||||
readmeLines := strings.Split( // Array item from lines
|
||||
strings.ReplaceAll( // Remove \t tabs
|
||||
readmeMetadata, "\t", "",
|
||||
),
|
||||
"\n")
|
||||
|
||||
for _, val := range readmeLines {
|
||||
if strings.Contains(val, "**Category**") {
|
||||
category = strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Category**:"),
|
||||
)
|
||||
}
|
||||
if strings.Contains(val, "**Backups**") {
|
||||
feat.Backups = strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Backups**:"),
|
||||
)
|
||||
}
|
||||
if strings.Contains(val, "**Email**") {
|
||||
feat.Email = strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Email**:"),
|
||||
)
|
||||
}
|
||||
if strings.Contains(val, "**SSO**") {
|
||||
feat.SSO = strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **SSO**:"),
|
||||
)
|
||||
}
|
||||
if strings.Contains(val, "**Healthcheck**") {
|
||||
feat.Healthcheck = strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Healthcheck**:"),
|
||||
)
|
||||
}
|
||||
if strings.Contains(val, "**Tests**") {
|
||||
feat.Tests = strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Tests**:"),
|
||||
)
|
||||
}
|
||||
if strings.Contains(val, "**Image**") {
|
||||
imageMetadata, err := GetImageMetadata(strings.TrimSpace(
|
||||
strings.TrimPrefix(val, "* **Image**:"),
|
||||
), recipeName)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
feat.Image = imageMetadata
|
||||
}
|
||||
}
|
||||
|
||||
return feat, category, nil
|
||||
}
|
||||
|
||||
// GetRecipeVersions retrieves all recipe versions.
|
||||
func GetRecipeVersions(recipeName string) (RecipeVersions, error) {
|
||||
versions := RecipeVersions{}
|
||||
|
Reference in New Issue
Block a user