Skip to content

Commit

Permalink
devbox: Add setup-ssh-agent-forwarding and offer that in ssh and code
Browse files Browse the repository at this point in the history
Add a command to setup SSH agent forwarding for devbox ssh endpoints.
Offer to do that in nsc devbox ssh and nsc devbox code.
  • Loading branch information
pavolmarko committed Jul 12, 2024
1 parent 38b56a7 commit e1dd20a
Show file tree
Hide file tree
Showing 6 changed files with 506 additions and 5 deletions.
6 changes: 6 additions & 0 deletions internal/cli/cmd/devbox/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ package devbox
import (
"context"
"fmt"
"io"

devboxv1beta "buf.build/gen/go/namespace/cloud/protocolbuffers/go/proto/namespace/private/devbox"
"github.com/kr/text"
"namespacelabs.dev/foundation/internal/console"
"namespacelabs.dev/foundation/internal/fnapi"
"namespacelabs.dev/foundation/internal/providers/nscloud/api/private"
Expand Down Expand Up @@ -71,3 +73,7 @@ func doEnsureDevbox(ctx context.Context, devboxClient *private.DevBoxServiceClie
regionalSshEndpoint: resp.RegionalSshEndpoint,
}, nil
}

func indent(w io.Writer) io.Writer {
return text.NewIndentWriter(w, []byte(" "))
}
5 changes: 0 additions & 5 deletions internal/cli/cmd/devbox/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

devboxv1beta "buf.build/gen/go/namespace/cloud/protocolbuffers/go/proto/namespace/private/devbox"
"github.com/dustin/go-humanize"
"github.com/kr/text"
"github.com/spf13/cobra"
"namespacelabs.dev/foundation/internal/cli/fncobra"
"namespacelabs.dev/foundation/internal/console"
Expand Down Expand Up @@ -70,7 +69,3 @@ func describeToWriter(out io.Writer, devbox *devboxv1beta.DevBox) {
fmt.Fprintln(bodyWriter, "Base image:\t", devbox.GetDevboxSpec().GetBaseImageRef())
fmt.Fprintln(bodyWriter, "SSH endpoint:\t", devbox.GetDevboxStatus().GetSshEndpoint())
}

func indent(w io.Writer) io.Writer {
return text.NewIndentWriter(w, []byte(" "))
}
1 change: 1 addition & 0 deletions internal/cli/cmd/devbox/devbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func NewDevBoxCmd() *cobra.Command {
cmd.AddCommand(newEnsureCommand())
cmd.AddCommand(newSshCommand())
cmd.AddCommand(newVscodeCommand())
cmd.AddCommand(newSetupSshAgentForwardingCommand())

return cmd
}
4 changes: 4 additions & 0 deletions internal/cli/cmd/devbox/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func sshDevbox(ctx context.Context, tag string) error {
return err
}

if err := offerSetupSshAgentForwarding(ctx); err != nil {
return err
}

cmd := exec.Command("ssh", instance.regionalSshEndpoint)
cmd.Stdout = os.Stdout
cmd.Stdin = os.Stdin
Expand Down
Loading

0 comments on commit e1dd20a

Please sign in to comment.