Parse metadata.Name before creating tpr resource (#284)

This commit is contained in:
Ta-Ching Chen
2017-08-14 08:55:31 -07:00
committed by Soam Vasani
parent 45f3095fb1
commit a52425a31d
7 changed files with 47 additions and 0 deletions
+11
View File
@@ -17,6 +17,9 @@ limitations under the License.
package controller
import (
"errors"
"regexp"
"github.com/fission/fission/tpr"
)
@@ -27,3 +30,11 @@ func makeTPRBackedAPI() (*API, error) {
}
return &API{fissionClient: fissionClient}, nil
}
func validateResourceName(name string) error {
re := regexp.MustCompile(`[a-z0-9]([-a-z0-9]*[a-z0-9])?`)
if len(re.FindString(name)) != len(name) {
return errors.New("Name must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?'")
}
return nil
}