You'll hvae to interpolate values into strings.
Start with this hash definition:
node = {
chef: {
node_name: 'foo'
}
}
string definition:
'https://'"#{node[:chef][:node_name]}"'/v1/xyz'
# => "https://foo/v1/xyz"
Roby concatenates adjacent strings into one:
'foo'"bar"'baz' # => "foobarbaz"
But this way code becomes messy and is less human readable:
'foobarbaz' # => "foobarbaz"
similarly:
"foobarbaz" # => "foobarbaz"
Instead of the string use this:
"https://#{node[:chef][:node_name]}/v1/xyz"
# => "https://foo/v1/xyz"
Another problem with your code is :
require 'base64'
"Basic #{Base64.encode64('#{node[\'user\']}:#{node[\'password\']')}"
# > "Basic I3tub2RlWyd1c2VyJ119OiN7bm9kZVsncGFzc3dvcmQnXQ==\n"
the root of your problem:
'#{node[\'user\']}:#{node[\'password\']'
# => "\#{node['user']}:\#{node['password']"
basically when you execute the code, the value passe dto base64.encode64 is the string. You're varaible are never interpolated so you get:
# > "Basic I3tub2RlWyd1c2VyJ119OiN7bm9kZVsncGFzc3dvcmQnXQ==\n"
It doesn't have the correct user or password encoded in it.
Also check, that your node hash may not have user or password keys. A cleaner way to call encode64 is:
encoded_user_password = Base64.encode64(
node.values_at('user', 'password').join(':')
)
Now interpolate into a string:
"Basic #{encoded_user_password}"
Also check ruby's URI class as it's the recommended way of building and manipulating URI's