Skip to content

Commit 8f90af4

Browse files
committed
Use %q over %s
1 parent 6ef1647 commit 8f90af4

11 files changed

+41
-40
lines changed

coderd/authorize.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ func AuthorizeFilter[O rbac.Objecter](api *API, r *http.Request, action rbac.Act
2222
// Eg:
2323
// if !api.Authorize(...) {
2424
// httpapi.Forbidden(rw)
25+
// return
2526
// }
2627
func (api *API) Authorize(r *http.Request, action rbac.Action, object rbac.Objecter) bool {
2728
roles := httpmw.AuthorizationUserRoles(r)

coderd/files.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (api *API) fileByHash(rw http.ResponseWriter, r *http.Request) {
8787
}
8888
file, err := api.Database.GetFileByHash(r.Context(), hash)
8989
if errors.Is(err, sql.ErrNoRows) {
90-
httpapi.ResourceNotFound(rw, fmt.Sprintf("File %s", hash))
90+
httpapi.ResourceNotFound(rw, fmt.Sprintf("File %q", hash))
9191
return
9292
}
9393
if err != nil {
@@ -101,7 +101,7 @@ func (api *API) fileByHash(rw http.ResponseWriter, r *http.Request) {
101101
if !api.Authorize(r, rbac.ActionRead,
102102
rbac.ResourceFile.WithOwner(file.CreatedBy.String()).WithID(file.Hash)) {
103103
// Return 404 to not leak the file exists
104-
httpapi.ResourceNotFound(rw, fmt.Sprintf("File %s", hash))
104+
httpapi.ResourceNotFound(rw, fmt.Sprintf("File %q", hash))
105105
return
106106
}
107107

coderd/httpmw/templateparam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func ExtractTemplateParam(db database.Store) func(http.Handler) http.Handler {
4747
}
4848

4949
if template.Deleted {
50-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", templateID))
50+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", templateID))
5151
return
5252
}
5353

coderd/httpmw/templateversionparam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func ExtractTemplateVersionParam(db database.Store) func(http.Handler) http.Hand
3434
}
3535
templateVersion, err := db.GetTemplateVersionByID(r.Context(), templateVersionID)
3636
if errors.Is(err, sql.ErrNoRows) {
37-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersionID))
37+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersionID))
3838
return
3939
}
4040
if err != nil {

coderd/httpmw/workspaceparam.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func ExtractWorkspaceParam(db database.Store) func(http.Handler) http.Handler {
3232
}
3333
workspace, err := db.GetWorkspaceByID(r.Context(), workspaceID)
3434
if errors.Is(err, sql.ErrNoRows) {
35-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspaceID))
35+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspaceID))
3636
return
3737
}
3838
if err != nil {

coderd/organizations_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestOrganizationByUserAndName(t *testing.T) {
4545
_, err = other.OrganizationByName(context.Background(), codersdk.Me, org.Name)
4646
var apiErr *codersdk.Error
4747
require.ErrorAs(t, err, &apiErr)
48-
require.Equal(t, http.StatusForbidden, apiErr.StatusCode())
48+
require.Equal(t, http.StatusNotFound, apiErr.StatusCode())
4949
})
5050

5151
t.Run("Valid", func(t *testing.T) {

coderd/parameters.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (api *API) deleteParameter(rw http.ResponseWriter, r *http.Request) {
124124
}
125125
// A deleted param is still updating the underlying resource for the scope.
126126
if !api.Authorize(r, rbac.ActionUpdate, obj) {
127-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Parameter %s with scope %s", scopeID, scope))
127+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Parameter %q with scope %q", scopeID, scope))
128128
return
129129
}
130130

@@ -135,7 +135,7 @@ func (api *API) deleteParameter(rw http.ResponseWriter, r *http.Request) {
135135
Name: name,
136136
})
137137
if errors.Is(err, sql.ErrNoRows) {
138-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Parameter %s with scope %s", scopeID, scope))
138+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Parameter %q with scope %q", scopeID, scope))
139139
return
140140
}
141141
if err != nil {

coderd/templates.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (api *API) template(rw http.ResponseWriter, r *http.Request) {
2929
template := httpmw.TemplateParam(r)
3030

3131
if !api.Authorize(r, rbac.ActionRead, template) {
32-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", template.ID))
32+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", template.ID))
3333
return
3434
}
3535

@@ -56,7 +56,7 @@ func (api *API) template(rw http.ResponseWriter, r *http.Request) {
5656
func (api *API) deleteTemplate(rw http.ResponseWriter, r *http.Request) {
5757
template := httpmw.TemplateParam(r)
5858
if !api.Authorize(r, rbac.ActionDelete, template) {
59-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", template.ID))
59+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", template.ID))
6060
return
6161
}
6262

@@ -273,7 +273,7 @@ func (api *API) templateByOrganizationAndName(rw http.ResponseWriter, r *http.Re
273273
})
274274
if err != nil {
275275
if errors.Is(err, sql.ErrNoRows) {
276-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s in organization %s", templateName, organization.Name))
276+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q in organization %q", templateName, organization.Name))
277277
return
278278
}
279279

@@ -285,7 +285,7 @@ func (api *API) templateByOrganizationAndName(rw http.ResponseWriter, r *http.Re
285285
}
286286

287287
if !api.Authorize(r, rbac.ActionRead, template) {
288-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s in organization %s", templateName, organization.Name))
288+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q in organization %q", templateName, organization.Name))
289289
return
290290
}
291291

@@ -312,7 +312,7 @@ func (api *API) templateByOrganizationAndName(rw http.ResponseWriter, r *http.Re
312312
func (api *API) patchTemplateMeta(rw http.ResponseWriter, r *http.Request) {
313313
template := httpmw.TemplateParam(r)
314314
if !api.Authorize(r, rbac.ActionUpdate, template) {
315-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", template.ID))
315+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", template.ID))
316316
return
317317
}
318318

coderd/templateversions.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
func (api *API) templateVersion(rw http.ResponseWriter, r *http.Request) {
2424
templateVersion := httpmw.TemplateVersionParam(r)
2525
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
26-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
26+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
2727
return
2828
}
2929

@@ -42,7 +42,7 @@ func (api *API) templateVersion(rw http.ResponseWriter, r *http.Request) {
4242
func (api *API) patchCancelTemplateVersion(rw http.ResponseWriter, r *http.Request) {
4343
templateVersion := httpmw.TemplateVersionParam(r)
4444
if !api.Authorize(r, rbac.ActionUpdate, templateVersion) {
45-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
45+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
4646
return
4747
}
4848

@@ -88,7 +88,7 @@ func (api *API) patchCancelTemplateVersion(rw http.ResponseWriter, r *http.Reque
8888
func (api *API) templateVersionSchema(rw http.ResponseWriter, r *http.Request) {
8989
templateVersion := httpmw.TemplateVersionParam(r)
9090
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
91-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
91+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
9292
return
9393
}
9494

@@ -136,7 +136,7 @@ func (api *API) templateVersionParameters(rw http.ResponseWriter, r *http.Reques
136136
apiKey := httpmw.APIKey(r)
137137
templateVersion := httpmw.TemplateVersionParam(r)
138138
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
139-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
139+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
140140
return
141141
}
142142

@@ -180,7 +180,7 @@ func (api *API) postTemplateVersionDryRun(rw http.ResponseWriter, r *http.Reques
180180
apiKey := httpmw.APIKey(r)
181181
templateVersion := httpmw.TemplateVersionParam(r)
182182
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
183-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
183+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
184184
return
185185
}
186186
// We use the workspace RBAC check since we don't want to allow dry runs if
@@ -301,7 +301,7 @@ func (api *API) patchTemplateVersionDryRunCancel(rw http.ResponseWriter, r *http
301301
}
302302
if !api.Authorize(r, rbac.ActionUpdate,
303303
rbac.ResourceWorkspace.InOrg(templateVersion.OrganizationID).WithOwner(job.InitiatorID.String())) {
304-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
304+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
305305
return
306306
}
307307

@@ -344,7 +344,7 @@ func (api *API) fetchTemplateVersionDryRunJob(rw http.ResponseWriter, r *http.Re
344344
jobID = chi.URLParam(r, "jobID")
345345
)
346346
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
347-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
347+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
348348
return database.ProvisionerJob{}, false
349349
}
350350

@@ -403,7 +403,7 @@ func (api *API) fetchTemplateVersionDryRunJob(rw http.ResponseWriter, r *http.Re
403403
func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Request) {
404404
template := httpmw.TemplateParam(r)
405405
if !api.Authorize(r, rbac.ActionRead, template) {
406-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", template.ID))
406+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", template.ID))
407407
return
408408
}
409409

@@ -491,7 +491,7 @@ func (api *API) templateVersionsByTemplate(rw http.ResponseWriter, r *http.Reque
491491
func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) {
492492
template := httpmw.TemplateParam(r)
493493
if !api.Authorize(r, rbac.ActionRead, template) {
494-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", template.ID))
494+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", template.ID))
495495
return
496496
}
497497

@@ -531,7 +531,7 @@ func (api *API) templateVersionByName(rw http.ResponseWriter, r *http.Request) {
531531
func (api *API) patchActiveTemplateVersion(rw http.ResponseWriter, r *http.Request) {
532532
template := httpmw.TemplateParam(r)
533533
if !api.Authorize(r, rbac.ActionUpdate, template) {
534-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %s", template.ID))
534+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template %q", template.ID))
535535
return
536536
}
537537

@@ -705,7 +705,7 @@ func (api *API) postTemplateVersionsByOrganization(rw http.ResponseWriter, r *ht
705705
func (api *API) templateVersionResources(rw http.ResponseWriter, r *http.Request) {
706706
templateVersion := httpmw.TemplateVersionParam(r)
707707
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
708-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
708+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
709709
return
710710
}
711711

@@ -727,7 +727,7 @@ func (api *API) templateVersionResources(rw http.ResponseWriter, r *http.Request
727727
func (api *API) templateVersionLogs(rw http.ResponseWriter, r *http.Request) {
728728
templateVersion := httpmw.TemplateVersionParam(r)
729729
if !api.Authorize(r, rbac.ActionRead, templateVersion) {
730-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %s", templateVersion.ID))
730+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Template version %q", templateVersion.ID))
731731
return
732732
}
733733

coderd/workspacebuilds.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (api *API) workspaceBuild(rw http.ResponseWriter, r *http.Request) {
2525

2626
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceWorkspace.
2727
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
28-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %s", workspaceBuild.ID))
28+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %q", workspaceBuild.ID))
2929
return
3030
}
3131

@@ -54,7 +54,7 @@ func (api *API) workspaceBuilds(rw http.ResponseWriter, r *http.Request) {
5454
workspace := httpmw.WorkspaceParam(r)
5555

5656
if !api.Authorize(r, rbac.ActionRead, workspace) {
57-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
57+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
5858
return
5959
}
6060

@@ -158,7 +158,7 @@ func (api *API) workspaceBuildByName(rw http.ResponseWriter, r *http.Request) {
158158
workspaceBuildName := chi.URLParam(r, "workspacebuildname")
159159
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceWorkspace.
160160
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
161-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %s", workspaceBuildName))
161+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %q", workspaceBuildName))
162162
return
163163
}
164164

@@ -167,7 +167,7 @@ func (api *API) workspaceBuildByName(rw http.ResponseWriter, r *http.Request) {
167167
Name: workspaceBuildName,
168168
})
169169
if errors.Is(err, sql.ErrNoRows) {
170-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %s", workspaceBuildName))
170+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %q", workspaceBuildName))
171171
return
172172
}
173173
if err != nil {
@@ -220,7 +220,7 @@ func (api *API) postWorkspaceBuilds(rw http.ResponseWriter, r *http.Request) {
220220
}
221221
if !api.Authorize(r, action, rbac.ResourceWorkspace.
222222
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
223-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
223+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
224224
return
225225
}
226226

@@ -449,7 +449,7 @@ func (api *API) workspaceBuildResources(rw http.ResponseWriter, r *http.Request)
449449

450450
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceWorkspace.
451451
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
452-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %s", workspaceBuild.ID))
452+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %q", workspaceBuild.ID))
453453
return
454454
}
455455

@@ -476,7 +476,7 @@ func (api *API) workspaceBuildLogs(rw http.ResponseWriter, r *http.Request) {
476476

477477
if !api.Authorize(r, rbac.ActionRead, rbac.ResourceWorkspace.
478478
InOrg(workspace.OrganizationID).WithOwner(workspace.OwnerID.String()).WithID(workspace.ID.String())) {
479-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %s", workspaceBuild.ID))
479+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %q", workspaceBuild.ID))
480480
return
481481
}
482482

@@ -502,7 +502,7 @@ func (api *API) workspaceBuildState(rw http.ResponseWriter, r *http.Request) {
502502
}
503503

504504
if !api.Authorize(r, rbac.ActionRead, workspace) {
505-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %s", workspaceBuild.ID))
505+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace build %q", workspaceBuild.ID))
506506
return
507507
}
508508

coderd/workspaces.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
func (api *API) workspace(rw http.ResponseWriter, r *http.Request) {
3333
workspace := httpmw.WorkspaceParam(r)
3434
if !api.Authorize(r, rbac.ActionRead, workspace) {
35-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
35+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
3636
return
3737
}
3838

@@ -193,7 +193,7 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
193193
})
194194
}
195195
if errors.Is(err, sql.ErrNoRows) {
196-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspaceName))
196+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspaceName))
197197
return
198198
}
199199
if err != nil {
@@ -204,7 +204,7 @@ func (api *API) workspaceByOwnerAndName(rw http.ResponseWriter, r *http.Request)
204204
return
205205
}
206206
if !api.Authorize(r, rbac.ActionRead, workspace) {
207-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.Name))
207+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.Name))
208208
return
209209
}
210210

@@ -482,7 +482,7 @@ func (api *API) postWorkspacesByOrganization(rw http.ResponseWriter, r *http.Req
482482
func (api *API) putWorkspaceAutostart(rw http.ResponseWriter, r *http.Request) {
483483
workspace := httpmw.WorkspaceParam(r)
484484
if !api.Authorize(r, rbac.ActionUpdate, workspace) {
485-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
485+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
486486
return
487487
}
488488

@@ -525,7 +525,7 @@ func (api *API) putWorkspaceAutostart(rw http.ResponseWriter, r *http.Request) {
525525
func (api *API) putWorkspaceTTL(rw http.ResponseWriter, r *http.Request) {
526526
workspace := httpmw.WorkspaceParam(r)
527527
if !api.Authorize(r, rbac.ActionUpdate, workspace) {
528-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
528+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
529529
return
530530
}
531531

@@ -574,7 +574,7 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) {
574574
workspace := httpmw.WorkspaceParam(r)
575575

576576
if !api.Authorize(r, rbac.ActionUpdate, workspace) {
577-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
577+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
578578
return
579579
}
580580

@@ -632,7 +632,7 @@ func (api *API) putExtendWorkspace(rw http.ResponseWriter, r *http.Request) {
632632
func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
633633
workspace := httpmw.WorkspaceParam(r)
634634
if !api.Authorize(r, rbac.ActionRead, workspace) {
635-
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %s", workspace.ID))
635+
httpapi.ResourceNotFound(rw, fmt.Sprintf("Workspace %q", workspace.ID))
636636
return
637637
}
638638

0 commit comments

Comments
 (0)