Skip to content

Commit

Permalink
Correct passing client args correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
sandromello committed Oct 28, 2022
1 parent 996cc43 commit 8877b91
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
24 changes: 12 additions & 12 deletions client/cmd/connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ var (
Short: "Connect to a remote resource",
SilenceUsage: false,
PreRun: func(cmd *cobra.Command, args []string) {
if len(args) != 1 {
if len(args) < 1 {
cmd.Usage()
os.Exit(1)
}

},
Run: func(cmd *cobra.Command, args []string) {
runConnect(args)
Expand Down Expand Up @@ -67,7 +66,7 @@ func runConnect(args []string) {
c := &connect{
proxyPort: connectFlags.proxyPort,
connStore: memory.New(),
clientArgs: args,
clientArgs: args[1:],
connectionName: args[0],
loader: loader,
}
Expand All @@ -81,9 +80,18 @@ func runConnect(args []string) {
c.printErrorAndExit(err.Error())
}
loader.Suffix = " validating connection..."
spec := map[string][]byte{}
if len(c.clientArgs) > 0 {
encArgs, err := pb.GobEncode(c.clientArgs)
if err != nil {
log.Fatalf("failed encoding args, err=%v", err)
}
spec[string(pb.SpecClientExecArgsKey)] = encArgs
}
c.client = client
if err := client.Send(&pb.Packet{
Type: pb.PacketGatewayConnectType.String(),
Spec: spec,
}); err != nil {
_, _ = client.Close()
c.printErrorAndExit("failed connecting to gateway, err=%v", err)
Expand Down Expand Up @@ -169,17 +177,9 @@ func (c *connect) processAgentConnectPhase(pkt *pb.Packet) {
c.loader.Stop()
c.client.StartKeepAlive()
term := proxyexec.New(c.client)
spec := map[string][]byte{}
if len(c.clientArgs) > 0 {
encArgs, err := pb.GobEncode(c.clientArgs)
if err != nil {
log.Fatalf("failed encoding args, err=%v", err)
}
spec[string(pb.SpecClientExecArgsKey)] = encArgs
}
c.printHeader(string(sessionID))
c.connStore.Set(string(sessionID), term)
if err := term.ConnecWithTTY(spec); err != nil {
if err := term.ConnecWithTTY(); err != nil {
c.processGracefulExit(err)
}
default:
Expand Down
4 changes: 2 additions & 2 deletions client/proxyexec/proxyexec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func New(client pb.ClientTransport) *Terminal {
}

// Connect control the current terminal connecting with the remote one
func (t *Terminal) ConnecWithTTY(spec map[string][]byte) error {
func (t *Terminal) ConnecWithTTY() error {
info, err := os.Stdin.Stat()
if err != nil {
return fmt.Errorf("failed obtaining stdin file description, err=%v", err)
Expand Down Expand Up @@ -61,7 +61,7 @@ func (t *Terminal) ConnecWithTTY(spec map[string][]byte) error {
sig <- pbexec.SIGWINCH

go func() {
sw := pb.NewStreamWriter(t.client, pb.PacketExecWriteAgentStdinType, spec)
sw := pb.NewStreamWriter(t.client, pb.PacketExecWriteAgentStdinType, nil)
_, _ = sw.Write(pbexec.TermEnterKeyStrokeType)
// TODO: check errors
_, _ = io.Copy(sw, os.Stdin)
Expand Down
6 changes: 5 additions & 1 deletion rootfs/app/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/bash

if [[ "$DEBUG_ENTRYPOINT" == "true" ]]; then
set -x
fi

export GIN_MODE=release
if [[ "$PROFILE" == "dev" ]]; then
/app/start-dev.sh
Expand All @@ -11,4 +15,4 @@ if [[ "$API_URL" != "" ]]; then
sed "s|http://localhost:8009|$API_URL|g" -i app/ui/public/js/app.js
fi

"${@}"
tini -- "${@}"
1 change: 1 addition & 0 deletions scripts/run-client-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

#go clean --cache
go build -o /tmp/hoop-client github.com/runopsio/hoop/client

/tmp/hoop-client "$@"

0 comments on commit 8877b91

Please sign in to comment.