From 71be7026d79e3ac7ef75644c850009715c2d006a Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Mon, 8 Apr 2019 12:41:48 -0400 Subject: [PATCH] fix: correct GetResourceValue errors --- plugins/resource/resource.go | 30 ++++++++++++++++++++++++------ plugins/resource/subcommands.go | 18 ------------------ 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/plugins/resource/resource.go b/plugins/resource/resource.go index 0d8e0187f..cddb2cf9e 100644 --- a/plugins/resource/resource.go +++ b/plugins/resource/resource.go @@ -67,23 +67,24 @@ 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) { +// Fetches a single value for a given app/process/request/key combination +func GetResourceValue(appName string, processType string, requestType string, key string) (string, error) { resources, err := common.PropertyGetAll("resource", appName) if err != nil { return "", err } + defaultValue := "" for key, value := range resources { - parts := strings.SplitN(strings.TrimPrefix(key, prefix), ".", 2) - if parts[0] != resourceType { - return "", err + if key == propertyKey("_default_", requestType, key) { + defaultValue = value } - if parts[1] == prefix { + if key == propertyKey(processType, requestType, key) { return value, nil } } - return "", errors.New("No value found") + return defaultValue, nil } func times(str string, n int) (out string) { @@ -97,3 +98,20 @@ func times(str string, n int) (out string) { func Right(str string, length int, pad string) string { return str + times(pad, length-len(str)) } + +func propertyKey(processType string, requestType string, key string) string { + return fmt.Sprintf("%v.%v.%v", processType, requestType, key) +} + +func getAppName(args []string) (string, error) { + if len(args) < 1 { + return "", errors.New("Please specify an app to run the command on") + } + + appName := args[0] + if err := common.VerifyAppName(appName); err != nil { + return "", err + } + + return appName, nil +} diff --git a/plugins/resource/subcommands.go b/plugins/resource/subcommands.go index 09a5dab73..2c0ced583 100644 --- a/plugins/resource/subcommands.go +++ b/plugins/resource/subcommands.go @@ -1,7 +1,6 @@ package resource import ( - "errors" "fmt" "github.com/dokku/dokku/plugins/common" ) @@ -169,20 +168,3 @@ func reportRequestType(appName string, processType string, requestType string) { } return } - -func propertyKey(processType string, requestType string, key string) string { - return fmt.Sprintf("%v.%v.%v", processType, requestType, key) -} - -func getAppName(args []string) (string, error) { - if len(args) < 1 { - return "", errors.New("Please specify an app to run the command on") - } - - appName := args[0] - if err := common.VerifyAppName(appName); err != nil { - return "", err - } - - return appName, nil -}