-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove Watcher Account "unsecure" settings #36736
Merged
albertzaharovits
merged 12 commits into
elastic:master
from
albertzaharovits:remove_watcher_secure_settings
Jan 20, 2019
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e6ce4a2
Done!
albertzaharovits ac53fb9
Done, but no docs
albertzaharovits 444b715
Merge branch 'master' into remove_watcher_secure_settings
albertzaharovits 73e9282
Docs
albertzaharovits 3aac147
Forgot about slack
albertzaharovits cf102df
Merge branch 'master' into remove_watcher_secure_settings
albertzaharovits a284719
Merge branch 'master' into remove_watcher_secure_settings
albertzaharovits 1e48dd0
Fix tests
albertzaharovits 25fde98
Checkstyle
albertzaharovits b080066
Fix tests
albertzaharovits 66bd17e
Unused imports
albertzaharovits a4d4354
x-pack/qa/smoke-test-watcher-with-security
albertzaharovits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ | |
package org.elasticsearch.xpack.watcher.notification.jira; | ||
|
||
import org.elasticsearch.common.Booleans; | ||
import org.elasticsearch.common.Strings; | ||
import org.elasticsearch.common.bytes.BytesReference; | ||
import org.elasticsearch.common.settings.SecureSetting; | ||
import org.elasticsearch.common.settings.SecureString; | ||
|
@@ -42,15 +41,12 @@ public class JiraAccount { | |
**/ | ||
public static final String DEFAULT_PATH = "/rest/api/2/issue"; | ||
|
||
static final String USER_SETTING = "user"; | ||
static final String PASSWORD_SETTING = "password"; | ||
static final String URL_SETTING = "url"; | ||
static final String ISSUE_DEFAULTS_SETTING = "issue_defaults"; | ||
static final String ALLOW_HTTP_SETTING = "allow_http"; | ||
|
||
private static final Setting<SecureString> SECURE_USER_SETTING = SecureSetting.secureString("secure_" + USER_SETTING, null); | ||
private static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_" + PASSWORD_SETTING, null); | ||
private static final Setting<SecureString> SECURE_URL_SETTING = SecureSetting.secureString("secure_" + URL_SETTING, null); | ||
public static final Setting<SecureString> SECURE_USER_SETTING = SecureSetting.secureString("secure_user", null); | ||
public static final Setting<SecureString> SECURE_PASSWORD_SETTING = SecureSetting.secureString("secure_password", null); | ||
public static final Setting<SecureString> SECURE_URL_SETTING = SecureSetting.secureString("secure_url", null); | ||
|
||
private final HttpClient httpClient; | ||
private final String name; | ||
|
@@ -62,7 +58,7 @@ public class JiraAccount { | |
public JiraAccount(String name, Settings settings, HttpClient httpClient) { | ||
this.httpClient = httpClient; | ||
this.name = name; | ||
String url = getSetting(name, URL_SETTING, settings, SECURE_URL_SETTING); | ||
String url = getSetting(name, settings, SECURE_URL_SETTING); | ||
try { | ||
URI uri = new URI(url); | ||
Scheme protocol = Scheme.parse(uri.getScheme()); | ||
|
@@ -71,16 +67,11 @@ public JiraAccount(String name, Settings settings, HttpClient httpClient) { | |
} | ||
this.url = uri; | ||
} catch (URISyntaxException | IllegalArgumentException e) { | ||
throw new SettingsException("invalid jira [" + name + "] account settings. invalid [" + URL_SETTING + "] setting", e); | ||
} | ||
this.user = getSetting(name, USER_SETTING, settings, SECURE_USER_SETTING); | ||
if (Strings.isEmpty(this.user)) { | ||
throw requiredSettingException(name, USER_SETTING); | ||
} | ||
this.password = getSetting(name, PASSWORD_SETTING, settings, SECURE_PASSWORD_SETTING); | ||
if (Strings.isEmpty(this.password)) { | ||
throw requiredSettingException(name, PASSWORD_SETTING); | ||
throw new SettingsException( | ||
"invalid jira [" + name + "] account settings. invalid [" + SECURE_URL_SETTING.getKey() + "] setting", e); | ||
} | ||
this.user = getSetting(name, settings, SECURE_USER_SETTING); | ||
this.password = getSetting(name, settings, SECURE_PASSWORD_SETTING); | ||
try (XContentBuilder builder = XContentBuilder.builder(XContentType.JSON.xContent())) { | ||
builder.startObject(); | ||
settings.getAsSettings(ISSUE_DEFAULTS_SETTING).toXContent(builder, ToXContent.EMPTY_PARAMS); | ||
|
@@ -95,17 +86,12 @@ public JiraAccount(String name, Settings settings, HttpClient httpClient) { | |
} | ||
} | ||
|
||
private static String getSetting(String accountName, String settingName, Settings settings, Setting<SecureString> secureSetting) { | ||
String value = settings.get(settingName); | ||
if (value == null) { | ||
SecureString secureString = secureSetting.get(settings); | ||
if (secureString == null || secureString.length() < 1) { | ||
throw requiredSettingException(accountName, settingName); | ||
} | ||
value = secureString.toString(); | ||
private static String getSetting(String accountName, Settings settings, Setting<SecureString> secureSetting) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like something we could put in Account There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed, but I think that's a job for another PR (see prev comment) |
||
SecureString secureString = secureSetting.get(settings); | ||
if (secureString == null || secureString.length() < 1) { | ||
throw requiredSettingException(accountName, secureSetting.getKey()); | ||
} | ||
|
||
return value; | ||
return secureString.toString(); | ||
} | ||
|
||
public String getName() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems a bit different from the other getSecureSettings that are in the other *Account classes, and somewhat trappy. Why would we be returning null instead of throwing up like we do in the others? I ask because I hope we can consolidate the functionality into only Account, if thats at all possible, instead of having a method that does this validation in every *Account class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hub-cap There is no Account base class. Also I tried to touch as less as possible to make reviewing easier. IMO we should be using the
SecureSetting
from the correspondingService
(EmailService
in this case). But I prefer to leave this for another time. WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds great to me