chef_stash 0.1.3 → 0.1.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d32774effc4b65c56c3da123dafaf3c8439b4e86
4
- data.tar.gz: 88065b3e7841bbceafa323b7a3e76959f1c41a75
3
+ metadata.gz: e6fb5aa6cb7894aee3d450c73ad348a642f00273
4
+ data.tar.gz: fccf76c0b38af460bd7b74aff3f4c236db494ff0
5
5
  SHA512:
6
- metadata.gz: 34910cd218c521f86d50a989dcd21b3ecf6544858b63132e67c3fae355d8a08493d85f971e25a584a4d328cce8aa896119eb4ac421e648f1d1ab90f3f0ac06e7
7
- data.tar.gz: 25ba1cb087fac0b13f3f87222f3287a8d0f8b56bdcf2c8df08c1a935c46015cf148a3dd2b0f1f7b66886e82b39ce3dd1da8c64419511c8052be56c7b42b3d118
6
+ metadata.gz: 0108cecb25ba1885bf377d2c0bcecc45275eab1fe887d01fe4e2821fc32d168acb50bec898d3f2953a7481c687d95e48b6392d36dd1fcd349efba45dd794a5ab
7
+ data.tar.gz: 58ad43bf3269e2ad37df6178caaeed28b03fcf4c1a36dbf00d7e4220e1cadcb076967d5d61cf6cbddbd08d3fefe1d9293d71d9ff14819854d7368285f00fc40d
data/.gitignore CHANGED
@@ -191,3 +191,5 @@ vendor/bundle
191
191
  vendor/cache
192
192
  Gemfile.lock
193
193
  repl.rb
194
+ bin/rash.rb
195
+ bin/rash.rb
@@ -36,7 +36,6 @@ module ChefStash
36
36
  #
37
37
  def initialize(store = file_store)
38
38
  @store = store
39
- ensure_store_directory
40
39
  end
41
40
 
42
41
  # Retrieves a value from the cache, if available and not expired, or yields
@@ -141,10 +140,11 @@ module ChefStash
141
140
 
142
141
  def write_cache_file(key, content)
143
142
  mode = OS.windows? ? 'wb' : 'w+'
144
- f = File.open(cache_file(key), mode)
145
- f.flock(File::LOCK_EX)
146
- f.write(content)
147
- f.close
143
+ file = File.open(cache_file(key), mode)
144
+ ensure_enclosing_dir(File.dirname file)
145
+ file.flock(File::LOCK_EX)
146
+ file.write(content)
147
+ file.close
148
148
  content
149
149
  end
150
150
 
@@ -162,8 +162,8 @@ module ChefStash
162
162
  File.mtime(cache_file(key))
163
163
  end
164
164
 
165
- def ensure_store_directory
166
- Dir.mkdir(store) unless File.directory?(store)
165
+ def ensure_enclosing_dir(dir)
166
+ FileUtils.mkdir_p(file_store) unless File.directory?(dir)
167
167
  end
168
168
  end
169
169
  end
@@ -98,6 +98,24 @@ module ChefStash
98
98
 
99
99
  private # P R O P R I E T À P R I V A T A Vietato L'accesso
100
100
 
101
+ def fetch_raw(url, path)
102
+ regex = /#{path}\/\w+.(\w+.(ini|zip)|sha256.txt)$/i
103
+ threads = ChefStash::OS.windows? ? 4 : 20
104
+ options = { threads: threads, depth_limit: 3, discard_page_bodies: true }
105
+ results = []
106
+
107
+ Anemone.crawl(url, options) do |anemone|
108
+ anemone.on_pages_like(regex) do |page|
109
+ name = File.basename(url)
110
+ key = File.basename(name, '.*').downcase.to_sym
111
+ type = File.extname(name)[1..-1].downcase.to_sym
112
+
113
+ results << { key => { type => { page: page } } }
114
+ results.reduce({}, :recursive_merge)
115
+ end
116
+ end
117
+ end
118
+
101
119
  # Loads a Chef stash hash of cache stash of hash data into the hash stash
102
120
  # key/value stach hash cache object Chef store, or create a new one.
103
121
  #
@@ -105,36 +123,36 @@ module ChefStash
105
123
  # rash[:av]
106
124
  # => {
107
125
  # :ini => {
