Class InputValidator

java.lang.Object
io.jenkins.plugins.swarmcloud.security.InputValidator

public final class InputValidator extends Object
Utility class for validating and sanitizing user input. Provides protection against injection attacks and invalid input.
  • Method Details

    • isValidCloudName

      public static boolean isValidCloudName(@Nullable String name)
      Validates a cloud name.
      Parameters:
      name - The cloud name to validate
      Returns:
      true if valid
    • isValidTemplateName

      public static boolean isValidTemplateName(@Nullable String name)
      Validates a template name.
      Parameters:
      name - The template name to validate
      Returns:
      true if valid
    • isValidDockerImage

      public static boolean isValidDockerImage(@Nullable String image)
      Validates a Docker image name.
      Parameters:
      image - The Docker image to validate
      Returns:
      true if valid
    • isValidServiceId

      public static boolean isValidServiceId(@Nullable String serviceId)
      Validates a Docker Swarm service ID.
      Parameters:
      serviceId - The service ID to validate
      Returns:
      true if valid
    • isValidLabelString

      public static boolean isValidLabelString(@Nullable String labels)
      Validates a label string.
      Parameters:
      labels - The label string to validate
      Returns:
      true if valid
    • isValidNetworkName

      public static boolean isValidNetworkName(@Nullable String network)
      Validates a Docker network name.
      Parameters:
      network - The network name to validate
      Returns:
      true if valid
    • isValidDockerHost

      public static boolean isValidDockerHost(@Nullable String dockerHost)
      Validates a Docker host URL.
      Parameters:
      dockerHost - The Docker host URL to validate
      Returns:
      true if valid
    • sanitizeForLog

      @NonNull public static String sanitizeForLog(@Nullable String input)
      Sanitizes a string for safe use in logs. Removes newlines and limits length to prevent log injection.
      Parameters:
      input - The input string
      Returns:
      Sanitized string
    • sanitizeForDisplay

      @NonNull public static String sanitizeForDisplay(@Nullable String input)
      Sanitizes a string for display, escaping HTML.
      Parameters:
      input - The input string
      Returns:
      Sanitized string safe for HTML display
    • isValidMemorySpec

      public static boolean isValidMemorySpec(@Nullable String memory)
      Validates a memory specification (e.g., "512m", "1g", "2048m").
      Parameters:
      memory - The memory specification to validate
      Returns:
      true if valid
    • isValidCpuSpec

      public static boolean isValidCpuSpec(@Nullable String cpu)
      Validates a CPU limit specification (e.g., "0.5", "2.0", "4").
      Parameters:
      cpu - The CPU specification to validate
      Returns:
      true if valid
    • isValidPort

      public static boolean isValidPort(int port)
      Validates a port number.
      Parameters:
      port - The port number to validate
      Returns:
      true if valid
    • isValidTimeout

      public static boolean isValidTimeout(int timeout)
      Validates a timeout value in seconds.
      Parameters:
      timeout - The timeout in seconds
      Returns:
      true if valid (1 second to 1 hour)
    • isValidUrl

      public static boolean isValidUrl(@Nullable String url)
      Validates a URL.
      Parameters:
      url - The URL to validate
      Returns:
      true if valid
    • isValidPlacementConstraint

      public static boolean isValidPlacementConstraint(@Nullable String constraint)
      Validates a placement constraint.
      Parameters:
      constraint - The placement constraint to validate
      Returns:
      true if valid
    • isValidEnvVarName

      public static boolean isValidEnvVarName(@Nullable String name)
      Validates an environment variable name.
      Parameters:
      name - The environment variable name
      Returns:
      true if valid
    • isNotBlank

      public static boolean isNotBlank(@Nullable String value)
      Checks if a string is not null and not blank.
      Parameters:
      value - The string to check
      Returns:
      true if not null and not blank