Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: show banner when workspace is outdated#4926

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mtojek merged 3 commits intocoder:mainfrommtojek:4489-ssh-outdated-baner
Nov 7, 2022

Conversation

mtojek
Copy link
Member

Fixes:#4489

This PR introduces a CLI banner presented when the workspace, to which the user is trying to SSH, is outdated.

@mtojekmtojek self-assigned thisNov 7, 2022
@mtojekmtojek marked this pull request as ready for reviewNovember 7, 2022 11:09
@mtojekmtojek requested a review froma teamNovember 7, 2022 11:09
Copy link
Member

@mafredrimafredri left a comment
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Nice simple solution 👍🏻.

I think printing to stderr is a good first step, but in the future I think it would be a good idea to start usingBannerCallback instead.

At least on systems with/etc/motd and OpenSSH, messages don't appear in non-interactive modes likessh host ls. I believe this should (automatically) be the case when usingBannerCallback too.

But to do that, we'd also need to fix all other occurrences of printing to stdout in thecoder ssh [--stdio] command.

cli/ssh.go Outdated
@@ -72,6 +73,11 @@ func ssh() *cobra.Command {
return err
}

updateWorkspaceBanner, outdated := verifyWorkspaceOutdated(client, workspace)
if outdated {
_, _ = fmt.Fprintln(cmd.OutOrStdout(), updateWorkspaceBanner)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

We should change this to print on stderr so that non-interactive commands likessh coder.workspace ls | grep hi aren't dirtied.

I wonder if we should consider only outputting when the recipient is a tty as well. 🤔

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Good catch!

Switched to stderr and added a TTY check.

@mtojek
Copy link
MemberAuthor

I think printing to stderr is a good first step, but in the future I think it would be a good idea to start usingBannerCallback instead.

Thanks for bringing up the idea of BannerCallback. I'm wondering if it isn't something we could park for further improvement. I don't mind working on this, but not sure if adjusting the entirecoder ssh isn't a rabbit hole. Let me know what you think.

cli/ssh.go Outdated
@@ -72,6 +73,11 @@ func ssh() *cobra.Command {
return err
}

updateWorkspaceBanner, outdated := verifyWorkspaceOutdated(client, workspace)
if outdated && isTTYOut(cmd) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ah, this tty check is only forstdout which doesn't help us (we want to confirm stderr.)

Made the following quick test:

❯ go run main.go >/dev/nullstdout isatty: falsestderr isatty: true❯ go run main.go 2>/dev/nullstdout isatty: truestderr isatty: false

Using:

package mainimport ("fmt""io""os""github.com/mattn/go-isatty")funcmain() {both:=io.MultiWriter(os.Stdout,os.Stderr)fmt.Fprintf(both,"stdout isatty: %v\n",isatty.IsTerminal(os.Stdout.Fd()))fmt.Fprintf(both,"stderr isatty: %v\n",isatty.IsTerminal(os.Stderr.Fd()))}

Arguably, this is a bug we potentially have across our whole CLI, but for now I think we can just add a new function:isTTYErr.

Copy link
MemberAuthor

@mtojekmtojekNov 7, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for the snippet. I refactored the originalisTTYOut function, but please let me know what you think.

mafredri reacted with thumbs up emoji
@mafredri
Copy link
Member

mafredri commentedNov 7, 2022
edited
Loading

Thanks for bringing up the idea of BannerCallback. I'm wondering if it isn't something we could park for further improvement. I don't mind working on this, but not sure if adjusting the entirecoder ssh isn't a rabbit hole. Let me know what you think.

Definitely. I'll create a separate issue for it. 👍🏻

Edit:#4927

mtojek reacted with thumbs up emoji

@mtojekmtojek requested a review frommafredriNovember 7, 2022 14:27

client := codersdk.Client{URL: serverURL}

t.Run("Up-to-date", func(t *testing.T) {
Copy link
Member

@mafredrimafredriNov 7, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Sorry, I didn't look too closely at these tests on my first pass. I should point out that the preferred way to test in thecoder/coder repo is write external tests (package cli_test).

With these types of tests, we'd do abit more setup for the test so that we can then test the output of runningcoder ssh ....

(Not a blocker for this PR, but just a heads up for future PRs.)

Copy link
MemberAuthor

@mtojekmtojekNov 7, 2022
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Ok, I see now. I can use existing coderdtest APIs. I need to create a workspace to simulate a template update (CreateTemplateVersion). Something likesetupWorkspaceForAgent, but customized.

I can adjust the implementation, but not sure if in this case the internal_test isn't just simpler (and shorter). Do you have any preference?

@bpmct
Copy link
Member

I primarily connect to my workspace with VS Code Remote SSH. Will VS Code users notice this, or is it hidden in the SSH logs somewhere?

@mtojek
Copy link
MemberAuthor

mtojek commentedNov 7, 2022
edited
Loading

Hi@bpmct! I'm afraid that VS code operates on a different level as it uses ssh-configs directly. I'm not quite sure if there is a channel to present a notification, warning, orange light, etc. to signal to the VS user that the workspace is outdated.

Regarding the traditional ssh, it's like this:

Screenshot 2022-11-07 at 17 28 56

EDIT:

aftercoder config-ssh executed andLogLevel DEBUG,ssh coder.mtojek-1 gives:

...debug1: identity file /Users/mtojek/.ssh/id_dsatype -1debug1: identity file /Users/mtojek/.ssh/id_dsa-certtype -1debug1: Local version string SSH-2.0-OpenSSH_9.0debug1: kex_exchange_identification: banner line 0: �\237\221\213 Your workspace is outdated! Update it here: https://dev.coder.com/@mtojek/mtojek-1!debug1: kex_exchange_identification: banner line 1:debug1: Remote protocol version 2.0, remote software version Go...

EDIT2:

With"remote.SSH.logLevel": "trace" insettings.json, I'm able to find the message about the outdated env, so I guess that it answers your question. Unfortunately it's deep in logs:

Screenshot 2022-11-07 at 18 56 55

@mtojek
Copy link
MemberAuthor

I'm going to merge this PR as we can always improve the experience in the next iterations.

@mtojekmtojek merged commit641aacf intocoder:mainNov 7, 2022
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsNov 7, 2022
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@mafredrimafredrimafredri approved these changes

Assignees

@mtojekmtojek

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Feature: show ssh login banner when workspace is outdated
3 participants
@mtojek@mafredri@bpmct

[8]ページ先頭

©2009-2025 Movatter.jp