Skip to content

Commit

Permalink
(PUP-9747) Filter extra bolt params {wip}
Browse files Browse the repository at this point in the history
This is an initial draft of the solution. Still needs tests and validation.
  • Loading branch information
DavidS committed Jun 11, 2019
1 parent d249941 commit 727a5d1
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions lib/puppet/resource_api/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,31 @@ def self.validate(name, connection_info)
environment: current_environment,
}
end

# Attributes we expect from bolt, but want to ignore if the transport does not expect them
[:uri, :host, :protocol, :user, :port].each do |attribute_name|
if connection_info.key?(attribute_name) && !transports[name].attributes.key?(attribute_name)
discard_known_good_attribute(transport_name, attribute_name)
connection_info.delete(attribute_name)
end
end

# Attributes that bolt emits, but we want to ignore if the transport does not expect them
([:name, :path, :query, :"run-on", :"remote-transport", :implementations] + connection_info.keys.grep { |k| k.to_s.starts_with? 'remote-' }).each do |attribute_name|
if connection_info.key?(attribute_name) && !transports[name].attributes.key?(attribute_name)
discard_known_bad_attribute(transport_name, attribute_name)
connection_info.delete(attribute_name)
end
end

# remove any other attributes the transport is not prepared to handle
connection_info.keys.each do |attribute_name|
if connection_info.key?(attribute_name) && !transports[name].attributes.key?(attribute_name)
discard_unknown_attribute(transport_name, attribute_name)
connection_info.delete(attribute_name)
end
end

message_prefix = 'The connection info provided does not match the Transport Schema'
transport_schema.check_schema(connection_info, message_prefix)
transport_schema.validate(connection_info)
Expand Down Expand Up @@ -93,4 +118,19 @@ def self.current_environment
end
end
private_class_method :current_environment

def self.discard_known_bad_attribute(transport_name, attribute_name)
get_context(transport_name).debug('Discarding bolt metaparameter: %{attribute_name}' % { attribute_name: attribute_name })
end
private_class_method :discard_known_bad_attribute

def self.discard_known_good_attribute(transport_name, attribute_name)
get_context(transport_name).info('Discarding superfluous bolt attribute: %{attribute_name}' % { attribute_name: attribute_name })
end
private_class_method :discard_known_good_attribute

def self.discard_unknown_attribute(transport_name, attribute_name)
get_context(transport_name).warning('Discarding unknown attribute: %{attribute_name}' % { attribute_name: attribute_name })
end
private_class_method :discard_unknown_attribute
end

0 comments on commit 727a5d1

Please sign in to comment.