<commit_before>require 'chef/provider'
require 'etcd'



class Chef
  class  Provider
    class Etcd < Chef::Provider

      def initialize(new_resource, run_context)
        super(new_resource, run_context)
      end

      def load_current_resource
        @current_resource ||= Chef::Resource::Etcd.new(new_resource.name)
        if key_exist?
          @current_resource.value(current_value)
        end
        @current_resource
      end

      def whyrun_supported?
        true
      end

      def config
        @config ||= Chef::Config[:etcd]
      end

      def etcd
        @etcd ||= ::Etcd.client(config)
      end  


      def key_exist?
        exist = true
        begin
          etcd.get(new_resource.key)
        rescue Net::HTTPServerException => e
          exist = false
        end
        exist
      end

      def current_value
        if key_exist?
          etcd.get(new_resource.key).value
        else
          nil
        end
      end

      def action_set
        if @current_resource.value == new_resource.value
          Chef::Log.debug(" etcd #{new_resource.key} is in sync")
        else
          converge_by "will set value of key #{new_resource.key}" do
            etcd.set(new_resource.key, new_resource.value)
            new_resource.updated_by_last_action(true)
          end
        end
      end
      def action_get
        converge_by "will set value of key #{new_resource.key}" do
          if key_exist?
            current_value
          else
            nil
          end
          new_resource.updated_by_last_action(true)
        end
      end

      def action_test_and_set
        begin
          etcd.test_and_set(new_resource.key, new_resource.value, new_resource.prev_value, new_resource.ttl)
        rescue Net::HTTPServerException => e
          converge_by "will not be able test_and_set value of key #{new_resource.key}" do
            new_resource.updated_by_last_action(true)
          end
        end
      end

      def action_watch
        converge_bey "will wait for update from etcd key #{new_resource.key}" do
          etcd.watch(new_resource.key)
          new_resource.updated_by_last_action(true)
        end
      end

      def action_delete
        if key_exist?
          converge_by "will delete etcd key #{new_resource.key}" do
            etcd.delete(new_resource.key)
            new_resource.updated_by_last_action(true)
          end
        else
          Chef::Log.debug("etcd key #{new_resource.key} does not exist")
        end
      end
    end
  end
end

<commit_msg>Fix a typo in etcd provider.<commit_after>require 'chef/provider'
require 'etcd'



class Chef
  class  Provider
    class Etcd < Chef::Provider

      def initialize(new_resource, run_context)
        super(new_resource, run_context)
      end

      def load_current_resource
        @current_resource ||= Chef::Resource::Etcd.new(new_resource.name)
        if key_exist?
          @current_resource.value(current_value)
        end
        @current_resource
      end

      def whyrun_supported?
        true
      end

      def config
        @config ||= Chef::Config[:etcd]
      end

      def etcd
        @etcd ||= ::Etcd.client(config)
      end


      def key_exist?
        exist = true
        begin
          etcd.get(new_resource.key)
        rescue Net::HTTPServerException => e
          exist = false
        end
        exist
      end

      def current_value
        if key_exist?
          etcd.get(new_resource.key).value
        else
          nil
        end
      end

      def action_set
        if @current_resource.value == new_resource.value
          Chef::Log.debug(" etcd #{new_resource.key} is in sync")
        else
          converge_by "will set value of key #{new_resource.key}" do
            etcd.set(new_resource.key, new_resource.value)
            new_resource.updated_by_last_action(true)
          end
        end
      end
      def action_get
        converge_by "will get value of key #{new_resource.key}" do
          if key_exist?
            current_value
          else
            nil
          end
          new_resource.updated_by_last_action(true)
        end
      end

      def action_test_and_set
        begin
          etcd.test_and_set(new_resource.key, new_resource.value, new_resource.prev_value, new_resource.ttl)
        rescue Net::HTTPServerException => e
          converge_by "will not be able test_and_set value of key #{new_resource.key}" do
            new_resource.updated_by_last_action(true)
          end
        end
      end

      def action_watch
        converge_bey "will wait for update from etcd key #{new_resource.key}" do
          etcd.watch(new_resource.key)
          new_resource.updated_by_last_action(true)
        end
      end

      def action_delete
        if key_exist?
          converge_by "will delete etcd key #{new_resource.key}" do
            etcd.delete(new_resource.key)
            new_resource.updated_by_last_action(true)
          end
        else
          Chef::Log.debug("etcd key #{new_resource.key} does not exist")
        end
      end
    end
  end
end


{'fraction_non_alphanumeric': 0.06747034804588761, 'fraction_numerical': 0.0, 'mean_word_length': 1.8063284233497, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '781821', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1507, 'n_words': 357}