hiera-redis 0.1.3 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/hiera/backend/redis_backend.rb +31 -23
- metadata +6 -5
| @@ -2,12 +2,14 @@ class Hiera | |
| 2 2 | 
             
              module Backend
         | 
| 3 3 | 
             
                class Redis_backend
         | 
| 4 4 |  | 
| 5 | 
            -
                  VERSION="0.1 | 
| 5 | 
            +
                  VERSION="0.2.1"
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                  attr_reader :redis
         | 
| 6 8 |  | 
| 7 9 | 
             
                  def initialize
         | 
| 8 10 |  | 
| 9 11 | 
             
                    require 'redis'
         | 
| 10 | 
            -
                    Hiera.debug("Hiera Redis backend starting")
         | 
| 12 | 
            +
                    Hiera.debug("Hiera Redis backend #{VERSION} starting")
         | 
| 11 13 |  | 
| 12 14 | 
             
                    # default values
         | 
| 13 15 | 
             
                    options = {:host => 'localhost', :port => 6379, :db => 0, :password => nil, :timeout => 3, :path => nil}
         | 
| @@ -17,38 +19,45 @@ class Hiera | |
| 17 19 | 
             
                      options[k] = Config[:redis][k] if Config[:redis].has_key?(k)
         | 
| 18 20 | 
             
                    end
         | 
| 19 21 |  | 
| 20 | 
            -
                    @ | 
| 22 | 
            +
                    @redis = Redis.new(options)
         | 
| 21 23 | 
             
                  end
         | 
| 22 24 |  | 
| 23 | 
            -
                  def  | 
| 24 | 
            -
             | 
| 25 | 
            -
                    answer = Backend.empty_answer(resolution_type)
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                    Backend.datasources(scope, order_override) do |source|
         | 
| 25 | 
            +
                  def redis_query(args = {})
         | 
| 28 26 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
                      rkey << source.split('/')
         | 
| 32 | 
            -
                      rkey << key
         | 
| 33 | 
            -
                      rkey = rkey.join(':')
         | 
| 27 | 
            +
                    # convert our seperator in order to maintain yaml compatibility
         | 
| 28 | 
            +
                    redis_key = args[:source].gsub('/', ':')
         | 
| 34 29 |  | 
| 35 | 
            -
             | 
| 30 | 
            +
                    if redis.type(redis_key) == "hash"
         | 
| 31 | 
            +
                      redis.hget(redis_key, args[:key])
         | 
| 32 | 
            +
                    else
         | 
| 33 | 
            +
                      redis_key << ":#{args[:key]}"
         | 
| 34 | 
            +
                      case redis.type(redis_key)
         | 
| 36 35 | 
             
                      when "set"
         | 
| 37 | 
            -
                         | 
| 36 | 
            +
                        redis.smembers(redis_key)
         | 
| 38 37 | 
             
                      when "hash"
         | 
| 39 | 
            -
                         | 
| 38 | 
            +
                        redis.hgetall(redis_key)
         | 
| 40 39 | 
             
                      when "list"
         | 
| 41 | 
            -
                         | 
| 40 | 
            +
                        redis.lrange(redis_key, 0, -1)
         | 
| 42 41 | 
             
                      when "string"
         | 
| 43 | 
            -
                         | 
| 42 | 
            +
                        redis.get(redis_key)
         | 
| 44 43 | 
             
                      when "zset"
         | 
| 45 | 
            -
                         | 
| 44 | 
            +
                        redis.zrange(redis_key, 0, -1)
         | 
| 46 45 | 
             
                      else
         | 
| 47 | 
            -
                        Hiera.debug("No such key: #{ | 
| 48 | 
            -
                         | 
| 46 | 
            +
                        Hiera.debug("No such key: #{redis_key}")
         | 
| 47 | 
            +
                        nil
         | 
| 49 48 | 
             
                      end
         | 
| 49 | 
            +
                    end
         | 
| 50 | 
            +
                  end
         | 
| 50 51 |  | 
| 51 | 
            -
             | 
| 52 | 
            +
                  def lookup(key, scope, order_override, resolution_type)
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                    answer = Backend.empty_answer(resolution_type)
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                    Backend.datasources(scope, order_override) do |source|
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                      data = redis_query(:source => source, :key => key)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                      next unless data
         | 
| 52 61 | 
             
                      new_answer = Backend.parse_answer(data, scope)
         | 
| 53 62 |  | 
| 54 63 | 
             
                      case resolution_type
         | 
| @@ -65,7 +74,6 @@ class Hiera | |
| 65 74 | 
             
                    end
         | 
| 66 75 |  | 
| 67 76 | 
             
                    answer
         | 
| 68 | 
            -
                    
         | 
| 69 77 | 
             
                  end
         | 
| 70 78 | 
             
                end
         | 
| 71 79 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,13 +1,13 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: hiera-redis
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              hash:  | 
| 4 | 
            +
              hash: 21
         | 
| 5 5 | 
             
              prerelease: 
         | 
| 6 6 | 
             
              segments: 
         | 
| 7 7 | 
             
              - 0
         | 
| 8 | 
            +
              - 2
         | 
| 8 9 | 
             
              - 1
         | 
| 9 | 
            -
               | 
| 10 | 
            -
              version: 0.1.3
         | 
| 10 | 
            +
              version: 0.2.1
         | 
| 11 11 | 
             
            platform: ruby
         | 
| 12 12 | 
             
            authors: 
         | 
| 13 13 | 
             
            - Adam Kosmin c/o Reliant Security, Inc.
         | 
| @@ -15,7 +15,7 @@ autorequire: | |
| 15 15 | 
             
            bindir: bin
         | 
| 16 16 | 
             
            cert_chain: []
         | 
| 17 17 |  | 
| 18 | 
            -
            date: 2012- | 
| 18 | 
            +
            date: 2012-05-30 00:00:00 Z
         | 
| 19 19 | 
             
            dependencies: []
         | 
| 20 20 |  | 
| 21 21 | 
             
            description: Allows hiera functions to pull data from a Redis database.
         | 
| @@ -58,9 +58,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 58 58 | 
             
            requirements: 
         | 
| 59 59 | 
             
            - hiera
         | 
| 60 60 | 
             
            rubyforge_project: 
         | 
| 61 | 
            -
            rubygems_version: 1.8. | 
| 61 | 
            +
            rubygems_version: 1.8.15
         | 
| 62 62 | 
             
            signing_key: 
         | 
| 63 63 | 
             
            specification_version: 3
         | 
| 64 64 | 
             
            summary: A Redis backend for Hiera.
         | 
| 65 65 | 
             
            test_files: []
         | 
| 66 66 |  | 
| 67 | 
            +
            has_rdoc: false
         |