Merge "Ignore extra bash code from openrc"

This commit is contained in:
Jenkins 2017-07-06 16:29:13 +00:00 committed by Gerrit Code Review
commit 5dee44333a
3 changed files with 28 additions and 4 deletions

View File

@ -16,10 +16,13 @@ module Puppet::Provider::Openstack::Auth
rcfile = [filename, '/root/openrc'].detect { |f| File.exists? f }
unless rcfile.nil?
File.open(rcfile).readlines.delete_if{|l| l=~ /^#|^$/ }.each do |line|
key, value = line.split('=')
key = key.split(' ').last
value = value.chomp.gsub(/'/, '')
env.merge!(key => value) if key =~ /OS_/
# we only care about the OS_ vars from the file LP#1699950
if line =~ /OS_/
key, value = line.split('=')
key = key.split(' ').last
value = value.chomp.gsub(/'/, '')
env.merge!(key => value) if key =~ /OS_/
end
end
end
return env

View File

@ -0,0 +1,5 @@
---
fixes:
- |
Improve openrc parsing to prevent issues when additional bash code is
present in a user's openrc file. LP#1699950

View File

@ -102,6 +102,22 @@ describe Puppet::Provider::Openstack::Auth do
end
end
context 'with a valid RC file with extra code in it' do
it 'provides a hash' do
mock = "export OS_USERNAME='test'\nexport OS_PASSWORD='abc123'\nexport OS_PROJECT_NAME='test'\nexport OS_AUTH_URL='http://127.0.0.1:5000'\n_openstack() {\n foo\n} "
filename = 'file'
File.expects(:exists?).with('file').returns(true)
File.expects(:open).with('file').returns(StringIO.new(mock))
response = klass.get_os_vars_from_rcfile(filename)
expect(response).to eq({
"OS_AUTH_URL" => "http://127.0.0.1:5000",
"OS_PASSWORD" => "abc123",
"OS_PROJECT_NAME" => "test",
"OS_USERNAME" => "test"})
end
end
context 'with an empty file' do
it 'provides an empty hash' do
filename = 'file'