Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74f0328

Browse files
committed
Fix linting error
1 parent 1aec36d commit 74f0328

File tree

7 files changed

+14
-49
lines changed

7 files changed

+14
-49
lines changed

cli/workspaceagent.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"net/url"
55
"os"
66

7-
"github.com/coder/coder/agent"
8-
"github.com/coder/coder/codersdk"
97
"github.com/powersj/whatsthis/pkg/cloud"
108
"github.com/spf13/cobra"
119
"golang.org/x/xerrors"
10+
11+
"github.com/coder/coder/agent"
12+
"github.com/coder/coder/codersdk"
1213
)
1314

1415
func workspaceAgent() *cobra.Command {

cli/workspaces.go

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ func workspaces() *cobra.Command {
66
cmd := &cobra.Command{
77
Use: "workspaces",
88
}
9+
cmd.AddCommand(workspaceAgent())
910
cmd.AddCommand(workspaceCreate())
1011

1112
return cmd

coderd/coderd.go

-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ func New(options *Options) (http.Handler, func()) {
156156
r.Get("/", api.provisionerJobResourcesByID)
157157
r.Route("/{workspaceresource}", func(r chi.Router) {
158158
r.Use(httpmw.ExtractWorkspaceResourceParam(options.Database))
159-
r.Get("/", api.provisionerJobResourceByID)
160159
r.Get("/agent", api.workspaceAgentConnectByResource)
161160
})
162161
})

coderd/provisionerjobs.go

+2-40
Original file line numberDiff line numberDiff line change
@@ -249,47 +249,9 @@ func (api *api) provisionerJobResourcesByID(rw http.ResponseWriter, r *http.Requ
249249
return
250250
}
251251
resources, err := api.Database.GetProvisionerJobResourcesByJobID(r.Context(), job.ID)
252-
if err != nil {
253-
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
254-
Message: fmt.Sprintf("get provisioner job resources: %s", err),
255-
})
256-
return
257-
}
258-
apiResources := make([]ProvisionerJobResource, 0)
259-
for _, resource := range resources {
260-
if !resource.AgentID.Valid {
261-
apiResources = append(apiResources, convertProvisionerJobResource(resource, nil))
262-
continue
263-
}
264-
agent, err := api.Database.GetProvisionerJobAgentByResourceID(r.Context(), resource.ID)
265-
if err != nil {
266-
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
267-
Message: fmt.Sprintf("get provisioner job agent: %s", err),
268-
})
269-
return
270-
}
271-
apiAgent, err := convertProvisionerJobAgent(agent)
272-
if err != nil {
273-
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
274-
Message: fmt.Sprintf("convert provisioner job agent: %s", err),
275-
})
276-
return
277-
}
278-
apiResources = append(apiResources, convertProvisionerJobResource(resource, &apiAgent))
279-
}
280-
render.Status(r, http.StatusOK)
281-
render.JSON(rw, r, apiResources)
282-
}
283-
284-
func (api *api) provisionerJobResourceByID(rw http.ResponseWriter, r *http.Request) {
285-
job := httpmw.ProvisionerJobParam(r)
286-
if !convertProvisionerJob(job).Status.Completed() {
287-
httpapi.Write(rw, http.StatusPreconditionFailed, httpapi.Response{
288-
Message: "Job hasn't completed!",
289-
})
290-
return
252+
if errors.Is(err, sql.ErrNoRows) {
253+
err = nil
291254
}
292-
resources, err := api.Database.GetProvisionerJobResourcesByJobID(r.Context(), job.ID)
293255
if err != nil {
294256
httpapi.Write(rw, http.StatusInternalServerError, httpapi.Response{
295257
Message: fmt.Sprintf("get provisioner job resources: %s", err),

coderd/workspaceagent_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import (
55
"testing"
66
"time"
77

8+
"github.com/google/uuid"
9+
"github.com/stretchr/testify/require"
10+
811
"cdr.dev/slog"
912
"cdr.dev/slog/sloggers/slogtest"
1013
"github.com/coder/coder/agent"
@@ -16,8 +19,6 @@ import (
1619
"github.com/coder/coder/peerbroker"
1720
"github.com/coder/coder/provisioner/echo"
1821
"github.com/coder/coder/provisionersdk/proto"
19-
"github.com/google/uuid"
20-
"github.com/stretchr/testify/require"
2122
)
2223

2324
func TestWorkspaceAgentServe(t *testing.T) {

codersdk/workspaceagent.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import (
1212
"golang.org/x/xerrors"
1313
"nhooyr.io/websocket"
1414

15+
"github.com/google/uuid"
16+
"github.com/hashicorp/yamux"
17+
1518
"github.com/coder/coder/coderd"
1619
"github.com/coder/coder/httpmw"
1720
"github.com/coder/coder/peer"
1821
"github.com/coder/coder/peerbroker"
1922
"github.com/coder/coder/peerbroker/proto"
2023
"github.com/coder/coder/provisionersdk"
21-
"github.com/google/uuid"
22-
"github.com/hashicorp/yamux"
2324
)
2425

2526
// AuthenticateWorkspaceAgentUsingGoogleCloudIdentity uses the Google Compute Engine Metadata API to

database/databasefake/databasefake.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ func (q *fakeQuerier) GetProvisionerJobAgentByInstanceID(_ context.Context, inst
534534
return database.ProvisionerJobAgent{}, sql.ErrNoRows
535535
}
536536

537-
func (q *fakeQuerier) GetProvisionerJobAgentByResourceID(ctx context.Context, resourceID uuid.UUID) (database.ProvisionerJobAgent, error) {
537+
func (q *fakeQuerier) GetProvisionerJobAgentByResourceID(_ context.Context, resourceID uuid.UUID) (database.ProvisionerJobAgent, error) {
538538
q.mutex.Lock()
539539
defer q.mutex.Unlock()
540540

@@ -962,7 +962,7 @@ func (q *fakeQuerier) UpdateProvisionerDaemonByID(_ context.Context, arg databas
962962
return sql.ErrNoRows
963963
}
964964

965-
func (q *fakeQuerier) UpdateProvisionerJobAgentByID(ctx context.Context, arg database.UpdateProvisionerJobAgentByIDParams) error {
965+
func (q *fakeQuerier) UpdateProvisionerJobAgentByID(_ context.Context, arg database.UpdateProvisionerJobAgentByIDParams) error {
966966
q.mutex.Lock()
967967
defer q.mutex.Unlock()
968968

0 commit comments

Comments
 (0)