This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 208
Add the possibility of using a dedicated private key #693
Open
IshentRas
wants to merge
1
commit into
openshift:master
Choose a base branch
from
IshentRas:enhancement_private-key
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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 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 |
---|---|---|
|
@@ -15,6 +15,8 @@ class Ssh < Base | |
|
||
You may run a specific SSH command by passing one or more arguments, or use a | ||
different SSH executable or pass options to SSH with the '--ssh' option. | ||
|
||
A dedicated private key can be passed to SSH with the '--key' option. | ||
|
||
To use the '--ssh' flag with an SSH executable path containing a space, wrap | ||
the executable path with double quotes: | ||
|
@@ -24,6 +26,7 @@ class Ssh < Base | |
takes_application :argument => true | ||
argument :command, "Command to run in the application's SSH session", ['--command COMMAND'], :type => :list, :optional => true | ||
option ["--ssh PATH"], "Path to your SSH executable or additional options" | ||
option ["--key KEY"], "Private KEY to use for the SSH connections. Requires a private key." | ||
option ["--gears"], "Execute this command on all gears in the app. Requires a command." | ||
option ["--limit INTEGER"], "Limit the number of simultaneous SSH connections opened with --gears (default: 5).", :type => Integer, :default => 5 | ||
option ["--raw"], "Output only the data returned by each host, no hostname prefix." | ||
|
@@ -42,8 +45,12 @@ def run(_, command) | |
$stderr.puts "Connecting to #{rest_app.ssh_string.to_s} ..." unless command.present? | ||
|
||
debug "Using user specified SSH: #{options.ssh}" if options.ssh | ||
|
||
command_line = [RHC::Helpers.split_path(ssh), ('-vv' if debug?), rest_app.ssh_string.to_s, command].flatten.compact | ||
debug "Using user specified SSH Private Key: #{options.key}" if options.key | ||
if options.key | ||
command_line = [RHC::Helpers.split_path(ssh), ('-vv' if debug?), rest_app.ssh_string.to_s, "-i", options.key, command].flatten.compact | ||
else | ||
command_line = [RHC::Helpers.split_path(ssh), ('-vv' if debug?), rest_app.ssh_string.to_s, command].flatten.compact | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could be simplified by using something like |
||
|
||
debug "Invoking Kernel.exec with #{command_line.inspect}" | ||
Kernel.send(:exec, *command_line) | ||
|
This file contains 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 |
---|---|---|
|
@@ -171,6 +171,32 @@ | |
end | ||
end | ||
|
||
describe 'app ssh custom private key' do | ||
let(:arguments) { ['app', 'ssh', 'app1', '--key', 'valid_private_key'] } | ||
|
||
context 'when custom private key is valid' do | ||
before(:each) do | ||
@domain = rest_client.add_domain("mockdomain") | ||
@domain.add_application("app1", "mock_type") | ||
Kernel.should_receive(:exec).with("ssh", "fakeuuidfortestsapp1@127.0.0.1", "-i", "valid_private_key").and_return(0) | ||
#subject.class.any_instance.stub(:discover_git_executable).and_return('git') | ||
end | ||
it { run_output.should match("Connecting to fakeuuidfortestsapp") } | ||
it { expect{ run }.to exit_with_code(0) } | ||
end | ||
|
||
context 'when custom private key does not exist' do | ||
let(:arguments) { ['app', 'ssh', 'app1', '--key', 'nonexistent_private_key'] } | ||
it { expect { run }.to exit_with_code(1) } | ||
end | ||
|
||
context 'when custom private key is inaccessible' do | ||
let(:arguments) { ['app', 'ssh', 'app1', '--key', 'inaccessible_private_key'] } | ||
it { expect { run }.to exit_with_code(1) } | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the "private key is inaccessible" different from the "private key does not exist" test? |
||
|
||
end | ||
|
||
describe 'app ssh custom ssh with spaces and arguments' do | ||
let(:arguments) { ['app', 'ssh', 'app1', '--ssh', '"/path/to /ssh" --with_custom_flag'] } | ||
context 'when custom ssh does not exist as a path' do | ||
|
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.
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'd rather this were
--ssh_key
.