-
Notifications
You must be signed in to change notification settings - Fork 881
refactor(agent/agentssh): move parsing of magic session and create type #16630
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have any blocking concerns 👍 some comments below.
func extractMagicSessionType(env []string) (magicType MagicSessionType, rawType string, filteredEnv []string) { | ||
for _, kv := range env { | ||
if !strings.HasPrefix(kv, MagicSessionTypeEnvironmentVariable) { | ||
continue | ||
} | ||
|
||
rawType = strings.TrimPrefix(kv, MagicSessionTypeEnvironmentVariable+"=") | ||
// Keep going, we'll use the last instance of the env. | ||
} | ||
|
||
// Always force lowercase checking to be case-insensitive. | ||
switch MagicSessionType(strings.ToLower(rawType)) { | ||
case MagicSessionTypeVSCode: | ||
magicType = MagicSessionTypeVSCode | ||
case MagicSessionTypeJetBrains: | ||
magicType = MagicSessionTypeJetBrains | ||
case "", MagicSessionTypeSSH: | ||
magicType = MagicSessionTypeSSH | ||
default: | ||
magicType = MagicSessionTypeUnknown | ||
} | ||
|
||
return magicType, rawType, slices.DeleteFunc(env, func(kv string) bool { | ||
return strings.HasPrefix(kv, MagicSessionTypeEnvironmentVariable+"=") | ||
}) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: extractMagicSessionType(env []string) (MagicSessionType, filteredEnv, error)
and return error in case of unknown magic session type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kind of like the suggestion, but I don't like returning valid data from a function that returns an error. Essentially we'd still want to filter the env in the case of an error parsing the magic session type. (We only warn log currently if it's invalid.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair!
@@ -612,15 +646,15 @@ func (s *Server) startPTYSession(logger slog.Logger, session ptySession, magicTy | |||
return nil | |||
} | |||
|
|||
func (s *Server) handleSignal(logger slog.Logger, ssig ssh.Signal, signaler interface{ Signal(os.Signal) error }, magicTypeLabel string) { | |||
func handleSignal(logger slog.Logger, ssig ssh.Signal, signaler interface{ Signal(os.Signal) error }, metrics *sshServerMetrics, magicTypeLabel string) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
case "": | ||
magicType = "ssh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This smells like some cutover compatibility logic here.
This change refactors the parsing of MagicSessionEnvs in the agentssh package and moves the logic to an earlier stage. Also intoduces enums for MagicSessionType.
In preparation of further changes for #15139.
I'm relying on current tests to verify this behavior, will add more test coverage in later PRs.