Add a check for nil secrets

Improve the error message if
secrets are not provided in request

Signed-off-by: Madhu Rajanna <madhupr007@gmail.com>
(cherry picked from commit b8568a5bb9)
This commit is contained in:
Madhu Rajanna 2019-09-25 20:15:19 +05:30 committed by Madhu Rajanna
parent 756a650cd1
commit 454394322a

View File

@ -17,6 +17,7 @@ limitations under the License.
package util package util
import ( import (
"errors"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
@ -72,6 +73,9 @@ func newCredentialsFromSecret(idField, keyField string, secrets map[string]strin
ok bool ok bool
) )
if len(secrets) == 0 {
return nil, errors.New("provided secret is empty")
}
if c.ID, ok = secrets[idField]; !ok { if c.ID, ok = secrets[idField]; !ok {
return nil, fmt.Errorf("missing ID field '%s' in secrets", idField) return nil, fmt.Errorf("missing ID field '%s' in secrets", idField)
} }