Class Censors

java.lang.Object
com.easypost.easyvcr.Censors

public final class Censors extends Object
Censoring capabilities for EasyVCR.
  • Constructor Details

    • Censors

      public Censors()
      Initialize a new instance of the Censors factory, using default censor string.
    • Censors

      public Censors(String censorString)
      Initialize a new instance of the Censors factory.
      Parameters:
      censorString - The string to use to censor sensitive information.
  • Method Details

    • regular

      public static Censors regular()
      Default censors is to not censor anything.
      Returns:
      Default set of censors.
    • strict

      public static Censors strict()
      Default sensitive censors is to censor common private information (i.e. API keys, auth tokens, etc.)
      Returns:
      Default sensitive set of censors.
    • censorJsonData

      public static String censorJsonData(String data, String censorText, List<CensorElement> elementsToCensor)
      Apply censors to a JSON string.
      Parameters:
      data - The JSON string to censor.
      censorText - The string to use to censor sensitive information.
      elementsToCensor - The body elements to censor.
      Returns:
      The censored JSON string.
    • applyBodyParameterCensors

      public static String applyBodyParameterCensors(String body, String censorText, List<CensorElement> bodyElementsToCensor)
      Censor the appropriate body elements.
      Parameters:
      body - String representation of request body to apply censors to.
      censorText - The string to use to censor sensitive information.
      bodyElementsToCensor - The body elements to censor.
      Returns:
      Censored string representation of request body.
    • applyHeaderCensors

      public static Map<String,​List<String>> applyHeaderCensors(Map<String,​List<String>> headers, String censorText, List<CensorElement> headersToCensor)
      Censor the appropriate headers.
      Parameters:
      headers - Map of headers to apply censors to.
      censorText - The string to use to censor sensitive information.
      headersToCensor - The headers to censor.
      Returns:
      Censored map of headers.
    • applyUrlCensors

      public static String applyUrlCensors(String url, String censorText, List<CensorElement> queryParamsToCensor, List<RegexCensorElement> pathElementsToCensor)
      Censor the appropriate query parameters.
      Parameters:
      url - Full URL string to apply censors to.
      censorText - The string to use to censor sensitive information.
      queryParamsToCensor - The query parameters to censor.
      pathElementsToCensor - The path elements to censor.
      Returns:
      Censored URL string.
    • censorBodyElements

      public Censors censorBodyElements(List<CensorElement> elements)
      Add a rule to censor specified body elements.
      Parameters:
      elements - List of body elements to censor.
      Returns:
      This Censors factory.
    • censorBodyElementsByKeys

      public Censors censorBodyElementsByKeys(List<String> elementKeys, boolean caseSensitive)
      Add a rule to censor specified body elements by their keys.
      Parameters:
      elementKeys - Keys of body elements to censor.
      caseSensitive - Whether to use case-sensitive censoring.
      Returns:
      This Censors factory.
    • censorBodyElementsByKeys

      public Censors censorBodyElementsByKeys(List<String> elementKeys)
      Add a rule to censor specified body elements by their keys.
      Parameters:
      elementKeys - Keys of body elementKeys to censor.
      Returns:
      This Censors factory.
    • censorHeaders

      public Censors censorHeaders(List<CensorElement> headers)
      Add a rule to censor specified headers. Note: This will censor the header keys in both the request and response.
      Parameters:
      headers - List of headers to censor.
      Returns:
      This Censors factory.
    • censorHeadersByKeys

      public Censors censorHeadersByKeys(List<String> headerKeys, boolean caseSensitive)
      Add a rule to censor specified headers by their keys. Note: This will censor the header keys in both the request and response.
      Parameters:
      headerKeys - Keys of headers to censor.
      caseSensitive - Whether to use case-sensitive censoring.
      Returns:
      This Censors factory.
    • censorHeadersByKeys

      public Censors censorHeadersByKeys(List<String> headerKeys)
      Add a rule to censor specified headers by their keys. Note: This will censor the header keys in both the request and response.
      Parameters:
      headerKeys - Keys of headers to censor.
      Returns:
      This Censors factory.
    • censorQueryParameters

      public Censors censorQueryParameters(List<CensorElement> elements)
      Add a rule to censor specified query parameters.
      Parameters:
      elements - List of query parameters to censor.
      Returns:
      This Censors factory.
    • censorQueryParametersByKeys

      public Censors censorQueryParametersByKeys(List<String> parameterKeys, boolean caseSensitive)
      Add a rule to censor specified query parameters by their keys.
      Parameters:
      parameterKeys - Keys of query parameters to censor.
      caseSensitive - Whether to use case-sensitive censoring.
      Returns:
      This Censors factory.
    • censorQueryParametersByKeys

      public Censors censorQueryParametersByKeys(List<String> parameterKeys)
      Add a rule to censor specified query parameters by their keys.
      Parameters:
      parameterKeys - Keys of query parameters to censor.
      Returns:
      This Censors factory.
    • censorPathElements

      public Censors censorPathElements(List<RegexCensorElement> elements)
      Add a rule to censor specified path elements.
      Parameters:
      elements - List of path elements to censor.
      Returns:
      This Censors factory.
    • censorPathElementsByPattern

      public Censors censorPathElementsByPattern(List<String> patterns, boolean caseSensitive)
      Add a rule to censor specified path elements by regular expression patterns.
      Parameters:
      patterns - Patterns of path elements to censor.
      caseSensitive - Whether to use case-sensitive pattern matching.
      Returns:
      This Censors factory.
    • censorPathElementsByPattern

      public Censors censorPathElementsByPattern(List<String> patterns)
      Add a rule to censor specified path elements by regular expression patterns.
      Parameters:
      patterns - Patterns of path elements to censor.
      Returns:
      This Censors factory.
    • applyBodyParameterCensors

      public String applyBodyParameterCensors(String body)
      Censor the appropriate body elements.
      Parameters:
      body - String representation of request body to apply censors to.
      Returns:
      Censored string representation of request body.
    • applyHeaderCensors

      public Map<String,​List<String>> applyHeaderCensors(Map<String,​List<String>> headers)
      Censor the appropriate headers.
      Parameters:
      headers - Map of headers to apply censors to.
      Returns:
      Censored map of headers.
    • applyUrlCensors

      public String applyUrlCensors(String url)
      Censor the appropriate query parameters.
      Parameters:
      url - Full URL string to apply censors to.
      Returns:
      Censored URL string.