feat: add trigger to allow retrieving resource properties on the fly

This commit is contained in:
Jose Diaz-Gonzalez committed 2019-04-08 11:31:34 -04:00
1 parent 243d5ecc43
commit c2898ec040
4 files changed
+49 -2

No files matched your search

+20
View File
@@ -1,6 +1,7 @@
package resource
import (
"errors"
"fmt"
"os"
"reflect"
@@ -66,6 +67,25 @@ func ReportSingleApp(appName, infoFlag string) {
common.LogFail(fmt.Sprintf("Invalid flag passed, valid flags: %s", strings.Join(strkeys, ", ")))
}
func GetResourceValue(appName string, procType string, resourceType string, prefix string) (string, error) {
resources, err := common.PropertyGetAll("resource", appName)
if err != nil {
return "", err
}
for key, value := range resources {
parts := strings.SplitN(strings.TrimPrefix(key, prefix), ".", 2)
if parts[0] != resourceType {
return "", err
}
if parts[1] == prefix {
return value, nil
}
}
return "", errors.New("No value found")
}
func times(str string, n int) (out string) {
for i := 0; i < n; i++ {
out += str