File tree Expand file tree Collapse file tree 1 file changed +28
-8
lines changed
src/main/kotlin/com/coder/toolbox/cli Expand file tree Collapse file tree 1 file changed +28
-8
lines changed Original file line number Diff line number Diff line change @@ -213,16 +213,36 @@ class CoderCLIManager(
213213 gpgVerifier.verifySignature(cliResult.dst, signatureResult.dst).let { result ->
214214 when {
215215 result.isValid() -> return true
216- result.isInvalid() -> {
217- val reason = (result as Invalid ).reason
218- throw UnsignedBinaryExecutionDeniedException (
219- " Signature of ${cliResult.dst} is invalid." + reason?.let { " Reason: $it " }.orEmpty()
220- )
216+ else -> {
217+ // remove the cli, otherwise next time the user tries to login the cached cli is picked up,
218+ // and we don't verify cached cli signatures
219+ runCatching { Files .delete(cliResult.dst) }
220+ .onFailure { ex ->
221+ context.logger.warn(ex, " Failed to delete CLI file: ${cliResult.dst} " )
222+ }
223+
224+ val exception = when {
225+ result.isInvalid() -> {
226+ val reason = (result as Invalid ).reason
227+ UnsignedBinaryExecutionDeniedException (
228+ " Signature of ${cliResult.dst} is invalid." + reason?.let { " Reason: $it " }.orEmpty()
229+ )
230+ }
231+
232+ result.signatureIsNotFound() -> {
233+ UnsignedBinaryExecutionDeniedException (
234+ " Can't verify signature of ${cliResult.dst} because ${signatureResult.dst} does not exist"
235+ )
236+ }
237+
238+ else -> {
239+ UnsignedBinaryExecutionDeniedException ((result as Failed ).error.message)
240+ }
241+ }
242+ throw exception
221243 }
222-
223- result.signatureIsNotFound() -> throw UnsignedBinaryExecutionDeniedException (" Can't verify signature of ${cliResult.dst} because ${signatureResult.dst} does not exist" )
224- else -> throw UnsignedBinaryExecutionDeniedException ((result as Failed ).error.message)
225244 }
245+
226246 }
227247 }
228248
You can’t perform that action at this time.
0 commit comments