@@ -159,31 +159,36 @@ class CoderCLIManager(
159
159
* Download the CLI from the deployment if necessary.
160
160
*/
161
161
suspend fun download (buildVersion : String , showTextProgress : (String ) -> Unit ): Boolean {
162
- val cliDownloadResult = withContext(Dispatchers .IO ) {
162
+ val cliResult = withContext(Dispatchers .IO ) {
163
163
downloader.downloadCli(buildVersion, showTextProgress)
164
+ }.let { result ->
165
+ when {
166
+ result.isSkipped() -> return false
167
+ result.isNotFoundOrFailed() -> throw IllegalStateException (" Could not find or download Coder CLI" )
168
+ else -> result as Downloaded
169
+ }
164
170
}
165
- if (cliDownloadResult.isSkipped()) return false
166
- if (cliDownloadResult.isNotFoundOrFailed()) throw IllegalStateException (" Could not find or download Coder CLI" )
167
171
168
- var singatureDownloadResult = withContext(Dispatchers .IO ) {
172
+ var signatureDownloadResult = withContext(Dispatchers .IO ) {
169
173
downloader.downloadSignature(showTextProgress)
170
174
}
171
175
172
- if (singatureDownloadResult .isNotDownloaded()) {
176
+ if (signatureDownloadResult .isNotDownloaded()) {
173
177
context.logger.info(" Trying to download signature file from releases.coder.com" )
174
- singatureDownloadResult = downloader.downloadReleasesSignature(showTextProgress)
178
+ signatureDownloadResult = withContext(Dispatchers .IO ) {
179
+ downloader.downloadReleasesSignature(showTextProgress)
180
+ }
175
181
}
176
182
177
183
// if we could not find any signature and the user wants to explicitly
178
184
// confirm whether we run an unsigned cli
179
- if (singatureDownloadResult.isNotDownloaded()) {
180
- val cli = cliDownloadResult as Downloaded
185
+ if (signatureDownloadResult.isNotDownloaded()) {
181
186
if (context.settingsStore.allowUnsignedBinaryWithoutPrompt) {
182
- context.logger.warn(" Running unsigned CLI from ${cli .source} " )
187
+ context.logger.warn(" Running unsigned CLI from ${cliResult .source} " )
183
188
} else {
184
189
val acceptsUnsignedBinary = context.ui.showYesNoPopup(
185
190
context.i18n.ptrl(" Security Warning" ),
186
- context.i18n.pnotr(" Can't verify the integrity of the Coder CLI pulled from ${cli .source} " ),
191
+ context.i18n.pnotr(" Can't verify the integrity of the Coder CLI pulled from ${cliResult .source} " ),
187
192
context.i18n.ptrl(" Accept" ),
188
193
context.i18n.ptrl(" Abort" ),
189
194
)
@@ -193,13 +198,13 @@ class CoderCLIManager(
193
198
} else {
194
199
// remove the cli, otherwise next time the user tries to login the cached cli is picked up
195
200
// and we don't verify cached cli signatures
196
- Files .delete(cli .dst)
197
- throw UnsignedBinaryExecutionDeniedException (" Running unsigned CLI from ${cli .source} was denied by the user" )
201
+ Files .delete(cliResult .dst)
202
+ throw UnsignedBinaryExecutionDeniedException (" Running unsigned CLI from ${cliResult .source} was denied by the user" )
198
203
}
199
204
}
200
205
}
201
206
202
- return cliDownloadResult .isDownloaded()
207
+ return cliResult .isDownloaded()
203
208
}
204
209
205
210
/* *
0 commit comments