Skip to content

Commit 142aa9d

Browse files
authored
[RORDEV-1807] Fix ror-tools behavior when consent environement flag is present (#1171)
1 parent 00a5cdb commit 142aa9d

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
publishedPluginVersion=1.67.0
2-
pluginVersion=1.67.0
2+
pluginVersion=1.68.0-pre1
33
pluginName=readonlyrest
44

55
org.gradle.jvmargs=-Xmx6144m

ror-tools/src/main/scala/tech/beshu/ror/tools/RorToolsApp.scala

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,17 @@ trait RorTools {
233233
.action((_, c) => c.copy(command = Some(Command.Unpatch(None))))
234234
.text("unpatch is a command that reverts modifications done by patching")
235235
.children(
236-
esPathOption.action((p, args) => modifyCommand(args, _.asInstanceOf[Command.Unpatch].copy(customEsPath = Some(os.Path(p)))))
236+
esPathOption.action((p, args) => modifyCommand(args, _.asInstanceOf[Command.Unpatch].copy(customEsPath = Some(os.Path(p))))),
237+
patchingConsentDefinition.hidden(), // Accepts patching consent argument, for example passed as env variable, but does not require or use it
237238
)
238239

239240
private lazy val verifyCommand =
240241
cmd("verify")
241242
.action((_, c) => c.copy(command = Some(Command.Verify(None))))
242243
.text("verify is a command that verifies if ES installation is patched")
243244
.children(
244-
esPathOption.action((p, args) => modifyCommand(args, _.asInstanceOf[Command.Verify].copy(customEsPath = Some(os.Path(p)))))
245+
esPathOption.action((p, args) => modifyCommand(args, _.asInstanceOf[Command.Verify].copy(customEsPath = Some(os.Path(p))))),
246+
patchingConsentDefinition.hidden(), // Accepts patching consent argument, for example passed as env variable, but does not require or use it
245247
)
246248

247249
private lazy val esPathOption =
@@ -255,9 +257,7 @@ trait RorTools {
255257
}
256258

257259
private lazy val patchingConsent =
258-
opt[String](consentFlagName)
259-
.unbounded()
260-
.valueName("<yes/no>")
260+
patchingConsentDefinition
261261
.validate { value =>
262262
value.toLowerCase match {
263263
case "yes" => success
@@ -273,6 +273,11 @@ trait RorTools {
273273
}
274274
.text("Optional, when provided with value 'yes', it confirms that the user understands and accepts the implications of ES patching. The patching can therefore be performed. When not provided, user will be asked for confirmation in interactive mode. You can read about patching in our documentation: https://docs.readonlyrest.com/elasticsearch#id-3.-patch-elasticsearch.")
275275

276+
private lazy val patchingConsentDefinition =
277+
opt[String](consentFlagName)
278+
.unbounded()
279+
.valueName("<yes/no>")
280+
276281
private def addPatchingConsentValue(scriptArguments: ScriptArguments, patchingConsent: PatchingConsent) = {
277282
modifyPatchCommand(scriptArguments, patch => patch.copy(patchingConsentValues = patch.patchingConsentValues ::: patchingConsent :: Nil))
278283
}

ror-tools/src/test/scala/tech/beshu/ror/tools/RorToolsAppSuite.scala

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,10 @@ class RorToolsAppSuite
311311
patchMetadataFile.delete()
312312
patchMetadataFile.exists() should be(false)
313313

314-
val (unpatchResult, unpatchOutput) = captureResultAndOutput {
315-
RorToolsTestApp.run(Array("unpatch", "--es-path", esLocalPath.toString))(_, _)
316-
}
314+
val (unpatchResult, unpatchOutput) = captureResultAndOutput(
315+
RorToolsTestApp.run(Array("unpatch", "--es-path", esLocalPath.toString))(_, _),
316+
mockedEnvs = Map("I_UNDERSTAND_AND_ACCEPT_ES_PATCHING" -> "yes") // Additionally verifies, that `unpatch` can be executed when env consent is present
317+
)
317318
unpatchResult should equal(Result.Failure)
318319
unpatchOutput.replace("\r\n", "\n") should include(
319320
"""Checking if Elasticsearch is patched ...
@@ -342,9 +343,10 @@ class RorToolsAppSuite
342343
}
343344
"Verify correctly recognizes that patch is not applied" in {
344345
patchMetadataFile.exists() should be(false)
345-
val (verifyResult, verifyOutput) = captureResultAndOutput {
346-
RorToolsTestApp.run(Array("verify", "--es-path", esLocalPath.toString))(_, _)
347-
}
346+
val (verifyResult, verifyOutput) = captureResultAndOutput(
347+
RorToolsTestApp.run(Array("verify", "--es-path", esLocalPath.toString))(_, _),
348+
mockedEnvs = Map("I_UNDERSTAND_AND_ACCEPT_ES_PATCHING" -> "yes") // Additionally verifies, that `verify` can be executed when env consent is present
349+
)
348350
verifyResult should equal(Result.Failure)
349351
verifyOutput should include(
350352
"""Checking if Elasticsearch is patched ...

0 commit comments

Comments
 (0)