Ignore extra bash code from openrc
If a user has additional code in their openrc file that isn't just bash variables, the auth provider might fail while parsing it. This change updates the logic to only try and parse lines with OS_ in it to make sure that extra things like bash code are ignored. Change-Id: Id6f5406dcf15642bc0d70caeac30224114bb0669 Closes-Bug: #1699950
This commit is contained in:
parent
93b8e7d365
commit
61044892ad
@ -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
|
||||
|
@ -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
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user