Skip to content

Use Terminal.readSecret in add string keystore command #126966

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

Merged
merged 4 commits into from
Apr 18, 2025

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Apr 16, 2025

As a followon to #126729, the add string keystore command doesn't need to use a reader at all (and it was incorrect for it to close the reader from the terminal). Instead, the Terminal abstraction already handles how to get at line by line secrets. This commit removes that usage of reader and uses readSecret calls instead.

closes #126882

As a followon to elastic#126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes elastic#126882
@rjernst rjernst added >refactoring :Core/Infra/CLI CLI utilities, scripts, and infrastructure auto-backport Automatically create backport pull requests when merged v8.18.1 v8.19.0 v9.0.1 v9.1.0 labels Apr 16, 2025
@rjernst rjernst requested a review from a team as a code owner April 16, 2025 21:27
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Apr 16, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Contributor

@prdoyle prdoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One optional suggestion.

Comment on lines 54 to 57
String prompt = "";
if (options.has(stdinOption) == false) {
prompt = "Enter value for " + s + ": ";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This style of supplying a default that is sometimes overridden later defeats Java's error detection for paths where the value is not set.

Suggested change
String prompt = "";
if (options.has(stdinOption) == false) {
prompt = "Enter value for " + s + ": ";
}
String prompt;
if (options.has(stdinOption)) {
prompt = "";
} else {
prompt = "Enter value for " + s + ": ";
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied your suggestion.

@rjernst rjernst enabled auto-merge (squash) April 18, 2025 16:49
@rjernst rjernst merged commit 584b237 into elastic:main Apr 18, 2025
15 of 17 checks passed
rjernst added a commit to rjernst/elasticsearch that referenced this pull request Apr 18, 2025
As a followon to elastic#126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes elastic#126882
rjernst added a commit to rjernst/elasticsearch that referenced this pull request Apr 18, 2025
As a followon to elastic#126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes elastic#126882
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.18
8.x
9.0

rjernst added a commit to rjernst/elasticsearch that referenced this pull request Apr 18, 2025
As a followon to elastic#126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes elastic#126882
elasticsearchmachine pushed a commit that referenced this pull request Apr 18, 2025
…7069)

As a followon to #126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes #126882
elasticsearchmachine pushed a commit that referenced this pull request Apr 18, 2025
…7070)

As a followon to #126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes #126882
elasticsearchmachine pushed a commit that referenced this pull request Apr 18, 2025
…7068)

As a followon to #126729, the add string keystore command doesn't need
to use a reader at all (and it was incorrect for it to close the reader
from the terminal). Instead, the Terminal abstraction already handles
how to get at line by line secrets. This commit removes that usage of
reader and uses readSecret calls instead.

closes #126882
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :Core/Infra/CLI CLI utilities, scripts, and infrastructure >refactoring Team:Core/Infra Meta label for core/infra team v8.18.1 v8.19.0 v9.0.1 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CI] AddStringKeyStoreCommandTests testStdinWithMultipleValues failing
3 participants