@@ -12,6 +12,7 @@ import (
1212)
1313
1414func (api * API ) regenerateGitSSHKey (rw http.ResponseWriter , r * http.Request ) {
15+ ctx := r .Context ()
1516 user := httpmw .UserParam (r )
1617
1718 if ! api .Authorize (r , rbac .ActionUpdate , rbac .ResourceUserData .WithOwner (user .ID .String ())) {
@@ -21,37 +22,37 @@ func (api *API) regenerateGitSSHKey(rw http.ResponseWriter, r *http.Request) {
2122
2223 privateKey , publicKey , err := gitsshkey .Generate (api .SSHKeygenAlgorithm )
2324 if err != nil {
24- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
25+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
2526 Message : "Internal error generating a new SSH keypair." ,
2627 Detail : err .Error (),
2728 })
2829 return
2930 }
3031
31- err = api .Database .UpdateGitSSHKey (r . Context () , database.UpdateGitSSHKeyParams {
32+ err = api .Database .UpdateGitSSHKey (ctx , database.UpdateGitSSHKeyParams {
3233 UserID : user .ID ,
3334 UpdatedAt : database .Now (),
3435 PrivateKey : privateKey ,
3536 PublicKey : publicKey ,
3637 })
3738 if err != nil {
38- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
39+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
3940 Message : "Internal error updating user's git SSH key." ,
4041 Detail : err .Error (),
4142 })
4243 return
4344 }
4445
45- newKey , err := api .Database .GetGitSSHKey (r . Context () , user .ID )
46+ newKey , err := api .Database .GetGitSSHKey (ctx , user .ID )
4647 if err != nil {
47- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
48+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
4849 Message : "Internal error fetching user's git SSH key." ,
4950 Detail : err .Error (),
5051 })
5152 return
5253 }
5354
54- httpapi .Write (rw , http .StatusOK , codersdk.GitSSHKey {
55+ httpapi .Write (ctx , rw , http .StatusOK , codersdk.GitSSHKey {
5556 UserID : newKey .UserID ,
5657 CreatedAt : newKey .CreatedAt ,
5758 UpdatedAt : newKey .UpdatedAt ,
@@ -61,23 +62,24 @@ func (api *API) regenerateGitSSHKey(rw http.ResponseWriter, r *http.Request) {
6162}
6263
6364func (api * API ) gitSSHKey (rw http.ResponseWriter , r * http.Request ) {
65+ ctx := r .Context ()
6466 user := httpmw .UserParam (r )
6567
6668 if ! api .Authorize (r , rbac .ActionRead , rbac .ResourceUserData .WithOwner (user .ID .String ())) {
6769 httpapi .ResourceNotFound (rw )
6870 return
6971 }
7072
71- gitSSHKey , err := api .Database .GetGitSSHKey (r . Context () , user .ID )
73+ gitSSHKey , err := api .Database .GetGitSSHKey (ctx , user .ID )
7274 if err != nil {
73- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
75+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
7476 Message : "Internal error fetching user's SSH key." ,
7577 Detail : err .Error (),
7678 })
7779 return
7880 }
7981
80- httpapi .Write (rw , http .StatusOK , codersdk.GitSSHKey {
82+ httpapi .Write (ctx , rw , http .StatusOK , codersdk.GitSSHKey {
8183 UserID : gitSSHKey .UserID ,
8284 CreatedAt : gitSSHKey .CreatedAt ,
8385 UpdatedAt : gitSSHKey .UpdatedAt ,
@@ -87,44 +89,45 @@ func (api *API) gitSSHKey(rw http.ResponseWriter, r *http.Request) {
8789}
8890
8991func (api * API ) agentGitSSHKey (rw http.ResponseWriter , r * http.Request ) {
92+ ctx := r .Context ()
9093 agent := httpmw .WorkspaceAgent (r )
91- resource , err := api .Database .GetWorkspaceResourceByID (r . Context () , agent .ResourceID )
94+ resource , err := api .Database .GetWorkspaceResourceByID (ctx , agent .ResourceID )
9295 if err != nil {
93- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
96+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
9497 Message : "Internal error fetching workspace resource." ,
9598 Detail : err .Error (),
9699 })
97100 return
98101 }
99102
100- job , err := api .Database .GetWorkspaceBuildByJobID (r . Context () , resource .JobID )
103+ job , err := api .Database .GetWorkspaceBuildByJobID (ctx , resource .JobID )
101104 if err != nil {
102- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
105+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
103106 Message : "Internal error fetching workspace build." ,
104107 Detail : err .Error (),
105108 })
106109 return
107110 }
108111
109- workspace , err := api .Database .GetWorkspaceByID (r . Context () , job .WorkspaceID )
112+ workspace , err := api .Database .GetWorkspaceByID (ctx , job .WorkspaceID )
110113 if err != nil {
111- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
114+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
112115 Message : "Internal error fetching workspace." ,
113116 Detail : err .Error (),
114117 })
115118 return
116119 }
117120
118- gitSSHKey , err := api .Database .GetGitSSHKey (r . Context () , workspace .OwnerID )
121+ gitSSHKey , err := api .Database .GetGitSSHKey (ctx , workspace .OwnerID )
119122 if err != nil {
120- httpapi .Write (rw , http .StatusInternalServerError , codersdk.Response {
123+ httpapi .Write (ctx , rw , http .StatusInternalServerError , codersdk.Response {
121124 Message : "Internal error fetching git SSH key." ,
122125 Detail : err .Error (),
123126 })
124127 return
125128 }
126129
127- httpapi .Write (rw , http .StatusOK , codersdk.AgentGitSSHKey {
130+ httpapi .Write (ctx , rw , http .StatusOK , codersdk.AgentGitSSHKey {
128131 PublicKey : gitSSHKey .PublicKey ,
129132 PrivateKey : gitSSHKey .PrivateKey ,
130133 })
0 commit comments