{"action":"created","comment":{"url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/comments/46945402","id":46945402,"diff_hunk":"@@ -0,0 +1,157 @@\n+$LOAD_PATH.unshift(File.join(File.dirname(__FILE__),\"..\",\"..\",\"..\"))\n+\n+Puppet::Type.type(:elasticsearch_plugin).provide(:plugin) do\n+  desc \"A provider for the resource type `elasticsearch_plugin`,\n+        which handles plugin installation\"\n+\n+  commands :plugin => '/usr/share/elasticsearch/bin/plugin'\n+  commands :es => '/usr/share/elasticsearch/bin/elasticsearch'\n+\n+  def exists?\n+    es_version\n+    if !File.exists?(pluginfile)\n+      debug \"Plugin file #{pluginfile} does not exist\"\n+      return false\n+    elsif File.exists?(pluginfile) && readpluginfile != pluginfile_content\n+      debug \"Got #{readpluginfile} Expected #{pluginfile_content}\"\n+      self.destroy\n+      false\n+    else\n+      debug \"Plugin exists\"\n+      return true\n+    end\n+  end\n+\n+  def pluginfile_content\n+    if is2x?\n+      items = @resource[:name].split(\"/\")\n+      if items.count == 1 # Official plugin\n+        version = plugin_version(@resource[:name])\n+        return \"#{@resource[:name]}/#{version}\"\n+      else\n+        return @resource[:name]\n+      end\n+    else\n+      return @resource[:name]\n+    end\n+  end\n+\n+  def pluginfile\n+    File.join(@resource[:plugin_dir], plugin_name(@resource[:name]), '.name')\n+  end\n+\n+  def writepluginfile\n+    File.open(pluginfile, 'w') do |file|\n+      file.write pluginfile_content\n+    end\n+  end\n+\n+  def readpluginfile\n+    f = File.open(pluginfile)\n+    f.readline\n+  end\n+\n+  def install1x\n+    if !@resource[:url].nil?\n+      commands = [ plugin_name(@resource[:name]), '--url', @resource[:url] ]\n+    elsif !@resource[:source].nil?\n+      commands = [ plugin_name(@resource[:name]), '--url', \"file://#{@resource[:source]}\" ]\n+    else\n+      commands = [ @resource[:name] ]\n+    end\n+    commands\n+  end\n+\n+  def install2x\n+    if !@resource[:url].nil?\n+      commands = [ @resource[:url] ]\n+    elsif !@resource[:source].nil?\n+      commands = [ \"file://#{@resource[:source]}\" ]\n+    else\n+      commands = [ @resource[:name] ]\n+    end\n+    commands\n+  end\n+\n+  def create\n+    es_version\n+    commands = []\n+    commands << @resource[:proxy_args] if @resource[:proxy_args]\n+    commands << 'install'\n+    commands << install1x if is1x?\n+    commands << install2x if is2x?\n+    \n+    plugin(commands)\n+    writepluginfile\n+  end\n+\n+  def destroy\n+    plugin(['remove', @resource[:name]])\n+  end\n+\n+  def es_version\n+    return @es_version if @es_version\n+    begin\n+      version = es('-v') # ES 1.x\n+    rescue\n+      version = es('--version') # ES 2.x\n+    rescue\n+      raise \"Unknown ES version. Got #{version.inspect}\"\n+    ensure\n+      @es_version = version.scan(/\\d+\\.\\d+\\.\\d+(?:\\-\\S+)?/).first\n+      debug \"Found ES version #{@es_version}\"\n+    end\n+  end\n+\n+  def is1x?\n+    Puppet::Util::Package.versioncmp(@es_version, '2.0.0') < 0\n+  end\n+\n+  def is2x?\n+    (Puppet::Util::Package.versioncmp(@es_version, '2.0.0') >= 0) && (Puppet::Util::Package.versioncmp(@es_version, '3.0.0') < 0)\n+  end\n+\n+  def plugin_version(plugin_name)\n+    items = plugin_name.split(\"/\")\n+    if is1x?\n+      if items.count == 3 # 'mobz/elasticsearch-head/1.2.3'\n+        return items[2].scan(/\\d+\\.\\d+\\.\\d+(?:\\-\\S+)?/).first","path":"lib/puppet/provider/elasticsearch_plugin/plugin.rb","position":118,"original_position":118,"commit_id":"0093b1e2f9c3eb5ecaeb8404a63586534c71f77b","original_commit_id":"0093b1e2f9c3eb5ecaeb8404a63586534c71f77b","user":{"login":"igalic","id":497249,"avatar_url":"https://avatars.githubusercontent.com/u/497249?v=3","gravatar_id":"","url":"https://api.github.com/users/igalic","html_url":"https://github.com/igalic","followers_url":"https://api.github.com/users/igalic/followers","following_url":"https://api.github.com/users/igalic/following{/other_user}","gists_url":"https://api.github.com/users/igalic/gists{/gist_id}","starred_url":"https://api.github.com/users/igalic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/igalic/subscriptions","organizations_url":"https://api.github.com/users/igalic/orgs","repos_url":"https://api.github.com/users/igalic/repos","events_url":"https://api.github.com/users/igalic/events{/privacy}","received_events_url":"https://api.github.com/users/igalic/received_events","type":"User","site_admin":false},"body":"suddenly we're dealing with [names](https://en.wikipedia.org/wiki/Connascence_%28computer_programming%29), not positions (see Jim Weireich's [Grand Unified Theory of Software](https://vimeo.com/10837903) :)","created_at":"2015-12-08T12:08:46Z","updated_at":"2015-12-08T12:08:46Z","html_url":"https://github.com/elastic/puppet-elasticsearch/pull/507#discussion_r46945402","pull_request_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507","_links":{"self":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/comments/46945402"},"html":{"href":"https://github.com/elastic/puppet-elasticsearch/pull/507#discussion_r46945402"},"pull_request":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507"}}},"pull_request":{"url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507","id":52141493,"html_url":"https://github.com/elastic/puppet-elasticsearch/pull/507","diff_url":"https://github.com/elastic/puppet-elasticsearch/pull/507.diff","patch_url":"https://github.com/elastic/puppet-elasticsearch/pull/507.patch","issue_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues/507","number":507,"state":"open","locked":false,"title":"Plugin Type & Provider","user":{"login":"electrical","id":271677,"avatar_url":"https://avatars.githubusercontent.com/u/271677?v=3","gravatar_id":"","url":"https://api.github.com/users/electrical","html_url":"https://github.com/electrical","followers_url":"https://api.github.com/users/electrical/followers","following_url":"https://api.github.com/users/electrical/following{/other_user}","gists_url":"https://api.github.com/users/electrical/gists{/gist_id}","starred_url":"https://api.github.com/users/electrical/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrical/subscriptions","organizations_url":"https://api.github.com/users/electrical/orgs","repos_url":"https://api.github.com/users/electrical/repos","events_url":"https://api.github.com/users/electrical/events{/privacy}","received_events_url":"https://api.github.com/users/electrical/received_events","type":"User","site_admin":false},"body":"Adding a custom Type and Provider for plugin installations","created_at":"2015-11-30T15:56:34Z","updated_at":"2015-12-08T12:08:46Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d76517e8780373086f837868e35f97216f6996f1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507/commits","review_comments_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507/comments","review_comment_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues/507/comments","statuses_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/statuses/0093b1e2f9c3eb5ecaeb8404a63586534c71f77b","head":{"label":"electrical:plugin_tp","ref":"plugin_tp","sha":"0093b1e2f9c3eb5ecaeb8404a63586534c71f77b","user":{"login":"electrical","id":271677,"avatar_url":"https://avatars.githubusercontent.com/u/271677?v=3","gravatar_id":"","url":"https://api.github.com/users/electrical","html_url":"https://github.com/electrical","followers_url":"https://api.github.com/users/electrical/followers","following_url":"https://api.github.com/users/electrical/following{/other_user}","gists_url":"https://api.github.com/users/electrical/gists{/gist_id}","starred_url":"https://api.github.com/users/electrical/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrical/subscriptions","organizations_url":"https://api.github.com/users/electrical/orgs","repos_url":"https://api.github.com/users/electrical/repos","events_url":"https://api.github.com/users/electrical/events{/privacy}","received_events_url":"https://api.github.com/users/electrical/received_events","type":"User","site_admin":false},"repo":{"id":18370953,"name":"puppet-elasticsearch","full_name":"electrical/puppet-elasticsearch","owner":{"login":"electrical","id":271677,"avatar_url":"https://avatars.githubusercontent.com/u/271677?v=3","gravatar_id":"","url":"https://api.github.com/users/electrical","html_url":"https://github.com/electrical","followers_url":"https://api.github.com/users/electrical/followers","following_url":"https://api.github.com/users/electrical/following{/other_user}","gists_url":"https://api.github.com/users/electrical/gists{/gist_id}","starred_url":"https://api.github.com/users/electrical/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/electrical/subscriptions","organizations_url":"https://api.github.com/users/electrical/orgs","repos_url":"https://api.github.com/users/electrical/repos","events_url":"https://api.github.com/users/electrical/events{/privacy}","received_events_url":"https://api.github.com/users/electrical/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/electrical/puppet-elasticsearch","description":"ElasticSearch Puppet module","fork":true,"url":"https://api.github.com/repos/electrical/puppet-elasticsearch","forks_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/forks","keys_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/teams","hooks_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/events","assignees_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/tags","blobs_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/languages","stargazers_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/subscription","commits_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/merges","archive_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/downloads","issues_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/electrical/puppet-elasticsearch/releases{/id}","created_at":"2014-04-02T15:18:58Z","updated_at":"2015-04-16T14:47:10Z","pushed_at":"2015-12-08T09:33:24Z","git_url":"git://github.com/electrical/puppet-elasticsearch.git","ssh_url":"git@github.com:electrical/puppet-elasticsearch.git","clone_url":"https://github.com/electrical/puppet-elasticsearch.git","svn_url":"https://github.com/electrical/puppet-elasticsearch","homepage":null,"size":767,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"elastic:master","ref":"master","sha":"b930ab83820a3776392ac5ea92241ce06fe7b73c","user":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"repo":{"id":6968490,"name":"puppet-elasticsearch","full_name":"elastic/puppet-elasticsearch","owner":{"login":"elastic","id":6764390,"avatar_url":"https://avatars.githubusercontent.com/u/6764390?v=3","gravatar_id":"","url":"https://api.github.com/users/elastic","html_url":"https://github.com/elastic","followers_url":"https://api.github.com/users/elastic/followers","following_url":"https://api.github.com/users/elastic/following{/other_user}","gists_url":"https://api.github.com/users/elastic/gists{/gist_id}","starred_url":"https://api.github.com/users/elastic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/elastic/subscriptions","organizations_url":"https://api.github.com/users/elastic/orgs","repos_url":"https://api.github.com/users/elastic/repos","events_url":"https://api.github.com/users/elastic/events{/privacy}","received_events_url":"https://api.github.com/users/elastic/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/elastic/puppet-elasticsearch","description":"Elasticsearch Puppet module","fork":false,"url":"https://api.github.com/repos/elastic/puppet-elasticsearch","forks_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/forks","keys_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/teams","hooks_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/hooks","issue_events_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues/events{/number}","events_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/events","assignees_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/assignees{/user}","branches_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/branches{/branch}","tags_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/tags","blobs_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/git/refs{/sha}","trees_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/statuses/{sha}","languages_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/languages","stargazers_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/stargazers","contributors_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/contributors","subscribers_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/subscribers","subscription_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/subscription","commits_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/commits{/sha}","git_commits_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/git/commits{/sha}","comments_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/comments{/number}","issue_comment_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues/comments{/number}","contents_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/contents/{+path}","compare_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/merges","archive_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/downloads","issues_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues{/number}","pulls_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls{/number}","milestones_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/milestones{/number}","notifications_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/labels{/name}","releases_url":"https://api.github.com/repos/elastic/puppet-elasticsearch/releases{/id}","created_at":"2012-12-02T15:09:34Z","updated_at":"2015-11-19T00:31:02Z","pushed_at":"2015-12-08T09:33:24Z","git_url":"git://github.com/elastic/puppet-elasticsearch.git","ssh_url":"git@github.com:elastic/puppet-elasticsearch.git","clone_url":"https://github.com/elastic/puppet-elasticsearch.git","svn_url":"https://github.com/elastic/puppet-elasticsearch","homepage":"","size":897,"stargazers_count":224,"watchers_count":224,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":257,"mirror_url":null,"open_issues_count":44,"forks":257,"open_issues":44,"watchers":224,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507"},"html":{"href":"https://github.com/elastic/puppet-elasticsearch/pull/507"},"issue":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues/507"},"comments":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/issues/507/comments"},"review_comments":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507/comments"},"review_comment":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/pulls/507/commits"},"statuses":{"href":"https://api.github.com/repos/elastic/puppet-elasticsearch/statuses/0093b1e2f9c3eb5ecaeb8404a63586534c71f77b"}}}}