Sha256: 990252e988debff46229ea75acae2fc3d75970da34c2e3e67f0344bb20175beb

Contents?: true

Size: 1.4 KB

Versions: 12

Compression:

Stored size: 1.4 KB

Contents

require 'chef/knife'

module KnifeSpork
  class SporkDataBagDelete < Chef::Knife

    deps do
      require 'knife-spork/runner'
      require 'json'
      require 'chef/knife/data_bag_delete'
    end

    banner 'knife spork data bag delete BAG [ITEM] (options)'


    def run
      self.class.send(:include, KnifeSpork::Runner)
      self.config = Chef::Config.merge!(config)

      if @name_args.length == 2
        @object_name = @name_args.first
        @object_secondary_name = @name_args.last
        run_plugins(:before_databagitemdelete)
        pre_databag = load_databag_item(@object_name,@object_secondary_name)
        databag_delete
        post_databag = {}
        @object_difference = json_diff(pre_databag,post_databag).to_s
        run_plugins(:after_databagitemdelete)
      elsif @name_args.length == 1
        @object_name = @name_args.first
        run_plugins(:before_databagdelete)
        pre_databag = load_databag(@object_name)
        databag_delete
        post_databag =  {}
        @object_difference = json_diff(pre_databag,post_databag).to_s
        run_plugins(:after_databagdelete)
      else
        show_usage
        ui.fatal("You must specify at least a data bag name")
        exit 1
      end
    end

    private
    def databag_delete
      dbd = Chef::Knife::DataBagDelete.new
      dbd.name_args = @name_args
      dbd.config[:editor] = config[:editor]
      dbd.run
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
knife-spork-1.7.2 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.7.1 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.7.0 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.6.3 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.6.2 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.6.1 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.6.0 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.5.1 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.5.0 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.4.2 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.4.1 lib/chef/knife/spork-databag-delete.rb
knife-spork-1.4.0 lib/chef/knife/spork-databag-delete.rb