Skip to content

Commit 82cca7b

Browse files
committed
impl: support for removing the workspace
- calls the coder REST API endpoints to remove a workspace id.
1 parent a254da8 commit 82cca7b

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/main/kotlin/com/coder/toolbox/sdk/CoderRestClient.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,14 @@ open class CoderRestClient(
240240
}
241241

242242
/**
243-
* @throws [APIResponseException].
243+
* @throws [APIResponseException] if issues are encountered during deletion
244244
*/
245245
fun removeWorkspace(workspace: Workspace) {
246-
// TODO - implement this
246+
val buildRequest = CreateWorkspaceBuildRequest(null, WorkspaceTransition.DELETE, false)
247+
val buildResponse = retroRestClient.createWorkspaceBuild(workspace.id, buildRequest).execute()
248+
if (buildResponse.code() != HttpURLConnection.HTTP_CREATED) {
249+
throw APIResponseException("delete workspace ${workspace.name}", url, buildResponse)
250+
}
247251
}
248252

249253
/**

src/main/kotlin/com/coder/toolbox/sdk/v2/models/CreateWorkspaceBuildRequest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import java.util.UUID
88
data class CreateWorkspaceBuildRequest(
99
// Use to update the workspace to a new template version.
1010
@Json(name = "template_version_id") val templateVersionID: UUID?,
11-
// Use to start and stop the workspace.
11+
// Use to start, stop and delete the workspace.
1212
@Json(name = "transition") val transition: WorkspaceTransition,
13+
@Json(name = "orphan") var orphan: Boolean? = null
1314
) {
1415
override fun equals(other: Any?): Boolean {
1516
if (this === other) return true

0 commit comments

Comments
 (0)