From 0b59486c82a9786c85438f6352636b19b83e1021 Mon Sep 17 00:00:00 2001 From: Eric Multanen Date: Thu, 16 Apr 2020 10:44:06 -0700 Subject: Controller API support Add controller API support as baseline for adding gRPC framework. Issue-ID: MULTICLOUD-1019 Signed-off-by: Eric Multanen Change-Id: Ifd522a0eefbb8e54be45cc62003d3809283c9bfe --- .../pkg/infra/validation/validation.go | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/orchestrator/pkg/infra') diff --git a/src/orchestrator/pkg/infra/validation/validation.go b/src/orchestrator/pkg/infra/validation/validation.go index 448ea5de..c43d29ec 100644 --- a/src/orchestrator/pkg/infra/validation/validation.go +++ b/src/orchestrator/pkg/infra/validation/validation.go @@ -23,6 +23,7 @@ import ( "io" "net" "regexp" + "strconv" "strings" pkgerrors "github.com/pkg/errors" @@ -280,6 +281,28 @@ func IsValidNumber(value, min, max int) []string { return errs } +func IsValidNumberStr(value string, min, max int) []string { + var errs []string + + if min > max { + errs = append(errs, "invalid constraints") + return errs + } + + n, err := strconv.Atoi(value) + if err != nil { + errs = append(errs, err.Error()) + return errs + } + if n < min { + errs = append(errs, "value less than minimum") + } + if n > max { + errs = append(errs, "value greater than maximum") + } + return errs +} + /* IsValidParameterPresent method takes in a vars map and a array of string parameters that you expect to be present in the GET request. -- cgit 1.2.3-korg