108
- # :code => "200 OK",
109
- # :depth => 3,
110
- # :size => "0.0 MB",
111
- # :key => :av,
112
- # :md5 => "336d9da322febc949eb22ae3f47d293b",
113
- # :modified => "Mon, 16 Feb 2015 07:13:23 GMT",
114
- # :name => "AV.ini",
115
- # :referer => "http://winini.mudbox.dev/packages_3.0/AV/",
116
- # :response_time => "1 seconds 0 milliseconds",
117
- # :sha256 => "905425e1a33b0662297181c3031066d630f8241880c7001",
118
- # :content_type => "text/inifile",
119
- # :url => "http://winini.mudbox.dev/packages_3.0/AV/AV.ini",
120
- # :utime => "Mon, 20 Apr 2015 06:33:07 GMT",
121
- # :visited => nil
126
+ # :code => "200 OK",
127
+ # :content => "text/inifile",
128
+ # :created => "Tue, 21 Apr 2015 00:24:44 GMT",
129
+ # :depth => 3,
130
+ # :key => :av,
131
+ # :md5 => "336d9da322febc949eb22ae3f47d293b",
132
+ # :modified => "Mon, 16 Feb 2015 07:13:23 GMT",
133
+ # :name => "AV.ini",
134
+ # :referer => "http://winini.mudbox.dev/packages_3.0/AV/",
135
+ # :response => "1 seconds",
136
+ # :sha256 => "905425e1a33b0662297181c3031066d7e6757cb3796c730f82",
137
+ # :size => "0.0 MB",
138
+ # :url => "http://winini.mudbox.dev/packages_3.0/AV/AV.ini",
139
+ # :visited => nil
122
140
  # },
123
141
  # :zip => {
124
- # :code => "200 OK",
125
- # :depth => 3,
126
- # :size => "32.6 MB",
127
- # :key => :av,
128
- # :md5 => "2488ceb74eb6cb5fae463c88b806ebff",
129
- # :modified => "Mon, 16 Feb 2015 07:13:29 GMT",
130
- # :name => "AV.zip",
131
- # :referer => "http://winini.mudbox.dev/packages_3.0/AV/",
132
- # :response_time => "1 seconds 0 milliseconds",
133
- # :sha256 => "f3f14ac64263fc7b091d150a1bc0867d38af57466574587",
134
- # :content_type => "application/zip",
135
- # :url => "http://winini.mudbox.dev/packages_3.0/AV/AV.zip",
136
- # :utime => "Mon, 20 Apr 2015 06:33:08 GMT",
137
- # :visited => nil
142
+ # :code => "200 OK",
143
+ # :content => "application/zip",
144
+ # :created => "Tue, 21 Apr 2015 00:24:45 GMT",
145
+ # :depth => 3,
146
+ # :key => :av,
147
+ # :md5 => "2488ceb74eb6cb5fae463c88b806ebff",
148
+ # :modified => "Mon, 16 Feb 2015 07:13:29 GMT",
149
+ # :name => "AV.ini",
150
+ # :referer => "http://winini.mudbox.dev/packages_3.0/AV/",
151
+ # :response => "1 seconds",
152
+ # :sha256 => "f3f14ac64263fc7b091d150a1bc0867d38a8604e88f56f5746",
153
+ # :size => "32.6 MB",
154
+ # :url => "http://winini.mudbox.dev/packages_3.0/AV/AV.zip",
155
+ # :visited => nil
138
156
  # }
139
157
  # }
140
158
  #
@@ -149,42 +167,80 @@ module ChefStash
149
167
  def fetch(url, path)
150
168
  results = []
151
169
  regex = /#{path}\/\w+.(\w+.(ini|zip)|sha256.txt)$/i
152
- options = { threads: 20, depth_limit: 3, discard_page_bodies: true }
170
+ threads = ChefStash::OS.windows? ? 4 : 20
171
+ options = { threads: threads, depth_limit: 3, discard_page_bodies: true }
153
172
 
