jerakia 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9f2853d09f628caae07235bf40b294e2025dce4
4
- data.tar.gz: b349c9f8181a4e47a44b53bf9d74602dfcbc2199
3
+ metadata.gz: a4dda5d22fe6e0fa29b9ce287a9b44f20c2fe3e9
4
+ data.tar.gz: 21e5f066edc6cd60249767e8ccd277559d9419d6
5
5
  SHA512:
6
- metadata.gz: 51b217b1c2a946378a4fd8947de57277bc74d2b1dfe659ca8363314b8ecf28b3905b960c04e5b0cece3063d5402fa9b862238fdde2a43755b8a2b9dd4fe38de3
7
- data.tar.gz: 3f35a0de6e1b987c41652e572ad31ecdd4aab804e109caae2729728bdb5a319227e626c7e2e1841ce6888e94b9258a2dc4890d20d71dee6b8d4c996b48f61fdb
6
+ metadata.gz: ab871bf140fd08288bbf39a7be8101c7151823c8eb3249e47e7ed89468399e500111edfc2dc5e108fdae7a557213811afedc5f3e8fb39c310fd27e68c718d187
7
+ data.tar.gz: 2d793c5c420b128380d813c92e99bb7c56ff137003a016b2f624eb54e9c2a225172f7a7ae49c40495bbbf98a8342a723347bb3deba7699aaab036268d35b511b
@@ -0,0 +1,82 @@
1
+ require 'jerakia/cache/file'
2
+
3
+ class Jerakia::Datasource
4
+ module File
5
+ attr_reader :file_format
6
+
7
+ def load_format_handler
8
+ format = options[:format] || :yaml
9
+ class_name = format.to_s.capitalize
10
+ require "jerakia/datasource/file/#{format}"
11
+ @file_format = eval "Jerakia::Datasource::File::#{class_name}"
12
+ end
13
+
14
+ def cache
15
+ Jerakia::Cache::File
16
+ end
17
+
18
+ def get_file_with_cache(diskname)
19
+ if options[:enable_caching]
20
+ Jerakia.log.debug("Querying cache for file #{diskname}")
21
+ cache.retrieve(diskname)
22
+ else
23
+ ::File.read(diskname) if ::File.exists?(diskname)
24
+ end
25
+ end
26
+
27
+ def list_fragments(prefix, extension)
28
+ Dir["#{prefix}.d/*.#{extension}"] if ::File.directory?("#{prefix}.d")
29
+ end
30
+
31
+ def read_from_file(fname)
32
+ fpath = []
33
+ fpath << options[:docroot] unless fname[0] == '/'
34
+ fpath << [fname, lookup.request.namespace]
35
+
36
+ extension = options[:extension] || @file_format::EXTENSION
37
+ diskname_prefix = ::File.join(fpath.flatten).gsub(/\/$/, '').to_s
38
+ diskname = "#{diskname_prefix}.#{extension}"
39
+
40
+ files = [diskname]
41
+ files << list_fragments(diskname_prefix, extension)
42
+
43
+ raw_data = ''
44
+
45
+ files.flatten.compact.each do |f|
46
+ Jerakia.log.debug("read_from_file() #{f}")
47
+ file_contents = get_file_with_cache(f)
48
+ raw_data << file_contents if file_contents
49
+ end
50
+
51
+ begin
52
+ file_format.convert(raw_data)
53
+ rescue Jerakia::FileParseError => e
54
+ raise Jerakia::FileParseError, "While parsing #{diskname}: #{e.message}"
55
+ end
56
+ end
57
+
58
+ def run
59
+ #
60
+ # Do the lookup
61
+
62
+ Jerakia.log.debug("Searching key #{lookup.request.key} from file format #{options[:format]} (#{whoami})")
63
+ option :searchpath, :type => Array, :mandatory => true
64
+ option :format, :type => Symbol, :default => :yaml
65
+ option :docroot, :type => String, :default => '/etc/jerakia/data'
66
+ option :extension, :type => String
67
+
68
+ load_format_handler
69
+
70
+ options[:searchpath].flatten.each do |path|
71
+ Jerakia.log.debug("Attempting to load data from #{path}")
72
+ return unless response.want?
73
+ data = read_from_file(path)
74
+ Jerakia.log.debug("Datasource provided #{data} looking for key #{lookup.request.key}")
75
+ unless data[lookup.request.key].nil?
76
+ Jerakia.log.debug("Found data #{data[lookup.request.key]}")
77
+ response.submit data[lookup.request.key]
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,23 @@
1
+ class Jerakia
2
+ class Policy
3
+ class Registry
4
+
5
+ @instances = {}
6
+
7
+ class << self
8
+ attr_reader :instances
9
+
10
+ def register(name, instance)
11
+ @instances[name] = instance unless @instances[name]
12
+ end
13
+ end
14
+
15
+ attr_reader :instance
16
+
17
+ def initialize(name, instance)
18
+ @instance = instance
19
+ self.class.register(name, self)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -45,6 +45,7 @@ class Jerakia
45
45
  end
46
46
 
47
47
  before do
48
+ authenticate!
48
49
  content_type 'application/json'
49
50
  end
50
51
 
@@ -3,5 +3,5 @@ class Jerakia
3
3
  #
4
4
  # This should be updated when a new gem is released and it is read from the gemspec file
5
5
  #
6
- VERSION = '1.2.0'.freeze
6
+ VERSION = '1.2.1'.freeze
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jerakia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Craig Dunn
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-17 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -132,6 +132,7 @@ files:
132
132
  - lib/jerakia/datasource/file.rb
133
133
  - lib/jerakia/datasource/file/json.rb
134
134
  - lib/jerakia/datasource/file/yaml.rb
135
+ - lib/jerakia/datasource/file_new.rb
135
136
  - lib/jerakia/datasource/http.rb
136
137
  - lib/jerakia/dsl/lookup.rb
137
138
  - lib/jerakia/dsl/policy.rb
@@ -144,6 +145,7 @@ files:
144
145
  - lib/jerakia/lookup/plugin_config.rb
145
146
  - lib/jerakia/lookup/pluginfactory.rb
146
147
  - lib/jerakia/policy.rb
148
+ - lib/jerakia/policy/registry.rb
147
149
  - lib/jerakia/request.rb
148
150
  - lib/jerakia/response.rb
149
151
  - lib/jerakia/response/filter.rb