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

Skip to content

Commit 81f3849

Browse files
committed
Merge branch 'main' into ides
2 parents ff10b9c + fb9dc4f commit 81f3849

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1816
-1219
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
site @coder/frontend
2+
site/src/xServices @presleyp

.github/dependabot.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ updates:
4141
timezone: "America/Chicago"
4242
commit-message:
4343
prefix: "chore"
44+
labels:
45+
- "dependencies"
46+
- "typescript/js"
4447
ignore:
4548
# Ignore major updates to Node.js types, because they need to
4649
# correspond to the Node.js engine version

.github/workflows/coder.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
runs-on: ubuntu-latest
3030
steps:
3131
- uses: actions/checkout@v3
32-
- uses: actions/setup-go@v2
32+
- uses: actions/setup-go@v3
3333
with:
3434
go-version: "~1.18"
3535
- name: golangci-lint
@@ -71,7 +71,7 @@ jobs:
7171
uses: arduino/setup-protoc@v1
7272
with:
7373
version: "3.19.4"
74-
- uses: actions/setup-go@v2
74+
- uses: actions/setup-go@v3
7575
with:
7676
go-version: "~1.18"
7777
- run: curl -sSL
@@ -123,7 +123,7 @@ jobs:
123123
steps:
124124
- uses: actions/checkout@v3
125125

126-
- uses: actions/setup-go@v2
126+
- uses: actions/setup-go@v3
127127
with:
128128
go-version: "~1.18"
129129

@@ -195,7 +195,7 @@ jobs:
195195
steps:
196196
- uses: actions/checkout@v3
197197

198-
- uses: actions/setup-go@v2
198+
- uses: actions/setup-go@v3
199199
with:
200200
go-version: "~1.18"
201201

@@ -293,7 +293,7 @@ jobs:
293293
- name: Set up Google Cloud SDK
294294
uses: google-github-actions/setup-gcloud@v0
295295

296-
- uses: actions/setup-go@v2
296+
- uses: actions/setup-go@v3
297297
with:
298298
go-version: "~1.18"
299299

@@ -367,7 +367,7 @@ jobs:
367367
js-${{ runner.os }}-
368368
369369
# Go is required for uploading the test results to datadog
370-
- uses: actions/setup-go@v2
370+
- uses: actions/setup-go@v3
371371
with:
372372
go-version: "~1.18"
373373

@@ -423,7 +423,7 @@ jobs:
423423
js-${{ runner.os }}-
424424
425425
# Go is required for uploading the test results to datadog
426-
- uses: actions/setup-go@v2
426+
- uses: actions/setup-go@v3
427427
with:
428428
go-version: "~1.18"
429429

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
- uses: actions/checkout@v3
1111
with:
1212
fetch-depth: 0
13-
- uses: actions/setup-go@v2
13+
- uses: actions/setup-go@v3
1414
with:
1515
go-version: "~1.18"
1616

