Skip to content

Commit

Permalink
feat(pipeline_template): Support semver for template tags
Browse files Browse the repository at this point in the history
  • Loading branch information
micnncim committed Nov 11, 2020
1 parent 9ff2529 commit 28206e1
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -62,6 +64,9 @@ public class V2PipelineTemplateController {
private static final List<String> VALID_TEMPLATE_TAGS =
Arrays.asList("latest", "stable", "unstable", "experimental", "test", "canary");

public static final Pattern VALID_TEMPLATE_TAG_PATTERN =
Pattern.compile("^[0-9]\\d*\\.\\d+\\.\\d+(?:-[a-zA-Z0-9]+)?$");

@Autowired(required = false)
PipelineTemplateDAO pipelineTemplateDAO = null;

Expand Down Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 28206e1

Please sign in to comment.