Last active
March 18, 2021 10:51
-
-
Save jsvd/a16a4442f37911e692e003ce6e3cb0a7 to your computer and use it in GitHub Desktop.
logstash plugin version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# use ./lpv.rb logstash_version plugin_name | |
# | |
# example: | |
# % ./lpv.rb 5.2.0 logstash-output-elasticsearch | |
# logstash-output-elasticsearch 6.2.4 https://github.com/logstash-plugins/logstash-output-elasticsearch/tree/v6.2.4 | |
require 'net/http' | |
logstash_version = ARGV[0] | |
plugin_name = ARGV[1] | |
if ARGV.size != 2 | |
puts "Usage: lpv.rb logstash-version plugin-name" | |
exit(1) | |
end | |
uri = if logstash_version.match(/^5\.[5678]/) | |
URI("https://raw.githubusercontent.com/elastic/logstash/v#{logstash_version}/Gemfile.jruby-1.9.lock.release") | |
elsif logstash_version.match(/^[25]/) | |
URI("https://raw.githubusercontent.com/elastic/logstash/v#{logstash_version}/Gemfile.jruby-1.9.lock") | |
elsif logstash_version.match(/^6\.[0-6]/) | |
URI("https://raw.githubusercontent.com/elastic/logstash/v#{logstash_version}/Gemfile.jruby-2.3.lock.release") | |
elsif logstash_version.match(/^[678]/) | |
URI("https://raw.githubusercontent.com/elastic/logstash/v#{logstash_version}/Gemfile.jruby-2.5.lock.release") | |
else | |
puts "Version #{logstash_version} of logstash is not supported" | |
exit(1) | |
end | |
response = Net::HTTP.start(uri.host, uri.port, :use_ssl => true) do |http| | |
request = Net::HTTP::Get.new(uri) | |
http.request(request) | |
end | |
lock_file = response.body | |
if match = lock_file.match(/#{plugin_name}\s+\((?<plugin_version>\d+\.\d+\.\d+).*?\)/) | |
plugin_version = match["plugin_version"] | |
puts "#{plugin_name} #{plugin_version} https://github.com/logstash-plugins/#{plugin_name}/tree/v#{plugin_version}" | |
else | |
puts "Couldn't find plugin version for #{plugin_name}" | |
exit(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment