Sha256: 9890318e7a7d95fe322f38761bcb79b2e23888e737cfafcd30c252269c280625

Contents?: true

Size: 1.49 KB

Versions: 1

Compression:

Stored size: 1.49 KB

Contents

module Ridley
  # @author Jamie Winsor <jamie@vialstudios.com>
  class EncryptedDataBagItemResource
    class << self
      # Finds a data bag item and decrypts it.
      #
      # @param [Ridley::Client] client
      # @param [Ridley::DataBagResource] data_bag
      # @param [String, #chef_id] object
      #
      # @return [nil, Ridley::DataBagItemResource]
      def find(client, data_bag, object)
        find!(client, data_bag, object)
      rescue Errors::HTTPNotFound
        nil
      end

      # Finds a data bag item and decrypts it. Throws an exception if the item doesn't exist.
      #
      # @param [Ridley::Client] client
      # @param [Ridley::DataBagResource] data_bag
      # @param [String, #chef_id] object
      #
      # @raise [Errors::HTTPNotFound]
      #   if a resource with the given chef_id is not found
      #
      # @return [nil, Ridley::DataBagItemResource]
      def find!(client, data_bag, object)
        data_bag_item = DataBagItem.find!(client, data_bag, object)
        data_bag_item.decrypt
        new(client, data_bag, data_bag_item.attributes)
      end
    end

    attr_reader :data_bag
    attr_reader :attributes

    # @param [Ridley::Client] client
    # @param [Ridley::DataBagResource] data_bag
    # @param [#to_hash] attributes
    def initialize(client, data_bag, attributes = {})
      @client     = client
      @data_bag   = data_bag
      @attributes = attributes
    end

    def to_s
      self.attributes
    end

    private

      attr_reader :client
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ridley-0.7.0.rc1 lib/ridley/resources/encrypted_data_bag_item_resource.rb