2

我有一本带有以下红宝石代码的厨师食谱:

class Chef::Recipe::Helpers
  def self.is_config?(filename)
    ['.lua', '.conf'].include?(File.extname(filename))
  end

  def self.out_filename(filename)
    File.extname(filename) == '.conf' ? 'nginx.conf' : filename
  end

  def self.unzip(data, dest_dir)
    ::Zip::File.open_buffer(data) do |fzip|
      fzip.each do |entry|
        next unless is_config?(entry.name)
        content = fzip.read(entry)
        filename = out_filename(entry.name)
        path = File.join(dest_dir, filename)
        File.write(path, content)
      end
    end
  end

  def self.fetch_from_url(url, dest_dir)
    response = HTTPClient.get(url, follows_redirect: true)
    if response.status == 200
      unzip(response.body, dest_dir)
    else
      raise 'Could not fetch files from 3scale'
    end
  end
end

我在工件存储库中有一个 zip 文件,该文件已压缩并上传,我提供了该端点以供此代码接收:

ruby_block 'fetch configuration files from a URL' do
  block do
    Helpers.fetch_from_url(node['3scale']['config-url'], version_dir)
  end
  action :run
end

这使用了帖子中提到的辅助函数,但是当我运行它时,出现以下错误:

 * ruby_block[fetch configuration files from a URL] action run
================================================================================
Error executing action `run` on resource 'ruby_block[fetch configuration files from a URL]'
================================================================================


IOError
-------
closed stream


Cookbook Trace:
---------------
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:23:in `block (2 levels) in unzip'
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:21:in `block in unzip'
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:20:in `unzip'
/var/chef/cache/cookbooks/dj-chef-3scale/libraries/default_helper.rb:34:in `fetch_from_url'
/var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb:79:in `block (2 levels) in from_file'


Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb

 77:   ruby_block 'fetch configuration files from a URL' do
 78:     block do
 79:       Helpers.fetch_from_url(node['3scale']['config-url'], version_dir)
 80:     end
 81:     action :run
 82:   end
 83: elsif mode == 'local'



Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb:77:in `from_file'

ruby_block("fetch configuration files from a URL") do
  action [:run]
  retries 0
  retry_delay 2
  block_name "fetch configuration files from a URL"
  cookbook_name "dj-chef-3scale"
  recipe_name "default"
  block #<Proc:0x0000000420e230@/var/chef/cache/cookbooks/dj-chef-3scale/recipes/default.rb:78>
end

不知道为什么我会在这里得到“封闭流”?

4

0 回答 0