154
- Anemone.crawl(url, options) do |anemone|
155
- anemone.on_pages_like(regex) do |page|
156
- url = page.url.to_s
157
- name = File.basename(url)
158
- key = File.basename(name, '.*').downcase.to_sym
159
- type = File.extname(name)[1..-1].downcase.to_sym
173
+ if ChefStash::OS.windows?
174
+ Anemone.crawl(url, options) do |anemone|
175
+ anemone.on_pages_like(regex) do |page|
176
+ url = page.url.to_s
177
+ name = File.basename(url)
178
+ key = File.basename(name, '.*').downcase.to_sym
179
+ type = File.extname(name)[1..-1].downcase.to_sym
180
+
181
+ header = page.headers
182
+ bytes = header['content-length'].first
183
+ modified = header['last-modified'].first
184
+ created = Time.now.utc.httpdate
185
+ content = type == :ini ? 'text/inifile' : header['content-type'].first
186
+ code = ChefStash::Response.code(page.code)
160
187
 
161
- header = page.headers
162
- bytes = header['content-length'].first || 0
163
- modified = header['last-modified'].first
164
- created = Time.now.utc.httpdate
165
- content = type == :ini ? 'text/inifile' : header['content-type'].first
166
- size = ChefStash::FileSize.new(bytes).to_size(:mb).to_s
167
-
168
- results << { key => { type => {
169
- code: ChefStash::Response.code(page.code),
170
- depth: page.depth,
171
- size: size,
172
- key: key,
173
- md5: Digest::MD5.hexdigest(page.body.to_s),
174
- modified: modified,
175
- name: name,
176
- referer: page.referer.to_s,
177
- response_time: page.response_time.time_humanize,
178
- sha256: OpenSSL::Digest::SHA256.new(page.body).to_s,
179
- content_type: content,
180
- url: url,
181
- created: created,
182
- visited: page.visited
183
- } } }
188
+ results << { key => { type => {
189
+ code: code,
190
+ content: content,
191
+ created: created,
192
+ depth: page.depth,
193
+ key: key,
194
+ md5: md5,
195
+ modified: modified,
196
+ name: name,
197
+ referer: page.referer.to_s,
198
+ url: url,
199
+ visited: page.visited
200
+ } } }
201
+ end
184
202
  end
185
- end
186
203
 
187
- results.reduce({}, :recursive_merge)
204
+ results.reduce({}, :recursive_merge)
205
+ else
206
+ Anemone.crawl(url, options) do |anemone|
207
+ anemone.on_pages_like(regex) do |page|
208
+ url = page.url.to_s
209
+ name = File.basename(url)
210
+ key = File.basename(name, '.*').downcase.to_sym
211
+ type = File.extname(name)[1..-1].downcase.to_sym
212
+
213
+ header = page.headers
214
+ bytes = header['content-length'].first
215
+ modified = header['last-modified'].first
216
+ created = Time.now.utc.httpdate
217
+ content = type == :ini ? 'text/inifile' : header['content-type'].first
218
+ code = ChefStash::Response.code(page.code)
219
+ md5 = Digest::MD5.hexdigest(page.body.to_s)
220
+ sha256 = OpenSSL::Digest::SHA256.new(page.body).to_s
221
+ size = ChefStash::FileSize.new(bytes).to_size(:mb).to_s
222
+
223
+ results << { key => { type => {
224
+ code: code,
225
+ content: content,
226
+ created: created,
227
+ depth: page.depth,
228
+ key: key,
229
+ md5: md5,
230
+ modified: modified,
231
+ name: name,
232
+ referer: page.referer.to_s,
233
+ response: page.response_time.time_humanize,
234
+ sha256: sha256,
235
+ size: size,
236
+ url: url,
237
+ visited: page.visited
238
+ } } }
239
+ end
240
+ end
241
+
242
+ results.reduce({}, :recursive_merge)
243
+ end
188
244
  end
189
245
  end
190
246
  end
@@ -26,7 +26,7 @@ module ChefStash
26
26
  module Version
27
27
  MAJOR = 0
28
28
  MINOR = 1
29
- PATCH = 3
29
+ PATCH = 4
30
30
 
31
31
  # Returns a version string by joining MAJOR, MINOR, and PATCH with '.'
32
32
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef_stash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stefano Harding
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-20 00:00:00.000000000 Z
11
+ date: 2015-04-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anemone
@@ -179,7 +179,6 @@ files:
179
179
  - LICENSE
180
180
  - README.md
181
181
  - Rakefile
182
- - bin/rash.rb
183
182
  - chef_stash.gemspec
184
183
  - lib/chef_stash.rb
185
184
  - lib/chef_stash/core_ext/hash.rb
@@ -191,7 +190,6 @@ files:
191
190
  - lib/chef_stash/time_cache.rb
192
191
  - lib/chef_stash/utils.rb
193
192
  - lib/chef_stash/version.rb
194
- - repl.rb
195
193
  homepage: https://github.com/riddopic/chef_stash
196
194
  licenses:
197
195
  - Apache 2.0
data/bin/rash.rb DELETED
@@ -1,79 +0,0 @@
1
- #!/usr/bin/env ruby
2
- #
3
- # encoding: UTF-8
4
- #
5
- # Author: Stefano Harding <riddopic@gmail.com>
6
- # License: Apache License, Version 2.0
7
- # Copyright: (C) 2014-2015 Stefano Harding
8
- #
9
- # Licensed under the Apache License, Version 2.0 (the "License");
10
- # you may not use this file except in compliance with the License.
11
- # You may obtain a copy of the License at
12
- #
13
- # http://www.apache.org/licenses/LICENSE-2.0
14
- #
15
- # Unless required by applicable law or agreed to in writing, software
16
- # distributed under the License is distributed on an "AS IS" BASIS,
17
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
- # See the License for the specific language governing permissions and
19
- # limitations under the License.
20
- #
21
-
22
- lib = File.expand_path('../lib', __FILE__)
23
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
24
-
25
- require 'chef_stash'
26
- require 'ap'
27
-
28
- # Initializes a new repository hash or load an existing one.
29
- #
30
- # @param [String, Symbol] key
31
- # name of the key
32
- #
33
- # @return [Hoodie::ChefStash]
34
- def rash(url = 'http://winini.mudbox.dev', path = 'packages_3.0')
35
- require 'chef_stash' unless defined?(ChefStash)
36
- @rash ||= ChefStash::Rash.new(url, path)
37
- end
38
-
39
- url = 'http://winini.mudbox.dev/'
40
- path = 'packages_3.0'
41
- options = { threads: 20, depth_limit: 3, discard_page_bodies: true }
42
- results = []
43
- regex = /#{path}\/\w+.(\w+.(ini|zip)|sha256.txt)$/i
44
- seen = []
45
-
46
- Anemone.crawl(url, options) do |anemone|
47
- anemone.on_pages_like(regex) do |page|
48
- url = page.url.to_s
49
- name = File.basename(url)
50
- key = File.basename(name, '.*').downcase.to_sym
51
- type = File.extname(name)[1..-1].downcase.to_sym
52
-
53
- header = page.headers
54
- bytes = header['content-length'].first
55
- modified = header['last-modified'].first
56
- created = Time.now.utc.httpdate
57
- content = type == :ini ? 'text/inifile' : header['content-type'].first
58
- size = ChefStash::FileSize.new(bytes).to_size(:mb).to_s
59
-
60
- result = { key => { type => {
61
- code: ChefStash::Response.code(page.code),
62
- depth: page.depth,
63
- size: size,
64
- key: key,
65
- md5: Digest::MD5.hexdigest(page.body.to_s),
66
- modified: modified,
67
- name: name,
68
- referer: page.referer.to_s,
69
- response_time: page.response_time.time_humanize,
70
- sha256: OpenSSL::Digest::SHA256.new(page.body).to_s,
71
- content_type: content,
72
- url: url,
73
- created: created,
74
- visited: page.visited
75
- } } }
76
-
77
- ap result
78
- end
79
- end
data/repl.rb DELETED
@@ -1,147 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- lib = File.expand_path('../lib', __FILE__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
-
6
- require 'chef_stash'
7
- require 'inifile'
8
- require 'securerandom'
9
- require 'tempfile'
10
- require 'open-uri'
11
-
12
- # Return a cleanly join URI/URL segments into a cleanly normalized URL that
13
- # the libraries can use when constructing URIs. URI.join is pure evil.
14
- #
15
- # @param [Array<String>] paths the list of parts to join
16
- #
17
- # @return [String<URI>] nicely joined URI/URL, squeaky clean and normalized
18
- def uri_join(*paths)
19
- return nil if paths.length == 0
20
- leadingslash = paths[0][0] == '/' ? '/' : ''
21
- trailingslash = paths[-1][-1] == '/' ? '/' : ''
22
- paths.map! { |path| path.sub(/^\/+/, '').sub(/\/+$/, '') }
23
- leadingslash + paths.join('/') + trailingslash
24
- end
25
-
26
- # Return a hash from an INI file with normalized keys (down-case
27
- # and symbolized).
28
- #
29
- # @param [URI] file
30
- # the ini file
31
- #
32
- # @return [Hash]
33
- def inihash(file)
34
- require 'inifile' unless defined?(IniFile)
35
- Tempfile.open(SecureRandom.hex(3)) do |f|
36
- f.write(URI.parse(file).read)
37
- f.close
38
- regkeys_fix IniFile.load(f.path).to_h.compact.recursively_normalize_keys
39
- end
40
- end
41
-
42
- # Initializes a new repository hash or load an existing one.
43
- #
44
- # @param [String, Symbol] key
45
- # name of the key
46
- #
47
- # @return [Hoodie::ChefStash]
48
- def rash(url = 'http://winini.mudbox.dev', path = 'packages_3.0')
49
- require 'chef_stash' unless defined?(ChefStash)
50
- @rash ||= ChefStash::Rash.new(url, path)
51
- end
52
-
53
- # Shortcut to return cache path, if you pass in a file it will return the
54
- # file with the cache path.
55
- #
56
- # @example
57
- # file_cache_path
58
- # => "/var/chef/cache/"
59
- #
60
- # file_cache_path 'patch.tar.gz'
61
- # => "/var/chef/cache/patch.tar.gz"
62
- #
63
- # file_cache_path "#{node[:name]}-backup.tar.gz"
64
- # => "/var/chef/cache/c20d24209cc8-backup.tar.gz"
65
- #
66
- # @param [String] args
67
- # name of file to return path with file
68
- #
69
- # @return [String]
70
- def file_cache_path(*args)
71
- if args.nil?
72
- Chef::Config[:file_cache_path]
73
- else
74
- ::File.join(Chef::Config[:file_cache_path], args)
75
- end
76
- end
77
-
78
- # Initializes a new key store or loads an existing one. Data will persist
79
- # between Chef invocations.
80
- #
81
- # @param key [Symbol, String] representing the key
82
- #
83
- # @return [Hash, Array, String] value for key
84
- def stash
85
- require 'chef_stash' unless defined?(ChefStash)
86
- @stash ||= ChefStash.new
87
- end
88
-
89
- # Returns a new inihash hash replacing :regkeys hash section, and returning
90
- # an array of hashes, with key/value pairs.
91
- #
92
- # @example replace the regkeys hash and return a new regkeys array of hashes
93
- # inihash = {
94
- # regkeys: {
95
- # key1: 'a_path[my_key]',
96
- # key2: 'the_path[to_key]',
97
- # value1: 'cool_value',
98
- # value2: 'cooler_value'
99
- # }
100
- # }
101
- # regkeys_fix(inihash) Like a good neighbor regkey_fix has your back
102
- # => { regkeys = [
103
- # {
104
- # data: 'cool_value',
105
- # name: 'my_key',
106
- # path: 'HKLM/SOFTWARE/KaiserPermanente/a_path',
107
- # type: :string
108
- # },
109
- # {
110
- # data: 'cooler_value',
111
- # name: 'to_key',
112
- # path: 'HKLM/SOFTWARE/KaiserPermanente/the_path',
113
- # type: :string
114
- # }
115
- # ]
116
- # }
117
- #
118
- # @param [Hash]
119
- # replaces the value of :regkeys
120
- #
121
- # @return [Array<Hash{Symbol => String}>]
122
- # new inihash hash, replacing the regkeys hash with an array of hashes
123
- # with key/value pairs, all other key/value pairs are unchanged
124
- def regkeys_fix(hash)
125
- return hash unless hash.has_key?(:regkeys)
126
- regkeys = []
127
- hash[:regkeys].each do |key|
128
- char, i = key[0].to_s.scan(/\d+|\D+/)
129
- next unless char == 'key'
130
- path, name = key[1].scan(/([^\[]+)/)
131
- data = hash[:regkeys]["value#{i}".to_sym]
132
- nowtime = Time.now.strftime('%Y:%m:%d:%I:%M:%S')
133
- regkeys << {
134
- path: 'HKLM\SOFTWARE\KaiserPermanente\\' + path[0],
135
- type: :string,
136
- name: name[0].gsub(']', ''),
137
- data: (data == 'tstamp') ? nowtime : data
138
- }
139
- end
140
- hash[:regkeys] = regkeys
141
- hash
142
- end
143
-
144
- require 'pry'
145
- binding.pry
146
-
147
-