Skip to content

Commit 1d43fec

Browse files
committed
Data models & REST calls for coder V2
1 parent 02d98cd commit 1d43fec

File tree

8 files changed

+142
-0
lines changed

8 files changed

+142
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.coder.gateway.sdk.v2
2+
3+
import com.coder.gateway.sdk.v2.models.AgentGitSSHKeys
4+
import com.coder.gateway.sdk.v2.models.LoginWithPasswordRequest
5+
import com.coder.gateway.sdk.v2.models.LoginWithPasswordResponse
6+
import com.coder.gateway.sdk.v2.models.User
7+
import com.coder.gateway.sdk.v2.models.Workspace
8+
import retrofit2.Call
9+
import retrofit2.http.Body
10+
import retrofit2.http.GET
11+
import retrofit2.http.Header
12+
import retrofit2.http.POST
13+
14+
interface CoderV2RestFacade {
15+
16+
/**
17+
* Retrieves a session token authenticating with an email and password.
18+
*/
19+
@POST("api/v2/users/login")
20+
fun authenticate(@Body loginRequest: LoginWithPasswordRequest): Call<LoginWithPasswordResponse>
21+
22+
/**
23+
* Retrieves details about the authenticated user.
24+
*/
25+
@GET("api/v2/users/me")
26+
fun me(@Header("Session-Token") sessionToken: String): Call<User>
27+
28+
/**
29+
* Retrieves all workspaces the authenticated user has access to.
30+
*/
31+
@GET("api/v2/workspaces")
32+
fun workspaces(@Header("Session-Token") sessionToken: String): Call<List<Workspace>>
33+
34+
@GET("api/v2/workspaceagents/me/gitsshkey")
35+
fun sshKeys(@Header("Session-Token") sessionToken: String): Call<AgentGitSSHKeys>
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
data class AgentGitSSHKeys(@SerializedName("public_key") val publicKey: String, @SerializedName("private_key") val privateKey: String)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* Enables callers to authenticate with email and password.
7+
*/
8+
data class LoginWithPasswordRequest(
9+
@SerializedName("email") val email: String,
10+
@SerializedName("password") val password: String
11+
)
12+
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
5+
/**
6+
* contains a session token for the newly authenticated user.
7+
*/
8+
data class LoginWithPasswordResponse(@SerializedName("session_token") val sessionToken: String)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
import java.time.Instant
5+
import java.util.UUID
6+
7+
data class ProvisionerJob(
8+
@SerializedName("id") val id: UUID,
9+
@SerializedName("created_at") val createdAt: Instant,
10+
@SerializedName("started_at") val startedAt: Instant,
11+
@SerializedName("completed_at") val completedAt: Instant,
12+
@SerializedName("error") val error: String,
13+
@SerializedName("status") val status: String,
14+
@SerializedName("worker_id") val workerID: UUID,
15+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
import java.time.Instant
5+
import java.util.UUID
6+
7+
data class User(
8+
@SerializedName("id") val id: UUID,
9+
@SerializedName("email") val email: String,
10+
@SerializedName("username") val username: String,
11+
@SerializedName("created_at") val createdAt: Instant,
12+
13+
@SerializedName("status") val status: String?,
14+
@SerializedName("organization_ids") val organizationIDs: List<UUID>?,
15+
@SerializedName("roles") val roles: Set<String>?,
16+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
import java.time.Duration
5+
import java.time.Instant
6+
import java.util.UUID
7+
8+
/**
9+
* Represents a deployment of a template. It references a specific version and can be updated.
10+
*/
11+
data class Workspace(
12+
@SerializedName("id") val id: UUID,
13+
@SerializedName("created_at") val createdAt: Instant,
14+
@SerializedName("updated_at") val updatedAt: Instant,
15+
@SerializedName("owner_id") val ownerID: UUID,
16+
@SerializedName("owner_name") val ownerName: String,
17+
@SerializedName("template_id") val templateID: UUID,
18+
@SerializedName("template_name") val templateName: String,
19+
@SerializedName("latest_build") val latestBuild: WorkspaceBuild,
20+
@SerializedName("outdated") val outdated: Boolean,
21+
@SerializedName("name") val name: String,
22+
@SerializedName("autostart_schedule") val autostartSchedule: String,
23+
@SerializedName("ttl") val ttl: Duration,
24+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.coder.gateway.sdk.v2.models
2+
3+
import com.google.gson.annotations.SerializedName
4+
import java.time.Instant
5+
import java.util.UUID
6+
7+
/**
8+
* WorkspaceBuild is an at-point representation of a workspace state.
9+
* BuildNumbers start at 1 and increase by 1 for each subsequent build.
10+
*/
11+
data class WorkspaceBuild(
12+
@SerializedName("id") val id: UUID,
13+
@SerializedName("created_at") val createdAt: Instant,
14+
@SerializedName("updated_at") val updatedAt: Instant,
15+
@SerializedName("workspace_id") val workspaceID: UUID,
16+
@SerializedName("template_version_id") val templateVersionID: UUID,
17+
@SerializedName("build_number") val buildNumber: Int,
18+
@SerializedName("name") val name: String,
19+
@SerializedName("transition") val workspaceTransition: String,
20+
@SerializedName("owner_id") val ownerID: UUID,
21+
@SerializedName("initiator_id") val initiatorID: UUID,
22+
@SerializedName("job") val job: ProvisionerJob,
23+
@SerializedName("deadline") val deadline: Instant,
24+
)
25+

0 commit comments

Comments
 (0)