Skip to content

chore(agent/agentssh): extract EnvInfoer#16603

Merged
johnstcn merged 4 commits into
mainfrom
cj/agentssh-createcommanddeps
Feb 19, 2025
Merged

chore(agent/agentssh): extract EnvInfoer#16603
johnstcn merged 4 commits into
mainfrom
cj/agentssh-createcommanddeps

Conversation

@johnstcn

@johnstcn johnstcn commented Feb 18, 2025

Copy link
Copy Markdown
Member

Extracts environment-level dependencies of agentssh.Server.CreateCommand() to an interface to allow alternative implementations to be passed in.

We'll need this so we can pass in an alternative implementation that can reference a running container instead of the agent's environment.

I'm not married to the naming convention and will rename the thing if anyone has a better name.

@mafredri mafredri left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Naming aside, changes look good so approving 👍🏻

// UserHomeDir returns the home directory of the current user.
UserHomeDir() (string, error)
// UserShell returns the shell of the given user.
UserShell(username string) (string, error)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I feel like all these methods are related to the environment, figuring out the user, env, home and shell, so EnvInfo sounds like a pretty good name to me. Deps is a bit vague IMO and makes me think of dependency injection. 😄


We could also simplify this interface somewhat. All we really need are:

  • User()
  • Environ()

We'd just make sure the returned user has the correct home directory and shell populated. Not sure if that'd be worth the lift, though.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

EnvInfoer it is!

I'd prefer to do the bare minimum here, but we can consolidate + simplify down the line!

t.Parallel()
cmd, err := s.CreateCommand(ctx, `#!/usr/bin/env bash
echo test`, nil)
echo test`, nil, nil)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps we should add a test for a custom implementation as well?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Can do!

@johnstcn johnstcn merged commit 4edd77b into main Feb 19, 2025
@johnstcn johnstcn deleted the cj/agentssh-createcommanddeps branch February 19, 2025 09:04
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 19, 2025
@johnstcn johnstcn changed the title chore(agent/agentssh): extract CreateCommandDeps chore(agent/agentssh): extract EnvInfoer Feb 19, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants