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

Fixed interpolate path split to allow / path #83

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 1 addition & 1 deletion lib/puppet/functions/hiera_vault.rb
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def interpolate(context, paths)
path = context.interpolate(path)
# TODO: Unify usage of '/' - File.join seems to be a mistake, since it won't work on Windows
# secret/puppet/scope1,scope2 => [[secret], [puppet], [scope1, scope2]]
segments = path.split('/').map { |segment| segment.split(',') }
segments = path.split(/(?=\/)/).map { |segment| segment.split(',') }
allowed_paths += build_paths(segments) unless segments.empty?
end
allowed_paths
Expand Down
8 changes: 7 additions & 1 deletion spec/functions/hiera_vault_path_interpolation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
'mounts' => {
VAULT_PATH + "/data" => [
'common',
'rproxy,api'
'rproxy,api',
'/'
]
}
}
Expand All @@ -59,6 +60,7 @@ def vault_test_client
vault_test_client.kv(VAULT_PATH).write("rproxy/ssl", { value: 'ssl'} )
vault_test_client.kv(VAULT_PATH).write("api/oauth", { value: 'oauth'} )
vault_test_client.kv(VAULT_PATH).write("api", { value: 'api_specific'} )
vault_test_client.kv(VAULT_PATH).write("/root", { value: 'root_specific'} )
end

context 'reading secrets' do
Expand All @@ -81,6 +83,10 @@ def vault_test_client
expect(function.lookup_key('api/oauth', vault_options, context))
.to include('value' => 'oauth')
end
it 'returns key from root path' do
expect(function.lookup_key('/root', vault_options, context))
.to include('value' => 'root_specific')
end
end
end
end
Expand Down