@@ -21,6 +21,8 @@ def register(schema)
2121
2222 # retrieve a Hash of transport schemas, keyed by their name.
2323 # Only already loaded transports are returned.
24+ # use Puppet::Util::Autoload.new(self, 'puppet/transport/schema').loadall(current_environment) to load all transport schemas
25+ # note that loadall uses `require` and thus does not re-load changed files, nor does it re-populate the internal cache
2426 def list
2527 Marshal . load ( Marshal . dump ( transports ) )
2628 end
@@ -39,13 +41,25 @@ def list_all_transports(force_environment)
3941 end
4042 module_function :list_all_transports # rubocop:disable Style/AccessModifierDeclarations
4143
42- # Loads all schemas using the Puppet Autoloader.
44+ # Loads all schemas using the Puppet Autoloader. This method is clearing the cache and forcing `Kernel.load`, so that the cache is up-to-date.
4345 def self . load_all_schemas
4446 require 'puppet'
4547 require 'puppet/settings'
4648 require 'puppet/util/autoload'
47- @autoloader ||= Puppet ::Util ::Autoload . new ( self , 'puppet/transport/schema' )
48- @autoloader . loadall ( current_environment )
49+
50+ # Since we're force-loading all schemas below, we can replace the cache here completely
51+ @transports = { }
52+
53+ loader = Puppet ::Util ::Autoload
54+ # from puppetlabs/puppet:lib/puppet/util/autoload.rb
55+ # Puppet::Util::Autoload.loadall('puppet/transport/schema', current_environment)
56+ path = 'puppet/transport/schema'
57+ env = current_environment
58+ # Load every instance of everything we can find.
59+ loader . files_to_load ( path , env ) . each do |file |
60+ name = file . chomp ( '.rb' )
61+ loader . load_file ( name , env )
62+ end
4963 end
5064 private_class_method :load_all_schemas
5165
@@ -108,12 +122,7 @@ def self.wrap_sensitive(name, connection_info)
108122 private_class_method :wrap_sensitive
109123
110124 def self . transports
111- env = current_environment
112- if env
113- ObjectIdCacheAdapter . adapt ( env ) . retrieve ( :rsapi_transport_cache )
114- else
115- @transports_default ||= { }
116- end
125+ @transports ||= { }
117126 end
118127 private_class_method :transports
119128
@@ -159,19 +168,4 @@ def self.clean_bolt_attributes(transport_schema, connection_info)
159168 nil
160169 end
161170 private_class_method :clean_bolt_attributes
162-
163- # copy from https://github.com/puppetlabs/puppet/blob/8cae8a17dbac08d2db0238d5bce2f1e4d1898d65/lib/puppet/pops/adapters.rb#L6-L17
164- # to keep backwards compatibility with puppet4 and 5, which don't have this yet.
165- class ObjectIdCacheAdapter < Puppet ::Pops ::Adaptable ::Adapter
166- attr_accessor :cache
167-
168- def initialize
169- @cache = { }
170- end
171-
172- # Retrieves a mutable hash with all stored values
173- def retrieve ( obj )
174- @cache [ obj . __id__ ] ||= { }
175- end
176- end
177171end
0 commit comments