Skip to content
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

Allow to run ssh commands to localhost #105 #108

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pierrelemee
Copy link

Allow to run ssh commands to localhost #105

See #105 : for testing reasons, one could want to test a set of SSH commands to a local Docker container.

For this purpose, I'm suggesting the option $allowLocalConnection, by default remains set to false. It can be set using the truey only setter allowLocalConnection(). If true, the check on local host that keeps the $command as a local one is disabled.

@@ -163,7 +172,8 @@ public function getExecuteCommand($command): string

$commandString = implode(PHP_EOL, $commands);

if (in_array($this->host, ['local', 'localhost', '127.0.0.1'])) {
// Unless local SSH connections are allowed, execute command locally
if (!$this->allowLocalConnection && in_array($this->host, ['local', 'localhost', '127.0.0.1'])) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you move this check to a new function called localConnectionsAllowed that returns a boolean?

In that function do not use $$ but make the code as simple as possible by using early returns.

Copy link
Author

Choose a reason for hiding this comment

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

Alright! But just to make sure I got it: you'd like to move the 2 checks inside this if to a dedicated method ? If so, wouldn't it be doRunCommandLocally(): bool instead ? Thanks

Copy link
Member

Choose a reason for hiding this comment

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

Yup

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants