Skip to content

Commit 3ae34f7

Browse files
fix(RDGRS-662): added ID to CC execution and show the local ports (#77)
* added ID to CC execution and show the local ports * new versions
1 parent d137d63 commit 3ae34f7

File tree

4 files changed

+69
-21
lines changed

4 files changed

+69
-21
lines changed

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ require (
1010
github.com/jpillora/sizestr v1.0.0 // indirect
1111
golang.org/x/crypto v0.26.0 // indirect
1212
golang.org/x/net v0.28.0 // indirect
13-
golang.org/x/sync v0.7.0 // indirect
13+
golang.org/x/sync v0.8.0 // indirect
1414
golang.org/x/sys v0.24.0 // indirect
1515
)
1616

17-
replace github.com/jpillora/chisel => github.com/outsystems/chisel v1.9.2-0.20230908114230-bf0e1ad1c3e6
17+
replace github.com/jpillora/chisel => github.com/outsystems/chisel v1.9.2-os.4
1818

1919
go 1.22

go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2E
88
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
99
github.com/jpillora/sizestr v1.0.0 h1:4tr0FLxs1Mtq3TnsLDV+GYUWG7Q26a6s+tV5Zfw2ygw=
1010
github.com/jpillora/sizestr v1.0.0/go.mod h1:bUhLv4ctkknatr6gR42qPxirmd5+ds1u7mzD+MZ33f0=
11-
github.com/outsystems/chisel v1.9.2-0.20230908114230-bf0e1ad1c3e6 h1:+jPXx3ix1uEbwZ4jRz/kICYaYkfcTFZDYnqslBTcB28=
12-
github.com/outsystems/chisel v1.9.2-0.20230908114230-bf0e1ad1c3e6/go.mod h1:QGQAxn4w6IbAHTGxDE/lD4dPUSU4pUzkH44skisW+ag=
11+
github.com/outsystems/chisel v1.9.2-os.4 h1:PplhrOrFlj2d0M/lNuvswSPzAmdlPkx8OZly1l5dyPs=
12+
github.com/outsystems/chisel v1.9.2-os.4/go.mod h1:H90bwoii5ME/1jRRxreLwd43gTmp03mJQa8xKHcCZW0=
1313
golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw=
1414
golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54=
1515
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
1616
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
17-
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
18-
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
17+
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
18+
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
1919
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=
2020
golang.org/x/sys v0.24.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
21-
golang.org/x/term v0.22.0 h1:BbsgPEJULsl2fV/AT3v15Mjva5yXKQDyKf+TbDz7QJk=
22-
golang.org/x/term v0.22.0/go.mod h1:F3qCibpT5AMpCRfhfT53vVJwhLtIVHhB9XDjfFvnMI4=
21+
golang.org/x/term v0.23.0 h1:F6D4vR+EHoL9/sWAWgAR1H2DcHr4PareCbAaCo1RpuU=
22+
golang.org/x/term v0.23.0/go.mod h1:DgV24QBUrK6jhZXl+20l6UWznPlwAHm1Q1mGHtydmSk=

main.go

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import (
1212
"strings"
1313
"time"
1414

15+
"math/rand"
16+
1517
chclient "github.com/jpillora/chisel/client"
1618
"github.com/jpillora/chisel/share/cos"
1719
"github.com/jpillora/chisel/share/settings"
@@ -140,12 +142,15 @@ func client(args []string) {
140142
if len(args) < 2 {
141143
log.Fatalf("A server and least one remote is required")
142144
}
143-
config.Server = args[0]
144145

145-
if err := validateRemotes(args[1:]); err != nil {
146+
localPorts, err := validateRemotes(args[1:])
147+
if err != nil {
146148
log.Fatal(err)
147149
}
148150

151+
queryParams := generateQueryParameters(localPorts)
152+
153+
config.Server = fmt.Sprintf("%s%s", args[0], queryParams)
149154
config.Remotes = args[1:]
150155

151156
//default auth
@@ -175,33 +180,39 @@ func client(args []string) {
175180
}
176181
}
177182

183+
func generateQueryParameters(localPorts string) string {
184+
return fmt.Sprintf("?id=%v&ports=%v", rand.Intn(999999999-100000000)+100000000, localPorts)
185+
}
186+
178187
// validate the provided Remotes configuration is valid
179-
func validateRemotes(remotes []string) error {
188+
func validateRemotes(remotes []string) (string, error) {
180189
uniqueRemotes := []string{}
190+
localPorts := []string{}
181191

182192
for _, newRemote := range remotes {
183193

194+
remote, err := settings.DecodeRemote(newRemote)
195+
if err != nil {
196+
return "", fmt.Errorf("failed to decode remote '%s': %s", newRemote, err)
197+
}
198+
184199
// iterate all remotes already in the unique list, if duplicate is found return error
185200
for _, unique := range uniqueRemotes {
186-
firstRemote, err := settings.DecodeRemote(unique)
201+
validatedRemote, err := settings.DecodeRemote(unique)
187202
if err != nil {
188-
return fmt.Errorf("failed to decode remote '%s': %s", unique, err)
203+
return "", fmt.Errorf("failed to decode remote '%s': %s", unique, err)
189204
}
190205

191-
secondRemote, err := settings.DecodeRemote(newRemote)
192-
if err != nil {
193-
return fmt.Errorf("failed to decode remote '%s': %s", newRemote, err)
194-
}
195-
196-
if isDuplicatedRemote(firstRemote, secondRemote) {
197-
return fmt.Errorf("invalid Remote configuration: local port '%s' is duplicated", secondRemote.LocalPort)
206+
if isDuplicatedRemote(validatedRemote, remote) {
207+
return "", fmt.Errorf("invalid Remote configuration: local port '%s' is duplicated", remote.LocalPort)
198208
}
199209
}
200210

201211
uniqueRemotes = append(uniqueRemotes, newRemote)
212+
localPorts = append(localPorts, remote.LocalPort)
202213
}
203214

204-
return nil
215+
return strings.Join(localPorts, ","), nil
205216
}
206217

207218
func isDuplicatedRemote(first, second *settings.Remote) bool {

main_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package main
2+
3+
import "testing"
4+
5+
func Test_validateRemotes(t *testing.T) {
6+
7+
tests := []struct {
8+
name string
9+
remotes []string
10+
want string
11+
wantErr bool
12+
}{
13+
{
14+
name: "success",
15+
remotes: []string{"R:15800:localhost:7000", "R:15801:localhost:7001"},
16+
want: "15800,15801",
17+
wantErr: false,
18+
},
19+
{
20+
name: "error",
21+
remotes: []string{"R:15800:localhost:7000", "R:15800:localhost:7001"},
22+
wantErr: true,
23+
},
24+
}
25+
for _, tt := range tests {
26+
t.Run(tt.name, func(t *testing.T) {
27+
got, err := validateRemotes(tt.remotes)
28+
if (err != nil) != tt.wantErr {
29+
t.Errorf("validateRemotes() error = %v, wantErr %v", err, tt.wantErr)
30+
return
31+
}
32+
if got != tt.want {
33+
t.Errorf("validateRemotes() = %v, want %v", got, tt.want)
34+
}
35+
})
36+
}
37+
}

0 commit comments

Comments
 (0)