Config Section: Add passwordForKey() convenience method
Section class already provides password() method that does the right thing (store the value in secure.config) and suppresses the input from the terminal. However this method expects user/password pair to exist. With OAuth Github authentication provider we need to provide password for GitHub Client Secret. Add another convenience method for Section to operate on single field with description. Change-Id: I9593cd5b35ae263003c1d1c9d771638a780ef96a
This commit is contained in:

committed by
Edwin Kempin

parent
b0a36c386b
commit
9e58478b66
@@ -170,6 +170,24 @@ public class Section {
|
||||
return nv;
|
||||
}
|
||||
|
||||
public String passwordForKey(String key, String password) {
|
||||
String ov = getSecure(password);
|
||||
if (ov != null) {
|
||||
// If the password is already stored, try to reuse it
|
||||
// rather than prompting for a whole new one.
|
||||
//
|
||||
if (ui.isBatch() || !ui.yesno(false, "Change %s", key)) {
|
||||
return ov;
|
||||
}
|
||||
}
|
||||
|
||||
final String nv = ui.password("%s", key);
|
||||
if (!eq(ov, nv)) {
|
||||
setSecure(password, nv);
|
||||
}
|
||||
return nv;
|
||||
}
|
||||
|
||||
public String getSecure(String name) {
|
||||
return flags.sec.getString(section, subsection, name);
|
||||
}
|
||||
|
Reference in New Issue
Block a user