Review Board 1.7.22


SQOOP-776 Sqoop2: show connection command shows password in plain text

Review Request #8620 - Created Dec. 15, 2012 and submitted

Jarek Cecho
SQOOP-776
Reviewers
Sqoop
sqoop-sqoop2
I've hacked current code to stop printing sensitive information and improved the user experience by printing input type specific information.

 
client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java
Revision 97eea795f7c5ebc9eab5e7f8741022342d55eb1d New Change
[20] 19 lines
[+20]
20
import org.apache.sqoop.model.MEnumInput;
20
import org.apache.sqoop.model.MEnumInput;
21
import org.apache.sqoop.model.MForm;
21
import org.apache.sqoop.model.MForm;
22
import org.apache.sqoop.model.MFramework;
22
import org.apache.sqoop.model.MFramework;
23
import org.apache.sqoop.model.MInput;
23
import org.apache.sqoop.model.MInput;
24
import org.apache.sqoop.model.MInputType;
24
import org.apache.sqoop.model.MInputType;

    
   
25
import org.apache.sqoop.model.MIntegerInput;
25
import org.apache.sqoop.model.MJobForms;
26
import org.apache.sqoop.model.MJobForms;

    
   
27
import org.apache.sqoop.model.MMapInput;
26
import org.apache.sqoop.model.MStringInput;
28
import org.apache.sqoop.model.MStringInput;
27
import org.apache.sqoop.utils.StringUtils;
29
import org.apache.sqoop.utils.StringUtils;
28
import org.codehaus.groovy.tools.shell.IO;
30
import org.codehaus.groovy.tools.shell.IO;
29

    
   
31

   
30
import java.util.Iterator;
32
import java.util.Iterator;
31
import java.util.List;
33
import java.util.List;

    
   
34
import java.util.Map;
32
import java.util.ResourceBundle;
35
import java.util.ResourceBundle;
33

    
   
36

   
34
/**
37
/**
35
 * Convenience static methods for displaying form related information
38
 * Convenience static methods for displaying form related information
36
 */
39
 */
[+20] [20] 89 lines
[+20] [+] private static void displayForm(IO io, MForm form, ResourceBundle bundle) {
126
    for (MInput<?> input : form.getInputs()) {
129
    for (MInput<?> input : form.getInputs()) {
127
      io.out.print("    ");
130
      io.out.print("    ");
128
      io.out.print(bundle.getString(input.getLabelKey()));
131
      io.out.print(bundle.getString(input.getLabelKey()));
129
      io.out.print(": ");
132
      io.out.print(": ");
130
      if(!input.isEmpty()) {
133
      if(!input.isEmpty()) {
131
        io.out.print(input.getUrlSafeValueString());
134
        // Based on the input type, let's perform specific load

    
   
135
        switch (input.getType()) {

    
   
136
          case STRING:

    
   
137
            displayInputString(io, (MStringInput) input);

    
   
138
            break;

    
   
139
          case INTEGER:

    
   
140
            displayInputInteger(io, (MIntegerInput) input);

    
   
141
            break;

    
   
142
          case MAP:

    
   
143
            displayInputMap(io, (MMapInput) input);

    
   
144
            break;

    
   
145
          case ENUM:

    
   
146
            displayInputEnum(io, (MEnumInput) input);

    
   
147
            break;

    
   
148
          default:

    
   
149
            io.out.println("Unsupported data type " + input.getType());

    
   
150
            return;

    
   
151
        }
132
      }
152
      }
133
      io.out.println("");
153
      io.out.println("");
134
    }
154
    }
135
  }
155
  }
136

    
   
156

   

    
   
157
  /**

    
   
158
   * Display content of String input.

    
   
159
   *

    
   
160
   * @param io Shell's IO object

    
   
161
   * @param input String input

    
   
162
   */

    
   
163
  private static void displayInputString(IO io, MStringInput input) {

    
   
164
    if (input.isMasked()) {

    
   
165
      io.out.print("(This input is sensitive)");

    
   
166
    } else {

    
   
167
      io.out.print(input.getValue());

    
   
168
    }

    
   
169
  }

    
   
170

   

    
   
171
  /**

    
   
172
   * Display content of Integer input.

    
   
173
   *

    
   
174
   * @param io Shell's IO object

    
   
175
   * @param input Integer input

    
   
176
   */

    
   
177
  private static void displayInputInteger(IO io, MIntegerInput input) {

    
   
178
    io.out.print(input.getValue());

    
   
179
  }

    
   
180

   

    
   
181
  /**

    
   
182
   * Display content of Map input

    
   
183
   *

    
   
184
   * @param io Shell's IO object

    
   
185
   * @param input Map input

    
   
186
   */

    
   
187
  private static void displayInputMap(IO io, MMapInput input) {

    
   
188
    for(Map.Entry<String, String> entry : input.getValue().entrySet()) {

    
   
189
      io.out.println();

    
   
190
      io.out.print("      ");

    
   
191
      io.out.print(entry.getKey());

    
   
192
      io.out.print(" = ");

    
   
193
      io.out.print(entry.getValue());

    
   
194
    }

    
   
195
  }

    
   
196

   

    
   
197
  /**

    
   
198
   * Display content of Enum input

    
   
199
   *

    
   
200
   * @param io Shell's IO object

    
   
201
   * @param input Enum input

    
   
202
   */

    
   
203
  private static void displayInputEnum(IO io, MEnumInput input) {

    
   
204
    io.out.print(input.getValue());

    
   
205
  }

    
   
206

   
137
  private FormDisplayer() {
207
  private FormDisplayer() {
138
    // Do not instantiate
208
    // Do not instantiate
139
  }
209
  }
140
}
210
}
  1. client/src/main/java/org/apache/sqoop/client/utils/FormDisplayer.java: Loading...