@Summary Get workspace agent Git SSH key @ID get-workspace-agent-git-ssh-key @Security CoderSessionToken @Produce json @Tags Agents @Success 200 {object} agentsdk.GitSSHKey @Router /api/v2/workspaceagents/me/gitsshkey [get]
(rw http.ResponseWriter, r *http.Request)
| 115 | // @Success 200 {object} agentsdk.GitSSHKey |
| 116 | // @Router /api/v2/workspaceagents/me/gitsshkey [get] |
| 117 | func (api *API) agentGitSSHKey(rw http.ResponseWriter, r *http.Request) { |
| 118 | ctx := r.Context() |
| 119 | agent := httpmw.WorkspaceAgent(r) |
| 120 | resource, err := api.Database.GetWorkspaceResourceByID(ctx, agent.ResourceID) |
| 121 | if err != nil { |
| 122 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 123 | Message: "Internal error fetching workspace resource.", |
| 124 | Detail: err.Error(), |
| 125 | }) |
| 126 | return |
| 127 | } |
| 128 | |
| 129 | job, err := api.Database.GetWorkspaceBuildByJobID(ctx, resource.JobID) |
| 130 | if err != nil { |
| 131 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 132 | Message: "Internal error fetching workspace build.", |
| 133 | Detail: err.Error(), |
| 134 | }) |
| 135 | return |
| 136 | } |
| 137 | |
| 138 | workspace, err := api.Database.GetWorkspaceByID(ctx, job.WorkspaceID) |
| 139 | if err != nil { |
| 140 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 141 | Message: "Internal error fetching workspace.", |
| 142 | Detail: err.Error(), |
| 143 | }) |
| 144 | return |
| 145 | } |
| 146 | |
| 147 | gitSSHKey, err := api.Database.GetGitSSHKey(ctx, workspace.OwnerID) |
| 148 | if httpapi.IsUnauthorizedError(err) { |
| 149 | httpapi.Forbidden(rw) |
| 150 | return |
| 151 | } |
| 152 | if err != nil { |
| 153 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 154 | Message: "Internal error fetching git SSH key.", |
| 155 | Detail: err.Error(), |
| 156 | }) |
| 157 | return |
| 158 | } |
| 159 | |
| 160 | httpapi.Write(ctx, rw, http.StatusOK, agentsdk.GitSSHKey{ |
| 161 | PublicKey: gitSSHKey.PublicKey, |
| 162 | PrivateKey: gitSSHKey.PrivateKey, |
| 163 | }) |
| 164 | } |
nothing calls this directly
no test coverage detected