logstash/lib/pluginmanager/pack_fetch_strategy/uri.rb
Pier-Hugues Pellerin 12cfa69215 Feature: A way to install/remove a plugin pack
A pack in this context is a *bundle* of plugins that can be distributed outside of rubygems; it is similar to what ES and kibana are doing, and
the user interface is modeled after them. See https://www.elastic.co/downloads/x-pack

**Do not mix it with the `bin/logstash-plugin pack/unpack` command.**

- it contains one or more plugins that need to be installed
- it is self-contains with the gems and the needed jars
- it is distributed as a zip file
- the file structure needs to follow some rules.

- As a reserved name name on elastic.co download http server
    - `bin/plugin install logstash-mypack` will check on the download server if a pack for the current specific logstash version exist and it will be downloaded, if it doesn't exist we fallback on rubygems.
    - The file on the server will follow this convention `logstash-mypack-{LOGSTASH_VERSION}.zip`

- As a fully qualified url
    - `bin/plugin install http://test.abc/logstash-mypack.zip`, if it exists it will be downloaded and installed if it does not we raise an error.

- As a local file
    - `bin/plugin install file:///tmp/logstash-mypack.zip`, if it exists it will be installed

Fixes #6168
2016-11-17 14:00:02 -05:00

44 lines
1.2 KiB
Ruby

# encoding: utf-8
require "pluginmanager/utils/http_client"
require "pluginmanager/pack_installer/local"
require "pluginmanager/pack_installer/remote"
require "pluginmanager/ui"
require "net/http"
require "uri"
module LogStash module PluginManager module PackFetchStrategy
class Uri
class << self
def get_installer_for(plugin_name)
begin
uri = URI.parse(plugin_name)
if local?(uri)
PluginManager.ui.debug("Local file: #{uri.path}")
return LogStash::PluginManager::PackInstaller::Local.new(uri.path)
elsif http?(uri)
PluginManager.ui.debug("Remote file: #{uri}")
return LogStash::PluginManager::PackInstaller::Remote.new(uri)
else
return nil
end
rescue URI::InvalidURIError,
URI::InvalidComponentError,
URI::BadURIError => e
PluginManager.ui.debug("Invalid URI for pack, uri: #{uri}")
return nil
end
end
private
def http?(uri)
!uri.scheme.nil? && uri.scheme.match(/^http/)
end
def local?(uri)
!uri.scheme.nil? && uri.scheme == "file"
end
end
end
end end end