Class CreateNamePattern

java.lang.Object
io.jenkins.plugins.batchcontrol.model.CreateNamePattern

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final class CreateNamePattern extends Object
The optional name restriction of a CREATE grant (D-40): either an exact item name, or a Java regular expression written as /regex/ that must match the whole item name. Only the item name is ever matched, never the full name.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Upper bound on the stored restriction, so a request cannot carry an unbounded regex.
    static final int
    D-40a (security-08 S-03): a longer new name never matches a restriction.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Plain-text description of a stored restriction for an explanation to the holder (e2e-03 DEF-19), for example names matching the pattern /app-[0-9]+/ or the name 'app-2'.
    Compiles a stored restriction for matching; a stored value that no longer parses matches nothing (fail-safe), represented by a pattern that never matches.
    boolean
    matches(String itemName)
    Whether the new item's name (not its full name) satisfies the restriction.
    static String
    Normalizes user input: null for an absent or blank restriction, otherwise the trimmed text.
    parse(String text)
    Validates and compiles a restriction at submission time.
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

    • MAX_LENGTH

      public static final int MAX_LENGTH
      Upper bound on the stored restriction, so a request cannot carry an unbounded regex.
      See Also:
    • MAX_NAME_LENGTH

      public static final int MAX_NAME_LENGTH
      D-40a (security-08 S-03): a longer new name never matches a restriction.
      See Also:
  • Method Details

    • normalize

      @CheckForNull public static String normalize(@CheckForNull String text)
      Normalizes user input: null for an absent or blank restriction, otherwise the trimmed text.
    • describe

      public static String describe(String text)
      Plain-text description of a stored restriction for an explanation to the holder (e2e-03 DEF-19), for example names matching the pattern /app-[0-9]+/ or the name 'app-2'.
    • parse

      public static CreateNamePattern parse(String text)
      Validates and compiles a restriction at submission time.
      Parameters:
      text - the normalized restriction (see normalize(java.lang.String)); must not be null
      Throws:
      IllegalArgumentException - if the text is too long, the regex does not compile, or an exact name is not a valid item name
    • forStored

      public static CreateNamePattern forStored(String text)
      Compiles a stored restriction for matching; a stored value that no longer parses matches nothing (fail-safe), represented by a pattern that never matches.
    • matches

      public boolean matches(@CheckForNull String itemName)
      Whether the new item's name (not its full name) satisfies the restriction. The name is matched exactly as submitted, untrimmed (S-06). A name over 255 characters never matches, and a regular-expression match that runs longer than the deadline fails (S-03), so no pattern can stall the calling thread.
    • toString

      public String toString()
      Overrides:
      toString in class Object