From a58acff3c7d8d80101839d7bdc4e0bca0ee9779c Mon Sep 17 00:00:00 2001 From: micnncim Date: Thu, 12 Nov 2020 02:39:43 +0900 Subject: [PATCH] feat(pipeline_template): Support semver for template tags --- .../controllers/V2PipelineTemplateController.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/V2PipelineTemplateController.java b/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/V2PipelineTemplateController.java index 62358f40c..56c7edd49 100644 --- a/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/V2PipelineTemplateController.java +++ b/front50-web/src/main/java/com/netflix/spinnaker/front50/controllers/V2PipelineTemplateController.java @@ -41,6 +41,8 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Hex; @@ -62,6 +64,9 @@ public class V2PipelineTemplateController { private static final List VALID_TEMPLATE_TAGS = Arrays.asList("latest", "stable", "unstable", "experimental", "test", "canary"); + public static final Pattern VALID_TEMPLATE_TAG_PATTERN = + Pattern.compile("^v?[0-9]\\d*\\.\\d+\\.\\d+(?:-[a-zA-Z0-9]+)?$"); + @Autowired(required = false) PipelineTemplateDAO pipelineTemplateDAO = null; @@ -257,10 +262,12 @@ private PipelineTemplateDAO getPipelineTemplateDAO() { } private void validatePipelineTemplateTag(String tag) { - if (!VALID_TEMPLATE_TAGS.contains(tag)) { + Matcher m = VALID_TEMPLATE_TAG_PATTERN.matcher(tag); + if (!VALID_TEMPLATE_TAGS.contains(tag) || !m.matches()) { throw new InvalidRequestException( String.format( - "The provided tag %s is not supported." + " Pipeline template must tag be one of %s", + "The provided tag %s is not supported." + + " Pipeline template must tag be one of %s or semantic versioning", tag, VALID_TEMPLATE_TAGS)); } }