agent/agent.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ func (a *agent) run(ctx context.Context) {
103103

104104
func (a *agent) handlePeerConn(ctx context.Context, conn *peer.Conn) {
105105
go func() {
106-
<-a.closed
107-
_ = conn.Close()
108-
}()
109-
go func() {
106+
select {
107+
case <-a.closed:
108+
_ = conn.Close()
109+
case <-conn.Closed():
110+
}
110111
<-conn.Closed()
111112
a.connCloseWait.Done()
112113
}()

agent/agent_test.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,18 +135,9 @@ func TestAgent(t *testing.T) {
135135
}
136136

137137
func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exec.Cmd {
138-
_, err := exec.LookPath("socat")
139-
if err != nil {
140-
t.Skip("You must have socat installed to run this test!")
141-
}
142-
143138
agentConn := setupAgent(t)
144-
145139
listener, err := net.Listen("tcp", "127.0.0.1:0")
146140
require.NoError(t, err)
147-
t.Cleanup(func() {
148-
_ = listener.Close()
149-
})
150141
go func() {
151142
for {
152143
conn, err := listener.Accept()
@@ -162,7 +153,12 @@ func setupSSHCommand(t *testing.T, beforeArgs []string, afterArgs []string) *exe
162153
t.Cleanup(func() {
163154
_ = listener.Close()
164155
})
165-
args := append(beforeArgs, "-o", "ProxyCommand socat - TCP4:"+listener.Addr().String(), "-o", "StrictHostKeyChecking=no", "host")
156+
tcpAddr, valid := listener.Addr().(*net.TCPAddr)
157+
require.True(t, valid)
158+
args := append(beforeArgs,
159+
"-o", "HostName "+tcpAddr.IP.String(),
160+
"-o", "Port "+strconv.Itoa(tcpAddr.Port),
161+
"-o", "StrictHostKeyChecking=no", "host")
166162
args = append(args, afterArgs...)
167163
return exec.Command("ssh", args...)
168164
}

cli/cliui/prompt.go

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/bgentry/speakeasy"
1414
"github.com/mattn/go-isatty"
1515
"github.com/spf13/cobra"
16+
"golang.org/x/xerrors"
1617
)
1718

1819
// PromptOptions supply a set of options to the prompt.
@@ -47,7 +48,7 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
4748
if opts.Secret && isInputFile && isatty.IsTerminal(inFile.Fd()) {
4849
line, err = speakeasy.Ask("")
4950
} else {
50-
if runtime.GOOS == "darwin" && isInputFile {
51+
if !opts.IsConfirm && runtime.GOOS == "darwin" && isInputFile {
5152
var restore func()
5253
restore, err = removeLineLengthLimit(int(inFile.Fd()))
5354
if err != nil {
@@ -64,37 +65,7 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
6465
// This enables multiline JSON to be pasted into an input, and have
6566
// it parse properly.
6667
if err == nil && (strings.HasPrefix(line, "{") || strings.HasPrefix(line, "[")) {
67-
var data bytes.Buffer
68-
for {
69-
_, _ = data.WriteString(line)
70-
var rawMessage json.RawMessage
71-
err = json.Unmarshal(data.Bytes(), &rawMessage)
72-
if err != nil {
73-
if err.Error() != "unexpected end of JSON input" {
74-
err = nil
75-
line = data.String()
76-
break
77-
}
78-
79-
// Read line-by-line. We can't use a JSON decoder
80-
// here because it doesn't work by newline, so
81-
// reads will block.
82-
line, err = reader.ReadString('\n')
83-
if err != nil {
84-
break
85-
}
86-
continue
87-
}
88-
// Compacting the JSON makes it easier for parsing and testing.
89-
bytes := data.Bytes()
90-
data.Reset()
91-
err = json.Compact(&data, bytes)
92-
if err != nil {
93-
break
94-
}
95-
line = data.String()
96-
break
97-
}
68+
line, err = promptJSON(reader, line)
9869
}
9970
}
10071
if err != nil {
@@ -113,7 +84,7 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
11384
return "", err
11485
case line := <-lineCh:
11586
if opts.IsConfirm && line != "yes" && line != "y" {
116-
return line, Canceled
87+
return line, xerrors.Errorf("got %q: %w", line, Canceled)
11788
}
11889
if opts.Validate != nil {
11990
err := opts.Validate(line)
@@ -131,3 +102,39 @@ func Prompt(cmd *cobra.Command, opts PromptOptions) (string, error) {
131102
return "", Canceled
132103
}
133104
}
105+
106+
func promptJSON(reader *bufio.Reader, line string) (string, error) {
107+
var data bytes.Buffer
108+
for {
109+
_, _ = data.WriteString(line)
110+
var rawMessage json.RawMessage
111+
err := json.Unmarshal(data.Bytes(), &rawMessage)
112+
if err != nil {
113+
if err.Error() != "unexpected end of JSON input" {
114+
// If a real syntax error occurs in JSON,
115+
// we want to return that partial line to the user.
116+
err = nil
117+
line = data.String()
118+
break
119+
}
120+
121+
// Read line-by-line. We can't use a JSON decoder
122+
// here because it doesn't work by newline, so
123+
// reads will block.
124+
line, err = reader.ReadString('\n')
125+
if err != nil {
126+
break
127+
}
128+
continue
129+
}
130+
// Compacting the JSON makes it easier for parsing and testing.
131+
rawJSON := data.Bytes()
132+
data.Reset()
133+
err = json.Compact(&data, rawJSON)
134+
if err != nil {
135+
return line, xerrors.Errorf("compact json: %w", err)
136+
}
137+
return data.String(), nil
138+
}
139+
return line, nil
140+
}

cli/cliui/resources_test.go

Lines changed: 63 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"testing"
55
"time"
66

7+
"github.com/stretchr/testify/require"
8+
79
"github.com/coder/coder/cli/cliui"
810
"github.com/coder/coder/coderd/database"
911
"github.com/coder/coder/codersdk"
@@ -15,69 +17,75 @@ func TestWorkspaceResources(t *testing.T) {
1517
t.Run("SingleAgentSSH", func(t *testing.T) {
1618
t.Parallel()
1719
ptty := ptytest.New(t)
18-
cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
19-
Type: "google_compute_instance",
20-
Name: "dev",
21-
Transition: database.WorkspaceTransitionStart,
22-
Agents: []codersdk.WorkspaceAgent{{
23-
Name: "dev",
24-
Status: codersdk.WorkspaceAgentConnected,
25-
Architecture: "amd64",
26-
OperatingSystem: "linux",
27-
}},
28-
}}, cliui.WorkspaceResourcesOptions{
29-
WorkspaceName: "example",
30-
})
20+
go func() {
21+
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
22+
Type: "google_compute_instance",
23+
Name: "dev",
24+
Transition: database.WorkspaceTransitionStart,
25+
Agents: []codersdk.WorkspaceAgent{{
26+
Name: "dev",
27+
Status: codersdk.WorkspaceAgentConnected,
28+
Architecture: "amd64",
29+
OperatingSystem: "linux",
30+
}},
31+
}}, cliui.WorkspaceResourcesOptions{
32+
WorkspaceName: "example",
33+
})
34+
require.NoError(t, err)
35+
}()
3136
ptty.ExpectMatch("coder ssh example")
3237
})
3338

3439
t.Run("MultipleStates", func(t *testing.T) {
3540
t.Parallel()
3641
ptty := ptytest.New(t)
3742
disconnected := database.Now().Add(-4 * time.Second)
38-
cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
39-
Address: "disk",
40-
Transition: database.WorkspaceTransitionStart,
41-
Type: "google_compute_disk",
42-
Name: "root",
43-
}, {
44-
Address: "disk",
45-
Transition: database.WorkspaceTransitionStop,
46-
Type: "google_compute_disk",
47-
Name: "root",
48-
}, {
49-
Address: "another",
50-
Transition: database.WorkspaceTransitionStart,
51-
Type: "google_compute_instance",
52-
Name: "dev",
53-
Agents: []codersdk.WorkspaceAgent{{
54-
CreatedAt: database.Now().Add(-10 * time.Second),
55-
Status: codersdk.WorkspaceAgentConnecting,
56-
Name: "dev",
57-
OperatingSystem: "linux",
58-
Architecture: "amd64",
59-
}},
60-
}, {
61-
Transition: database.WorkspaceTransitionStart,
62-
Type: "kubernetes_pod",
63-
Name: "dev",
64-
Agents: []codersdk.WorkspaceAgent{{
65-
Status: codersdk.WorkspaceAgentConnected,
66-
Name: "go",
67-
Architecture: "amd64",
68-
OperatingSystem: "linux",
43+
go func() {
44+
err := cliui.WorkspaceResources(ptty.Output(), []codersdk.WorkspaceResource{{
45+
Address: "disk",
46+
Transition: database.WorkspaceTransitionStart,
47+
Type: "google_compute_disk",
48+
Name: "root",
49+
}, {
50+
Address: "disk",
51+
Transition: database.WorkspaceTransitionStop,
52+
Type: "google_compute_disk",
53+
Name: "root",
54+
}, {
55+
Address: "another",
56+
Transition: database.WorkspaceTransitionStart,
57+
Type: "google_compute_instance",
58+
Name: "dev",
59+
Agents: []codersdk.WorkspaceAgent{{
60+
CreatedAt: database.Now().Add(-10 * time.Second),
61+
Status: codersdk.WorkspaceAgentConnecting,
62+
Name: "dev",
63+
OperatingSystem: "linux",
64+
Architecture: "amd64",
65+
}},
6966
}, {
70-
DisconnectedAt: &disconnected,
71-
Status: codersdk.WorkspaceAgentDisconnected,
72-
Name: "postgres",
73-
Architecture: "amd64",
74-
OperatingSystem: "linux",
75-
}},
76-
}}, cliui.WorkspaceResourcesOptions{
77-
WorkspaceName: "dev",
78-
HideAgentState: false,
79-
HideAccess: false,
80-
})
67+
Transition: database.WorkspaceTransitionStart,
68+
Type: "kubernetes_pod",
69+
Name: "dev",
70+
Agents: []codersdk.WorkspaceAgent{{
71+
Status: codersdk.WorkspaceAgentConnected,
72+
Name: "go",
73+
Architecture: "amd64",
74+
OperatingSystem: "linux",
75+
}, {
76+
DisconnectedAt: &disconnected,
77+
Status: codersdk.WorkspaceAgentDisconnected,
78+
Name: "postgres",
79+
Architecture: "amd64",
80+
OperatingSystem: "linux",
81+
}},
82+
}}, cliui.WorkspaceResourcesOptions{
83+
WorkspaceName: "dev",
84+
HideAgentState: false,
85+
HideAccess: false,
86+
})
87+
require.NoError(t, err)
88+
}()
8189
ptty.ExpectMatch("google_compute_disk.root")
8290
ptty.ExpectMatch("google_compute_instance.dev")
8391
ptty.ExpectMatch("coder ssh dev.postgres")

0 commit comments

Comments
 (0)