Skip to content

Instantly share code, notes, and snippets.

@voelzmo
Last active August 17, 2016 14:32
Show Gist options
  • Save voelzmo/cf5a737d1f406beb6ad9bc32a1e8845b to your computer and use it in GitHub Desktop.
Save voelzmo/cf5a737d1f406beb6ad9bc32a1e8845b to your computer and use it in GitHub Desktop.
module Bosh::OpenStackCloud
class CpiLambda
CONTEXT_CA_PATH = '/var/vcap/jobs/openstack_cpi/config/cacert_context.pem'
def self.create(cpi_config, cpi_log, ca_cert_from_config, ca_cert_from_context=CONTEXT_CA_PATH)
lambda do |context|
unless cpi_config.has_key?('cloud') && cpi_config['cloud'].has_key?('properties')
raise "Could not find cloud properties in the configuration"
end
cloud_properties = cpi_config['cloud']['properties']
cloud_properties['cpi_log'] = cpi_log
connection_options = cloud_properties['openstack']['connection_options']
if !connection_options.delete('ca_cert').nil?
connection_options['ssl_ca_file'] = ca_cert_from_config
end
# allow openstack config to be overwritten dynamically by context
if context && context['cpi_properties']
cloud_properties['openstack'] = context['cpi_properties']
connection_options = cloud_properties['openstack']['connection_options']
if !connection_options.delete('ca_cert').nil?
write_ca_cert_to_disk(cloud_properties, CONTEXT_CA_PATH)
connection_options['ssl_ca_file'] = CONTEXT_CA_PATH
end
end
Bosh::Clouds::Openstack.new(cloud_properties)
end
end
private
def self.write_ca_cert_to_disk(cloud_properties, ca_cert_path)
connection_options = cloud_properties['openstack']['connection_options']
File.write(ca_cert_path, connection_options['ca_cert']) if connection_options && connection_options['ca_cert']
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment