]> review.fuel-infra Code Review - puppet-modules/puppetlabs-apt.git/commitdiff
Logger; fix a few things so that set() works
authorDavid Schmitt <david.schmitt@puppet.com>
Wed, 26 Jul 2017 14:39:07 +0000 (15:39 +0100)
committerDavid Schmitt <david.schmitt@puppet.com>
Mon, 11 Sep 2017 09:53:34 +0000 (10:53 +0100)
lib/puppet/provider/apt_key2/apt_key2.rb
lib/puppet/type/apt_key2.rb
lib/puppet_x/apt_key/resource_api.rb

index 6f7a26c39ce8249f1acc2b0f3b33ebf919d4a257..e08dfe5ed4e95f055a4f910635090eca5102444c 100644 (file)
@@ -109,7 +109,7 @@ register_provider('apt_key2') do
           end while r.exitstatus == 0
         end
       elsif current && resource[:ensure].to_s == 'present'
-        # No updating implemented
+        logger.warning(title, 'No updating implemented')
         # update(key, noop: noop)
       elsif !current && resource[:ensure].to_s == 'present'
         create(title, resource, noop: noop)
index 4cccaf8bb436818874ddff6469dd29d036dbb08c..5f528e3170be9fe54b38a25c847d1401d1c217d1 100644 (file)
@@ -17,8 +17,9 @@ register_type({
     EOS
     attributes:   {
         ensure:      {
-            type: 'Enum[present, absent]',
-            docs: 'Whether this apt key should be present or absent on the target system.'
+            type:    'Enum[present, absent]',
+            docs:    'Whether this apt key should be present or absent on the target system.',
+            default: 'present',
         },
         id:          {
             type:    'Variant[Pattern[/\A(0x)?[0-9a-fA-F]{8}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{16}\Z/], Pattern[/\A(0x)?[0-9a-fA-F]{40}\Z/]]',
@@ -36,7 +37,8 @@ register_type({
         server:      {
             type:    'Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/]',
             docs:    'The key server to fetch the key from based on the ID. It can either be a domain name or url.',
-            default: :'keyserver.ubuntu.com'
+            kind:    :read_only,
+            default: 'keyserver.ubuntu.com',
         },
         options:     {
             type: 'Optional[String]',
index 990d5aabe51a9ac4000c37e26359369edc1aa7f6..3b1cc078c5e77a4e81005e3e391adc04b6bf2c27 100644 (file)
@@ -43,6 +43,26 @@ module Puppet::SimpleResource
   end
 end
 
+class Logger
+  def initialize(typename)
+    @typename = typename
+  end
+  [:debug, :info, :notice, :warning, :err, :critical, :alert, :emerg].each do |method|
+    define_method(method) do |*args|
+      if args.length == 1
+        puts "#{method}: #{@typename}: #{args.last}"
+      elsif args.length == 2
+        titles = args.first
+        titles = [titles].flatten.compact
+        resources = titles.collect { |t| "#{@typename}[#{t}]" }.join(", ")
+        puts "#{method}: #{resources}: #{args.last}"
+      else
+        puts "#{method}: #{args.map(&inspect).join(", ")}"
+      end
+    end
+  end
+end
+
 def register_type(definition)
   Puppet::Type.newtype(definition[:name].to_sym) do
     @docs = definition[:docs]
@@ -64,7 +84,7 @@ def register_type(definition)
       # TODO: using newparam everywhere would suppress change reporting
       #       that would allow more fine-grained reporting through logger,
       #       but require more invest in hooking up the infrastructure to emulate existing data
-      param_or_property = if options[:read_only] || options[:namevar]
+      param_or_property = if options[:kind] == :read_only || options[:namevar]
                             :newparam
                           else
                             :newproperty
@@ -157,8 +177,12 @@ def register_type(definition)
                 newvalue v do
                 end
               end
+            when 'Pattern[/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/]'
+              newvalues(/\A((hkp|http|https):\/\/)?([a-z\d])([a-z\d-]{0,61}\.)+[a-z\d]+(:\d{2,5})?$/)
             when /^(Enum|Optional|Variant)/
-              fail("#{$1} is not currently supported")
+              fail("Datatype #{$1} is not yet supported in this prototype")
+            else
+              fail("Datatype #{options[:type]} is not yet supported in this prototype")
           end
         end
       end
@@ -187,14 +211,15 @@ def register_type(definition)
         result[:ensure] = :absent
       end
 
+      puts 'retrieve done'
+
       @rapi_current_state = current_state
       result
     end
 
     def flush
       puts 'flush'
-      # binding.pry
-      target_state = self.class.canonicalize([Hash[@parameters.collect { |k, v| [k, v.value] }]])
+      target_state = self.class.canonicalize([Hash[@parameters.collect { |k, v| [k, v.value] }]]).first
       if @rapi_current_state != target_state
         self.class.set({title => @rapi_current_state}, {title => target_state}, false)
       else
@@ -202,6 +227,10 @@ def register_type(definition)
       end
     end
 
+    define_singleton_method(:logger) do
+      return Logger.new(definition[:name])
+    end
+
     def self.commands(*args)
       args.each do |command_group|
         command_group.each do |command_name, command|