Skip to content

Commit 9a477f7

Browse files
authored
Rename environment dir accessors (#121803) (#121834)
The node environment has many paths. The accessors for these currently use a "file" suffix, but they are always directories. This commit renames the accessors to make it clear these paths are directories.
1 parent b544227 commit 9a477f7

File tree

128 files changed

+520
-528
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+520
-528
lines changed

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddFileKeyStoreCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected void executeCommand(Terminal terminal, OptionSet options, Environment
7474
keyStore.setFile(setting, Files.readAllBytes(file));
7575
}
7676

77-
keyStore.save(env.configFile(), getKeyStorePassword().getChars());
77+
keyStore.save(env.configDir(), getKeyStorePassword().getChars());
7878
}
7979

8080
@SuppressForbidden(reason = "file arg for cli")

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/AddStringKeyStoreCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ protected void executeCommand(Terminal terminal, OptionSet options, Environment
100100
}
101101
}
102102

103-
keyStore.save(env.configFile(), getKeyStorePassword().getChars());
103+
keyStore.save(env.configDir(), getKeyStorePassword().getChars());
104104
}
105105

106106
}

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/BaseKeyStoreCommand.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public BaseKeyStoreCommand(String description, boolean keyStoreMustExist) {
3939
@Override
4040
public final void execute(Terminal terminal, OptionSet options, Environment env, ProcessInfo processInfo) throws Exception {
4141
try {
42-
final Path configFile = env.configFile();
42+
final Path configFile = env.configDir();
4343
keyStore = KeyStoreWrapper.load(configFile);
4444
if (keyStore == null) {
4545
if (keyStoreMustExist) {
4646
throw new UserException(
4747
ExitCodes.DATA_ERROR,
4848
"Elasticsearch keystore not found at ["
49-
+ KeyStoreWrapper.keystorePath(env.configFile())
49+
+ KeyStoreWrapper.keystorePath(env.configDir())
5050
+ "]. Use 'create' command to create one."
5151
);
5252
} else if (options.has(forceOption) == false) {

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/ChangeKeyStorePasswordCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ChangeKeyStorePasswordCommand extends BaseKeyStoreCommand {
3131
protected void executeCommand(Terminal terminal, OptionSet options, Environment env) throws Exception {
3232
try (SecureString newPassword = readPassword(terminal, true)) {
3333
final KeyStoreWrapper keyStore = getKeyStore();
34-
keyStore.save(env.configFile(), newPassword.getChars());
34+
keyStore.save(env.configDir(), newPassword.getChars());
3535
terminal.println("Elasticsearch keystore password changed successfully.");
3636
} catch (SecurityException e) {
3737
throw new UserException(ExitCodes.DATA_ERROR, e.getMessage());

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/CreateKeyStoreCommand.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,16 @@ class CreateKeyStoreCommand extends KeyStoreAwareCommand {
4040
@Override
4141
public void execute(Terminal terminal, OptionSet options, Environment env, ProcessInfo processInfo) throws Exception {
4242
try (SecureString password = options.has(passwordOption) ? readPassword(terminal, true) : new SecureString(new char[0])) {
43-
Path keystoreFile = KeyStoreWrapper.keystorePath(env.configFile());
43+
Path keystoreFile = KeyStoreWrapper.keystorePath(env.configDir());
4444
if (Files.exists(keystoreFile)) {
4545
if (terminal.promptYesNo("An elasticsearch keystore already exists. Overwrite?", false) == false) {
4646
terminal.println("Exiting without creating keystore.");
4747
return;
4848
}
4949
}
5050
KeyStoreWrapper keystore = KeyStoreWrapper.create();
51-
keystore.save(env.configFile(), password.getChars());
52-
terminal.println("Created elasticsearch keystore in " + KeyStoreWrapper.keystorePath(env.configFile()));
51+
keystore.save(env.configDir(), password.getChars());
52+
terminal.println("Created elasticsearch keystore in " + KeyStoreWrapper.keystorePath(env.configDir()));
5353
} catch (SecurityException e) {
5454
throw new UserException(ExitCodes.IO_ERROR, "Error creating the elasticsearch keystore.");
5555
}

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/HasPasswordKeyStoreCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class HasPasswordKeyStoreCommand extends KeyStoreAwareCommand {
3232

3333
@Override
3434
public void execute(Terminal terminal, OptionSet options, Environment env, ProcessInfo processInfo) throws Exception {
35-
final Path configFile = env.configFile();
35+
final Path configFile = env.configDir();
3636
final KeyStoreWrapper keyStore = KeyStoreWrapper.load(configFile);
3737

3838
// We handle error printing here so we can respect the "--silent" flag

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/RemoveSettingKeyStoreCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ protected void executeCommand(Terminal terminal, OptionSet options, Environment
4545
}
4646
keyStore.remove(setting);
4747
}
48-
keyStore.save(env.configFile(), getKeyStorePassword().getChars());
48+
keyStore.save(env.configDir(), getKeyStorePassword().getChars());
4949
}
5050
}

distribution/tools/keystore-cli/src/main/java/org/elasticsearch/cli/keystore/UpgradeKeyStoreCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class UpgradeKeyStoreCommand extends BaseKeyStoreCommand {
2626

2727
@Override
2828
protected void executeCommand(final Terminal terminal, final OptionSet options, final Environment env) throws Exception {
29-
KeyStoreWrapper.upgrade(getKeyStore(), env.configFile(), getKeyStorePassword().getChars());
29+
KeyStoreWrapper.upgrade(getKeyStore(), env.configDir(), getKeyStorePassword().getChars());
3030
}
3131

3232
}

distribution/tools/keystore-cli/src/test/java/org/elasticsearch/cli/keystore/AddFileKeyStoreCommandTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,14 @@ private Path createRandomFile() throws IOException {
4646
for (int i = 0; i < length; ++i) {
4747
bytes[i] = randomByte();
4848
}
49-
Path file = env.configFile().resolve(randomAlphaOfLength(16));
49+
Path file = env.configDir().resolve(randomAlphaOfLength(16));
5050
Files.write(file, bytes);
5151
return file;
5252
}
5353

5454
private void addFile(KeyStoreWrapper keystore, String setting, Path file, String password) throws Exception {
5555
keystore.setFile(setting, Files.readAllBytes(file));
56-
keystore.save(env.configFile(), password.toCharArray());
56+
keystore.save(env.configDir(), password.toCharArray());
5757
}
5858

5959
public void testMissingCreateWithEmptyPasswordWhenPrompted() throws Exception {
@@ -77,7 +77,7 @@ public void testMissingNoCreate() throws Exception {
7777
terminal.addSecretInput(randomFrom("", "keystorepassword"));
7878
terminal.addTextInput("n"); // explicit no
7979
execute("foo");
80-
assertNull(KeyStoreWrapper.load(env.configFile()));
80+
assertNull(KeyStoreWrapper.load(env.configDir()));
8181
}
8282

8383
public void testOverwritePromptDefault() throws Exception {

distribution/tools/keystore-cli/src/test/java/org/elasticsearch/cli/keystore/AddStringKeyStoreCommandTests.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testMissingPromptCreateWithoutPasswordWithoutPromptIfForced() throws
8383
public void testMissingNoCreate() throws Exception {
8484
terminal.addTextInput("n"); // explicit no
8585
execute("foo");
86-
assertNull(KeyStoreWrapper.load(env.configFile()));
86+
assertNull(KeyStoreWrapper.load(env.configDir()));
8787
}
8888

8989
public void testOverwritePromptDefault() throws Exception {
@@ -143,7 +143,7 @@ public void testForceNonExistent() throws Exception {
143143

144144
public void testPromptForValue() throws Exception {
145145
String password = "keystorepassword";
146-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
146+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
147147
terminal.addSecretInput(password);
148148
terminal.addSecretInput("secret value");
149149
execute("foo");
@@ -152,7 +152,7 @@ public void testPromptForValue() throws Exception {
152152

153153
public void testPromptForMultipleValues() throws Exception {
154154
final String password = "keystorepassword";
155-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
155+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
156156
terminal.addSecretInput(password);
157157
terminal.addSecretInput("bar1");
158158
terminal.addSecretInput("bar2");
@@ -165,7 +165,7 @@ public void testPromptForMultipleValues() throws Exception {
165165

166166
public void testStdinShort() throws Exception {
167167
String password = "keystorepassword";
168-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
168+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
169169
terminal.addSecretInput(password);
170170
setInput("secret value 1");
171171
execute("-x", "foo");
@@ -174,7 +174,7 @@ public void testStdinShort() throws Exception {
174174

175175
public void testStdinLong() throws Exception {
176176
String password = "keystorepassword";
177-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
177+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
178178
terminal.addSecretInput(password);
179179
setInput("secret value 2");
180180
execute("--stdin", "foo");
@@ -183,7 +183,7 @@ public void testStdinLong() throws Exception {
183183

184184
public void testStdinNoInput() throws Exception {
185185
String password = "keystorepassword";
186-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
186+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
187187
terminal.addSecretInput(password);
188188
setInput("");
189189
execute("-x", "foo");
@@ -192,7 +192,7 @@ public void testStdinNoInput() throws Exception {
192192

193193
public void testStdinInputWithLineBreaks() throws Exception {
194194
String password = "keystorepassword";
195-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
195+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
196196
terminal.addSecretInput(password);
197197
setInput("Typedthisandhitenter\n");
198198
execute("-x", "foo");
@@ -201,7 +201,7 @@ public void testStdinInputWithLineBreaks() throws Exception {
201201

202202
public void testStdinInputWithCarriageReturn() throws Exception {
203203
String password = "keystorepassword";
204-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
204+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
205205
terminal.addSecretInput(password);
206206
setInput("Typedthisandhitenter\r");
207207
execute("-x", "foo");
@@ -210,7 +210,7 @@ public void testStdinInputWithCarriageReturn() throws Exception {
210210

211211
public void testStdinWithMultipleValues() throws Exception {
212212
final String password = "keystorepassword";
213-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
213+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
214214
terminal.addSecretInput(password);
215215
setInput("bar1\nbar2\nbar3");
216216
execute(randomFrom("-x", "--stdin"), "foo1", "foo2", "foo3");
@@ -221,7 +221,7 @@ public void testStdinWithMultipleValues() throws Exception {
221221

222222
public void testAddUtf8String() throws Exception {
223223
String password = "keystorepassword";
224-
KeyStoreWrapper.create().save(env.configFile(), password.toCharArray());
224+
KeyStoreWrapper.create().save(env.configDir(), password.toCharArray());
225225
terminal.addSecretInput(password);
226226
final int stringSize = randomIntBetween(8, 16);
227227
try (CharArrayWriter secretChars = new CharArrayWriter(stringSize)) {

distribution/tools/keystore-cli/src/test/java/org/elasticsearch/cli/keystore/BootstrapTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void setupEnv() throws IOException {
4242

4343
public void testLoadSecureSettings() throws Exception {
4444
final char[] password = KeyStoreWrapperTests.getPossibleKeystorePassword();
45-
final Path configPath = env.configFile();
45+
final Path configPath = env.configDir();
4646
final SecureString seed;
4747
try (KeyStoreWrapper keyStoreWrapper = KeyStoreWrapper.create()) {
4848
seed = KeyStoreWrapper.SEED_SETTING.get(Settings.builder().setSecureSettings(keyStoreWrapper).build());

distribution/tools/keystore-cli/src/test/java/org/elasticsearch/cli/keystore/CreateKeyStoreCommandTests.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void testNotMatchingPasswords() throws Exception {
4848
public void testDefaultNotPromptForPassword() throws Exception {
4949
assumeFalse("Cannot open unprotected keystore on FIPS JVM", inFipsJvm());
5050
execute();
51-
Path configDir = env.configFile();
51+
Path configDir = env.configDir();
5252
assertNotNull(KeyStoreWrapper.load(configDir));
5353
}
5454

@@ -63,7 +63,7 @@ public void testPosix() throws Exception {
6363
} else {
6464
execute();
6565
}
66-
Path configDir = env.configFile();
66+
Path configDir = env.configDir();
6767
assertNotNull(KeyStoreWrapper.load(configDir));
6868
}
6969

@@ -79,13 +79,13 @@ public void testNotPosix() throws Exception {
7979
} else {
8080
execute();
8181
}
82-
Path configDir = env.configFile();
82+
Path configDir = env.configDir();
8383
assertNotNull(KeyStoreWrapper.load(configDir));
8484
}
8585

8686
public void testOverwrite() throws Exception {
8787
String password = getPossibleKeystorePassword();
88-
Path keystoreFile = KeyStoreWrapper.keystorePath(env.configFile());
88+
Path keystoreFile = KeyStoreWrapper.keystorePath(env.configDir());
8989
byte[] content = "not a keystore".getBytes(StandardCharsets.UTF_8);
9090
Files.write(keystoreFile, content);
9191

@@ -110,6 +110,6 @@ public void testOverwrite() throws Exception {
110110
} else {
111111
execute();
112112
}
113-
assertNotNull(KeyStoreWrapper.load(env.configFile()));
113+
assertNotNull(KeyStoreWrapper.load(env.configDir()));
114114
}
115115
}

distribution/tools/keystore-cli/src/test/java/org/elasticsearch/cli/keystore/KeyStoreCommandTestCase.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ KeyStoreWrapper createKeystore(String password, String... settings) throws Excep
7777
}
7878

7979
void saveKeystore(KeyStoreWrapper keystore, String password) throws Exception {
80-
keystore.save(env.configFile(), password.toCharArray());
80+
keystore.save(env.configDir(), password.toCharArray());
8181
}
8282

8383
KeyStoreWrapper loadKeystore(String password) throws Exception {
84-
KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configFile());
84+
KeyStoreWrapper keystore = KeyStoreWrapper.load(env.configDir());
8585
keystore.decrypt(password.toCharArray());
8686
return keystore;
8787
}

0 commit comments

Comments
 (0)