// Copyright 2011 The MOE Authors All Rights Reserved

package com.google.devtools.moe.client.repositories;

import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;

import java.util.List;

/**
 * Configuration for a MOE metadata scrubber.
 */
public class MetadataScrubberConfig {
  @SerializedName("usernames_to_scrub")
  private List<String> usernamesToScrub;

  @SerializedName("scrub_confidential_words")
  private boolean scrubConfidentialWords = true;

  /**
   * Formatting for changelog adapted from fromRepository for commits in toRepository. See
   * {@link DescriptionMetadataScrubber}.
   */
  @SerializedName("log_format")
  private String logFormat = "{description}\n\tChange on {date} by {author}";

  public MetadataScrubberConfig() {} // Constructed by gson

  public List<String> getUsernamesToScrub() {
    return usernamesToScrub;
  }

  /**
   * Access the boolean field, which can be used as a trigger for
   * the proper MetadataScrubber to scrub any confidential words.
   * @return boolean whether confidential words should be scrubbed
   */
  public boolean getScrubConfidentialWords() {
    return scrubConfidentialWords;
  }

  public String getLogFormat() {
    return logFormat;
  }

  /**
   * @return the list of {@link MetadataScrubber}s as determined by this configuration
   */
  public List<MetadataScrubber> getScrubbers() {
    ImmutableList.Builder<MetadataScrubber> scrubbersBuilder = ImmutableList.builder();

    if (usernamesToScrub != null && !usernamesToScrub.isEmpty()) {
      scrubbersBuilder.add(new MetadataUsernameScrubber(getUsernamesToScrub()));
    }

    if (getScrubConfidentialWords()) {
      // Here is where you can use a MetadataScrubber that scrubs confidential words.
    }

    scrubbersBuilder.add(new PublicSectionMetadataScrubber());

    scrubbersBuilder.add(new DescriptionMetadataScrubber(logFormat));

    return scrubbersBuilder.build();
  }
}

// Copyright 2011 The MOE Authors All Rights Reserved

package com.google.devtools.moe.client.repositories;

import com.google.common.collect.ImmutableList;
import com.google.gson.annotations.SerializedName;

import java.util.List;

/**
 * Configuration for a MOE metadata scrubber.
 */
public class MetadataScrubberConfig {
  @SerializedName("usernames_to_scrub")
  private List<String> usernamesToScrub;

  @SerializedName("scrub_confidential_words")
  private boolean scrubConfidentialWords = true;

  @SerializedName("sensitive_res")
  private List<String> sensitiveRes = ImmutableList.of();

  /**
   * Formatting for changelog adapted from fromRepository for commits in toRepository. See
   * {@link DescriptionMetadataScrubber}.
   */
  @SerializedName("log_format")
  private String logFormat = "{description}\n\tChange on {date} by {author}";

  public MetadataScrubberConfig() {} // Constructed by gson

  public List<String> getUsernamesToScrub() {
    return usernamesToScrub;
  }

  /**
   * Access the boolean field, which can be used as a trigger for
   * the proper MetadataScrubber to scrub any confidential words.
   * @return boolean whether confidential words should be scrubbed
   */
  public boolean getScrubConfidentialWords() {
    return scrubConfidentialWords;
  }

  /** A list of regular expressions for sensitive text to be scrubbed from revision metadata. */
  public List<String> getSensitiveRes() {
    return sensitiveRes;
  }

  public String getLogFormat() {
    return logFormat;
  }

  /**
   * @return the list of {@link MetadataScrubber}s as determined by this configuration
   */
  public List<MetadataScrubber> getScrubbers() {
    ImmutableList.Builder<MetadataScrubber> scrubbersBuilder = ImmutableList.builder();

    if (usernamesToScrub != null && !usernamesToScrub.isEmpty()) {
      scrubbersBuilder.add(new MetadataUsernameScrubber(getUsernamesToScrub()));
    }

    if (scrubConfidentialWords) {
      // Here is where you can use a MetadataScrubber that scrubs confidential words.
    }

    scrubbersBuilder.add(new PublicSectionMetadataScrubber());

    scrubbersBuilder.add(new DescriptionMetadataScrubber(logFormat));

    return scrubbersBuilder.build();
  }
}

Add a "sensitive_res" setting to the metadata_scrubber_config, allowing custom additional regexes to be scrubbed from change descriptions. Add regex for "[] "[] "[] to SENSITIVE_WORDS and rename SENSITIVE_WORDS to the more accurate name, SENSITIVE_RES. Change on 2013/01/07 by kpy <kpy@google.com> ------------- Created by MOE: http://code.google.com/p/moe-java MOE_MIGRATED_REVID=40836763