-
Notifications
You must be signed in to change notification settings - Fork 891
feat: Add vscodeipc
subcommand for VS Code Extension
#5326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
eae77d7
Add extio
kylecarbs b959fb1
feat: Add `vscodeipc` subcommand for VS Code Extension
kylecarbs efc3025
Merge branch 'main' into vscodeext
kylecarbs cece1a5
Merge branch 'main' into vscodeext
kylecarbs 489eba0
Add authentication header, improve comments, and add tests for the CLI
kylecarbs fc50572
Update cli/vscodeipc_test.go
kylecarbs aca49b5
Update cli/vscodeipc_test.go
kylecarbs 78e47c7
Update cli/vscodeipc/vscodeipc_test.go
kylecarbs cb3725e
Merge branch 'vscodeext' of https://github.com/coder/coder into vscod…
kylecarbs ab45e44
Fix requested changes
kylecarbs d5197e9
Merge branch 'main' into vscodeext
kylecarbs 6bad9ae
Fix IPC tests
kylecarbs 2531768
Fix shell execution
kylecarbs b8f9b93
Fix nix flake
kylecarbs 6ab104f
Silence usage
kylecarbs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,7 @@ func Core() []*cobra.Command { | |
users(), | ||
versionCmd(), | ||
workspaceAgent(), | ||
vscodeipcCmd(), | ||
} | ||
} | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package cli | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
"net/http" | ||
"net/url" | ||
|
||
"github.com/google/uuid" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/xerrors" | ||
|
||
"github.com/coder/coder/cli/cliflag" | ||
"github.com/coder/coder/cli/vscodeipc" | ||
"github.com/coder/coder/codersdk" | ||
) | ||
|
||
// vscodeipcCmd spawns a local HTTP server on the provided port that listens to messages. | ||
// It's made for use by the Coder VS Code extension. See: https://github.com/coder/vscode-coder | ||
func vscodeipcCmd() *cobra.Command { | ||
var ( | ||
rawURL string | ||
token string | ||
port uint16 | ||
) | ||
cmd := &cobra.Command{ | ||
Use: "vscodeipc <workspace-agent>", | ||
Args: cobra.ExactArgs(1), | ||
SilenceUsage: true, | ||
Hidden: true, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
if rawURL == "" { | ||
return xerrors.New("CODER_URL must be set!") | ||
} | ||
// token is validated in a header on each request to prevent | ||
// unauthenticated clients from connecting. | ||
if token == "" { | ||
return xerrors.New("CODER_TOKEN must be set!") | ||
} | ||
listener, err := net.Listen("tcp", fmt.Sprintf("127.0.0.1:%d", port)) | ||
if err != nil { | ||
return xerrors.Errorf("listen: %w", err) | ||
} | ||
defer listener.Close() | ||
addr, ok := listener.Addr().(*net.TCPAddr) | ||
if !ok { | ||
return xerrors.Errorf("listener.Addr() is not a *net.TCPAddr: %T", listener.Addr()) | ||
} | ||
url, err := url.Parse(rawURL) | ||
if err != nil { | ||
return err | ||
} | ||
agentID, err := uuid.Parse(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
client := codersdk.New(url) | ||
client.SetSessionToken(token) | ||
|
||
handler, closer, err := vscodeipc.New(cmd.Context(), client, agentID, nil) | ||
if err != nil { | ||
return err | ||
} | ||
defer closer.Close() | ||
// nolint:gosec | ||
server := http.Server{ | ||
kylecarbs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Handler: handler, | ||
} | ||
defer server.Close() | ||
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s\n", addr.String()) | ||
errChan := make(chan error, 1) | ||
go func() { | ||
err := server.Serve(listener) | ||
errChan <- err | ||
}() | ||
select { | ||
case <-cmd.Context().Done(): | ||
return cmd.Context().Err() | ||
case err := <-errChan: | ||
return err | ||
} | ||
}, | ||
} | ||
cliflag.StringVarP(cmd.Flags(), &rawURL, "url", "u", "CODER_URL", "", "The URL of the Coder instance!") | ||
cliflag.StringVarP(cmd.Flags(), &token, "token", "t", "CODER_TOKEN", "", "The session token of the user!") | ||
cmd.Flags().Uint16VarP(&port, "port", "p", 0, "The port to listen on!") | ||
return cmd | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.