mirror of
https://github.com/elastic/logstash.git
synced 2025-04-24 14:47:19 -04:00
This PR changes the behavior of copying license files from .tgz Originally, only two files, MaxMind LICENSE.txt and COPYRIGHT.txt, are required Now more files, README.txt and Elastic ToC, are potentially required Instead of targeting the files, this change copies all content in .tgz
This commit is contained in:
parent
fab5dd8da8
commit
3c27f8ab40
3 changed files with 22 additions and 9 deletions
|
@ -78,7 +78,8 @@ module LogStash module Filters module Geoip class DownloadManager
|
|||
end
|
||||
end
|
||||
|
||||
# extract COPYRIGHT.txt, LICENSE.txt and GeoLite2-{ASN,City}.mmdb from .tgz to temp directory
|
||||
# extract all files and folders from .tgz to vendor directory
|
||||
# existing files folders will be replaced
|
||||
def unzip(zip_path)
|
||||
new_database_path = zip_path[0...-(GZ_EXT.length)] + DB_EXT
|
||||
temp_dir = Stud::Temporary.pathname
|
||||
|
@ -86,9 +87,15 @@ module LogStash module Filters module Geoip class DownloadManager
|
|||
LogStash::Util::Tar.extract(zip_path, temp_dir)
|
||||
logger.debug("extract database to ", :path => temp_dir)
|
||||
|
||||
::Dir.each_child(temp_dir) do |file|
|
||||
path = ::File.join(temp_dir, file)
|
||||
|
||||
FileUtils.cp(::File.join(temp_dir, database_name_ext), new_database_path)
|
||||
FileUtils.cp_r(::Dir.glob(::File.join(temp_dir, "{COPYRIGHT,LICENSE}.txt")), @vendor_path)
|
||||
if !::File.directory?(path) && database_name_ext.eql?(file)
|
||||
FileUtils.cp(path, new_database_path)
|
||||
else
|
||||
FileUtils.cp_r(path, @vendor_path)
|
||||
end
|
||||
end
|
||||
|
||||
new_database_path
|
||||
end
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
# you may not use this file except in compliance with the Elastic License.
|
||||
|
||||
require_relative 'test_helper'
|
||||
require 'fileutils'
|
||||
require "filters/geoip/download_manager"
|
||||
|
||||
describe LogStash::Filters::Geoip do
|
||||
|
@ -105,13 +106,17 @@ describe LogStash::Filters::Geoip do
|
|||
let(:copyright_path) { get_file_path('COPYRIGHT.txt') }
|
||||
let(:license_path) { get_file_path('LICENSE.txt') }
|
||||
let(:readme_path) { get_file_path('README.txt') }
|
||||
let(:folder_path) { get_file_path('inner') }
|
||||
let(:folder_more_path) { ::File.join(get_file_path('inner'), 'more.txt') }
|
||||
let(:folder_less_path) { ::File.join(get_file_path('inner'), 'less.txt') }
|
||||
|
||||
before do
|
||||
file_path = ::File.expand_path("./fixtures/sample", ::File.dirname(__FILE__))
|
||||
after do
|
||||
file_path = ::File.expand_path("./fixtures/sample.mmdb", ::File.dirname(__FILE__))
|
||||
delete_file(file_path, copyright_path, license_path, readme_path)
|
||||
FileUtils.rm_r folder_path
|
||||
end
|
||||
|
||||
it "should extract database and license related files" do
|
||||
it "should extract all files in tarball" do
|
||||
path = ::File.expand_path("./fixtures/sample.tgz", ::File.dirname(__FILE__))
|
||||
unzip_db_path = download_manager.send(:unzip, path)
|
||||
|
||||
|
@ -119,9 +124,10 @@ describe LogStash::Filters::Geoip do
|
|||
expect(::File.exist?(unzip_db_path)).to be_truthy
|
||||
expect(::File.exist?(copyright_path)).to be_truthy
|
||||
expect(::File.exist?(license_path)).to be_truthy
|
||||
expect(::File.exist?(readme_path)).to be_falsey
|
||||
|
||||
delete_file(unzip_db_path, copyright_path, license_path)
|
||||
expect(::File.exist?(readme_path)).to be_truthy
|
||||
expect(::File.directory?(folder_path)).to be_truthy
|
||||
expect(::File.exist?(folder_more_path)).to be_truthy
|
||||
expect(::File.exist?(folder_less_path)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue