def get(names = [])
cli_args = %w(adv --list-keys --with-colons --fingerprint --fixed-list-mode)
- key_output = apt_key(cli_args).encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '')
+ key_output = apt_key_lines(*cli_args)
pub_line = nil
fpr_line = nil
- result = key_output.split("\n").collect do |line|
+ result = key_output.collect do |line|
+ line = line.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '')
if line.start_with?('pub')
pub_line = line
elsif line.start_with?('fpr')
fpr_line = line
end
+ # puts "debug: parsing #{line}; fpr: #{fpr_line.inspect}; pub: #{pub_line.inspect}"
next unless (pub_line and fpr_line)
+ # puts "debug: key_line_to_hash"
+
hash = key_line_to_hash(pub_line, fpr_line)
# reset scanning
end
def to_manifest
- [
- "apt_key { #{values[:name].inspect}: ",
- ] + values.keys.select { |k| k != :name }.collect { |k| " #{k} => #{values[k].inspect}," } + ['}']
+ (["apt_key { #{values[:name].inspect}: "] + values.keys.select { |k| k != :name }.collect { |k| " #{k} => #{values[k].inspect}," } + ['}']).join("\n")
end
end
end
end
if options[:namevar]
- # puts 'setting namevar'
+ puts 'setting namevar'
isnamevar
has_namevar = true
namevar_name = name
end
end
- def self.instances
+ define_singleton_method(:instances) do
puts 'instances'
# klass = Puppet::Type.type(:api)
+ # force autoloading of the provider
+ autoloaded_provider = provider(name)
get.collect do |resource_hash|
Puppet::SimpleResource::TypeShim.new(resource_hash[namevar_name], resource_hash)
end
end
- def retrieve
+ define_method(:retrieve) do
puts 'retrieve'
result = Puppet::Resource.new(self.class, title)
current_state = self.class.get.find { |h| h[namevar_name] == title }
end
def self.commands(*args)
- puts "registering command: #{args.inspect}"
+ args.each do |command_group|
+ command_group.each do |command_name, command|
+ puts "registering command: #{command_name}, using #{command}"
+ define_singleton_method(command_name) do |*args|
+ puts "spawn([#{command.to_s}, #{command.to_s}], #{args.inspect})"
+ # TODO: capture output to debug stream
+ p = Process.spawn([command, command], *args)
+ Process.wait(p)
+ unless $?.exitstatus == 0
+ raise Puppet::ResourceError, "#{command} failed with exit code #{$?.exitstatus}"
+ end
+ end
+
+ define_singleton_method("#{command_name}_lines") do |*args|
+ puts "capture3([#{command.to_s}, #{command.to_s}], #{args.inspect})"
+ stdin_str, stderr_str, status = Open3.capture3([command, command], *args)
+ unless status.exitstatus == 0
+ raise Puppet::ResourceError, "#{command} failed with exit code #{$?.exitstatus}"
+ end
+ stdin_str.split("\n")
+ end
+ end
+ end
end
end
end
def register_provider(typename, &block)
type = Puppet::Type.type(typename.to_sym)
type.instance_eval &block
+ # require'pry';binding.pry
end