|
6 | 6 | class Puppet::ResourceApi::Transport::Wrapper |
7 | 7 | attr_reader :transport, :schema |
8 | 8 |
|
9 | | - def initialize(name, url_or_config) |
10 | | - if url_or_config.is_a? String |
11 | | - url = URI.parse(url_or_config) |
12 | | - raise "Unexpected url '#{url_or_config}' found. Only file:/// URLs for configuration supported at the moment." unless url.scheme == 'file' |
| 9 | + def initialize(name, url_or_config_or_transport) |
| 10 | + if url_or_config_or_transport.is_a? String |
| 11 | + url = URI.parse(url_or_config_or_transport) |
| 12 | + raise "Unexpected url '#{url_or_config_or_transport}' found. Only file:/// URLs for configuration supported at the moment." unless url.scheme == 'file' |
13 | 13 | raise "Trying to load config from '#{url.path}, but file does not exist." if url && !File.exist?(url.path) |
14 | 14 | config = self.class.deep_symbolize(Hocon.load(url.path, syntax: Hocon::ConfigSyntax::HOCON) || {}) |
15 | | - else |
16 | | - config = url_or_config |
| 15 | + elsif url_or_config_or_transport.is_a? Hash |
| 16 | + config = url_or_config_or_transport |
| 17 | + elsif transport_class?(name, url_or_config_or_transport) |
| 18 | + @transport = url_or_config_or_transport |
17 | 19 | end |
18 | 20 |
|
19 | | - @transport = Puppet::ResourceApi::Transport.connect(name, config) |
| 21 | + @transport ||= Puppet::ResourceApi::Transport.connect(name, config) |
20 | 22 | @schema = Puppet::ResourceApi::Transport.list[name] |
21 | 23 | end |
22 | 24 |
|
| 25 | + def transport_class?(name, transport) |
| 26 | + class_name = name.split('_').map { |e| e.capitalize }.join |
| 27 | + expected = Puppet::Transport.const_get(class_name).to_s |
| 28 | + expected == transport.class.to_s |
| 29 | + end |
| 30 | + |
23 | 31 | def facts |
24 | 32 | context = Puppet::ResourceApi::PuppetContext.new(@schema) |
25 | 33 | # @transport.facts + custom_facts # look into custom facts work by TP |
|
0 commit comments