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

(maint) Expand filepaths passed on the CLI relative to cwd #1791

Merged
merged 1 commit into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,5 @@ locales/
documentation/plan_functions.md
documentation/bolt_command_reference.md
documentation/bolt_configuration_reference.md
tasks/
plans/
6 changes: 3 additions & 3 deletions lib/bolt/bolt_option_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ def initialize(options)
@options[:password] = STDIN.noecho(&:gets).chomp
STDERR.puts
end
define('--private-key KEY', 'Private ssh key to authenticate with') do |key|
@options[:'private-key'] = key
define('--private-key KEY', 'Path to private ssh key to authenticate with') do |key|
@options[:'private-key'] = File.expand_path(key)
end
define('--[no-]host-key-check', 'Check host keys with SSH') do |host_key_check|
@options[:'host-key-check'] = host_key_check
Expand Down Expand Up @@ -718,7 +718,7 @@ def initialize(options)
end
define('--hiera-config FILEPATH',
'Specify where to load Hiera config from (default: ~/.puppetlabs/bolt/hiera.yaml)') do |path|
@options[:'hiera-config'] = path
@options[:'hiera-config'] = File.expand_path(path)
end
define('-i', '--inventoryfile FILEPATH',
'Specify where to load inventory from (default: ~/.puppetlabs/bolt/inventory.yaml)') do |path|
Expand Down
12 changes: 11 additions & 1 deletion spec/bolt/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,14 +422,24 @@ def stub_config(file_content = {})
describe "key" do
it "accepts a private key" do
allow(Bolt::Util).to receive(:validate_file).and_return(true)
path = '~/.ssh/google_compute_engine'
path = File.expand_path('~/.ssh/google_compute_engine')
cli = Bolt::CLI.new(%W[ command run uptime
--private-key #{path}
--targets foo])
expect(cli.parse).to include('private-key': path)
expect(cli.config.transports['ssh']['private-key']).to eq(File.expand_path(path))
end

it "expands private key relative to cwd" do
allow(Bolt::Util).to receive(:validate_file).and_return(true)
path = './ssh/google_compute_engine'
cli = Bolt::CLI.new(%W[ command run uptime
--private-key #{path}
--targets foo])
expect(cli.parse).to include('private-key': File.expand_path(path))
expect(cli.config.transports['ssh']['private-key']).to eq(File.expand_path(path))
end

it "generates an error message if no key value is given" do
cli = Bolt::CLI.new(%w[command run --targets foo --private-key])
expect {
Expand Down
6 changes: 3 additions & 3 deletions spec/integration/lookup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
after(:each) { Puppet.settings.send(:clear_everything_for_tests) }

let(:boltdir) { fixture_path('hiera') }
let(:hiera_config) { 'hiera.yaml' }
let(:hiera_config) { File.join(boltdir, 'hiera.yaml') }
let(:plan) { 'test::lookup' }

let(:cli_command) {
Expand Down Expand Up @@ -87,7 +87,7 @@
end

context 'with interpolations' do
let(:hiera_config) { 'hiera_interpolations.yaml' }
let(:hiera_config) { File.join(boltdir, 'hiera_interpolations.yaml') }

it 'returns an error' do
result = run_cli_json(cli_command + %w[key=test::interpolations])
Expand Down Expand Up @@ -124,7 +124,7 @@
end

context 'with a missing backend' do
let(:hiera_config) { 'hiera_missing_backend.yaml' }
let(:hiera_config) { File.join(boltdir, 'hiera_missing_backend.yaml') }

it 'returns an error' do
result = run_cli_json(cli_command + %w[key=test::backends])
Expand Down