Class: OpenVPNConfigurator::RouteGatherer

Inherits:
Object
  • Object
show all
Includes:
SemanticLogger::Loggable
Defined in:
lib/openvpn_configurator/route_gatherer.rb

Constant Summary collapse

AWS_IP_RANGES_URL =
'https://ip-ranges.amazonaws.com/ip-ranges.json'.freeze

Instance Method Summary collapse

Instance Method Details

#extend_template(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/openvpn_configurator/route_gatherer.rb', line 20

def extend_template(options)
	template = read_file options[:input_path]
	old_output = read_file options[:output_path], nonexistent_behavior: :empty_string

	routes = gather_routes options
	reduced = reduce_routes routes
	rendered = render_routes reduced, client: !!options[:client]

	result = format "%s\n\n\n# Added by OpenVPN Configurator v%s at %s\n%s", template, VERSION, Time.now.iso8601(6), rendered
	if result != old_output
		logger.info "Output content changed, rewriting file #{options[:output_path].inspect}"
		write_file options[:output_path], result
		change_actions options
	else
		logger.info 'Output content unchanged, no actions taken.'
	end
end