{"action":"created","comment":{"url":"https://api.github.com/repos/cerner/cerner_splunk/pulls/comments/25821885","id":25821885,"diff_hunk":"@@ -0,0 +1,141 @@\n+# coding: UTF-8\n+#\n+# Cookbook Name:: cerner_splunk\n+# File Name:: tarball.rb\n+#\n+# Methods for working with data from a tarball.\n+\n+require 'rubygems/package'\n+require 'zlib'\n+require 'fileutils'\n+\n+module CernerSplunk\n+  # Utility class to encapsulate operations on tar.gz files\n+  # Mad Props to http://stackoverflow.com/a/19139114/504685\n+  class TarBall\n+    def initialize(file_name, options = {})\n+      @data = []\n+      @clean_proc = Remover.new(@data)\n+      ObjectSpace.define_finalizer(self, @clean_proc)\n+      @file_name = @data[0] = file_name\n+      @reader = @data[1] =  Gem::Package::TarReader.new(Zlib::GzipReader.open @file_name)\n+      @prefix = options[:prefix]\n+      @options = options\n+    end\n+\n+    attr_reader :prefix\n+\n+    def get_file(name)\n+      data = []\n+      target_path = @prefix.nil? ? name : \"#{@prefix}/#{name}\"\n+      iterate file: proc { |path, entry| data << entry.read if path == target_path }, other: proc {}\n+      fail \"Multiple entries for #{target_path} found in #{@file_name}\" if data.size > 1\n+      data.first\n+    end\n+\n+    def extract(extract_dir)\n+      file_handler = proc do |path, entry|\n+        target = \"#{extract_dir}/#{path}\"\n+        make_dirs extract_dir, path\n+        File.open(target, 'wb') { |f| f.print entry.read }\n+        FileUtils.chmod entry.header.mode, target\n+        FileUtils.chown @options[:user], @options[:group], target\n+      end\n+\n+      dir_handler = proc do |path, entry|\n+        target = \"#{extract_dir}/#{path}\"\n+        make_dirs extract_dir, path, true\n+        FileUtils.chmod entry.header.mode, target\n+      end\n+\n+      symlink_handler = proc do |path, entry, other = {}|\n+        target = \"#{extract_dir}/#{path}\"\n+        make_dirs extract_dir, path\n+        File.unlink target if File.exist? target\n+        File.symlink other[:linkname], target\n+        FileUtils.chmod entry.header.mode, target\n+        FileUtils.chown @options[:user], @options[:group], target\n+      end\n+\n+      iterate file: file_handler, directory: dir_handler, symlink: symlink_handler\n+    end\n+\n+    def count(callbacks = {}, &other)\n+      callbacks = { other: other } if other && callbacks.empty?\n+      i = 0\n+      hsh = callbacks.each_with_object({}) { |(k, v), h| h[k] = proc { |*args| i += 1 if v.call(args) } }\n+      hsh[:other] = proc { i += 1 } if hsh.empty?\n+      hsh[:other] = proc {} unless hsh[:other]\n+      iterate hsh\n+      i\n+    end\n+\n+    def num_files\n+      count file: proc { true }\n+    end\n+\n+    def make_dirs(extract_dir, path, all = false)\n+      segments = path.split('/')\n+      segments = segments[0...-1] unless all\n+      segments.each_with_object(extract_dir.dup) do |segment, target|\n+        target << \"/#{segment}\"\n+        FileUtils.mkdir target unless File.directory? target\n+        FileUtils.chown @options[:user], @options[:group], target\n+      end\n+    end\n+\n+    def iterate(callbacks = {}) # rubocop:disable PerceivedComplexity, CyclomaticComplexity","path":"libraries/tarball.rb","position":87,"original_position":87,"commit_id":"a44768b5e83fabfe91ba8c0859698fab79b9f73b","original_commit_id":"a44768b5e83fabfe91ba8c0859698fab79b9f73b","user":{"login":"acharlieh","id":413832,"avatar_url":"https://avatars.githubusercontent.com/u/413832?v=3","gravatar_id":"","url":"https://api.github.com/users/acharlieh","html_url":"https://github.com/acharlieh","followers_url":"https://api.github.com/users/acharlieh/followers","following_url":"https://api.github.com/users/acharlieh/following{/other_user}","gists_url":"https://api.github.com/users/acharlieh/gists{/gist_id}","starred_url":"https://api.github.com/users/acharlieh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acharlieh/subscriptions","organizations_url":"https://api.github.com/users/acharlieh/orgs","repos_url":"https://api.github.com/users/acharlieh/repos","events_url":"https://api.github.com/users/acharlieh/events{/privacy}","received_events_url":"https://api.github.com/users/acharlieh/received_events","type":"User","site_admin":false},"body":"I have a first pass here: 63280a41fabbf0b60c05de65b7051885595b6504\r\n\r\nDoes this make more sense? Anything in particular that seems odd?","created_at":"2015-03-04T22:36:52Z","updated_at":"2015-03-04T22:36:52Z","html_url":"https://github.com/cerner/cerner_splunk/pull/48#discussion_r25821885","pull_request_url":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48","_links":{"self":{"href":"https://api.github.com/repos/cerner/cerner_splunk/pulls/comments/25821885"},"html":{"href":"https://github.com/cerner/cerner_splunk/pull/48#discussion_r25821885"},"pull_request":{"href":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48","id":30339118,"html_url":"https://github.com/cerner/cerner_splunk/pull/48","diff_url":"https://github.com/cerner/cerner_splunk/pull/48.diff","patch_url":"https://github.com/cerner/cerner_splunk/pull/48.patch","issue_url":"https://api.github.com/repos/cerner/cerner_splunk/issues/48","number":48,"state":"open","locked":false,"title":"Fixes #37 - Install apps via tarballs ","user":{"login":"acharlieh","id":413832,"avatar_url":"https://avatars.githubusercontent.com/u/413832?v=3","gravatar_id":"","url":"https://api.github.com/users/acharlieh","html_url":"https://github.com/acharlieh","followers_url":"https://api.github.com/users/acharlieh/followers","following_url":"https://api.github.com/users/acharlieh/following{/other_user}","gists_url":"https://api.github.com/users/acharlieh/gists{/gist_id}","starred_url":"https://api.github.com/users/acharlieh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acharlieh/subscriptions","organizations_url":"https://api.github.com/users/acharlieh/orgs","repos_url":"https://api.github.com/users/acharlieh/repos","events_url":"https://api.github.com/users/acharlieh/events{/privacy}","received_events_url":"https://api.github.com/users/acharlieh/received_events","type":"User","site_admin":false},"body":"Implementation of #37. This was quite the adventure. But this gives us the ability to install apps from .tar.gz files (and .spl, but .spl is just a renamed .tar.gz). We'll need a new enhancement / issue if we want to install apps from .zip files as well. (In the past few days I've seen a number zip files with all kinds of formats.)\r\n\r\nPlease review and be harsh! Question everything!","created_at":"2015-03-03T01:34:34Z","updated_at":"2015-03-04T22:36:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"462e1ad63d14f3e2e14d65905424f333e5df5650","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48/commits","review_comments_url":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48/comments","review_comment_url":"https://api.github.com/repos/cerner/cerner_splunk/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cerner/cerner_splunk/issues/48/comments","statuses_url":"https://api.github.com/repos/cerner/cerner_splunk/statuses/a44768b5e83fabfe91ba8c0859698fab79b9f73b","head":{"label":"acharlieh:issue/37","ref":"issue/37","sha":"a44768b5e83fabfe91ba8c0859698fab79b9f73b","user":{"login":"acharlieh","id":413832,"avatar_url":"https://avatars.githubusercontent.com/u/413832?v=3","gravatar_id":"","url":"https://api.github.com/users/acharlieh","html_url":"https://github.com/acharlieh","followers_url":"https://api.github.com/users/acharlieh/followers","following_url":"https://api.github.com/users/acharlieh/following{/other_user}","gists_url":"https://api.github.com/users/acharlieh/gists{/gist_id}","starred_url":"https://api.github.com/users/acharlieh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acharlieh/subscriptions","organizations_url":"https://api.github.com/users/acharlieh/orgs","repos_url":"https://api.github.com/users/acharlieh/repos","events_url":"https://api.github.com/users/acharlieh/events{/privacy}","received_events_url":"https://api.github.com/users/acharlieh/received_events","type":"User","site_admin":false},"repo":{"id":26274824,"name":"cerner_splunk","full_name":"acharlieh/cerner_splunk","owner":{"login":"acharlieh","id":413832,"avatar_url":"https://avatars.githubusercontent.com/u/413832?v=3","gravatar_id":"","url":"https://api.github.com/users/acharlieh","html_url":"https://github.com/acharlieh","followers_url":"https://api.github.com/users/acharlieh/followers","following_url":"https://api.github.com/users/acharlieh/following{/other_user}","gists_url":"https://api.github.com/users/acharlieh/gists{/gist_id}","starred_url":"https://api.github.com/users/acharlieh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/acharlieh/subscriptions","organizations_url":"https://api.github.com/users/acharlieh/orgs","repos_url":"https://api.github.com/users/acharlieh/repos","events_url":"https://api.github.com/users/acharlieh/events{/privacy}","received_events_url":"https://api.github.com/users/acharlieh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/acharlieh/cerner_splunk","description":"Cerner's Splunk Cookbook","fork":true,"url":"https://api.github.com/repos/acharlieh/cerner_splunk","forks_url":"https://api.github.com/repos/acharlieh/cerner_splunk/forks","keys_url":"https://api.github.com/repos/acharlieh/cerner_splunk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/acharlieh/cerner_splunk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/acharlieh/cerner_splunk/teams","hooks_url":"https://api.github.com/repos/acharlieh/cerner_splunk/hooks","issue_events_url":"https://api.github.com/repos/acharlieh/cerner_splunk/issues/events{/number}","events_url":"https://api.github.com/repos/acharlieh/cerner_splunk/events","assignees_url":"https://api.github.com/repos/acharlieh/cerner_splunk/assignees{/user}","branches_url":"https://api.github.com/repos/acharlieh/cerner_splunk/branches{/branch}","tags_url":"https://api.github.com/repos/acharlieh/cerner_splunk/tags","blobs_url":"https://api.github.com/repos/acharlieh/cerner_splunk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/acharlieh/cerner_splunk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/acharlieh/cerner_splunk/git/refs{/sha}","trees_url":"https://api.github.com/repos/acharlieh/cerner_splunk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/acharlieh/cerner_splunk/statuses/{sha}","languages_url":"https://api.github.com/repos/acharlieh/cerner_splunk/languages","stargazers_url":"https://api.github.com/repos/acharlieh/cerner_splunk/stargazers","contributors_url":"https://api.github.com/repos/acharlieh/cerner_splunk/contributors","subscribers_url":"https://api.github.com/repos/acharlieh/cerner_splunk/subscribers","subscription_url":"https://api.github.com/repos/acharlieh/cerner_splunk/subscription","commits_url":"https://api.github.com/repos/acharlieh/cerner_splunk/commits{/sha}","git_commits_url":"https://api.github.com/repos/acharlieh/cerner_splunk/git/commits{/sha}","comments_url":"https://api.github.com/repos/acharlieh/cerner_splunk/comments{/number}","issue_comment_url":"https://api.github.com/repos/acharlieh/cerner_splunk/issues/comments{/number}","contents_url":"https://api.github.com/repos/acharlieh/cerner_splunk/contents/{+path}","compare_url":"https://api.github.com/repos/acharlieh/cerner_splunk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/acharlieh/cerner_splunk/merges","archive_url":"https://api.github.com/repos/acharlieh/cerner_splunk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/acharlieh/cerner_splunk/downloads","issues_url":"https://api.github.com/repos/acharlieh/cerner_splunk/issues{/number}","pulls_url":"https://api.github.com/repos/acharlieh/cerner_splunk/pulls{/number}","milestones_url":"https://api.github.com/repos/acharlieh/cerner_splunk/milestones{/number}","notifications_url":"https://api.github.com/repos/acharlieh/cerner_splunk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/acharlieh/cerner_splunk/labels{/name}","releases_url":"https://api.github.com/repos/acharlieh/cerner_splunk/releases{/id}","created_at":"2014-11-06T14:59:42Z","updated_at":"2015-02-12T22:55:46Z","pushed_at":"2015-03-04T22:03:29Z","git_url":"git://github.com/acharlieh/cerner_splunk.git","ssh_url":"git@github.com:acharlieh/cerner_splunk.git","clone_url":"https://github.com/acharlieh/cerner_splunk.git","svn_url":"https://github.com/acharlieh/cerner_splunk","homepage":null,"size":409,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cerner:stable","ref":"stable","sha":"866cbae38f75c2a96a681ee303587d8322ab4447","user":{"login":"cerner","id":1873208,"avatar_url":"https://avatars.githubusercontent.com/u/1873208?v=3","gravatar_id":"","url":"https://api.github.com/users/cerner","html_url":"https://github.com/cerner","followers_url":"https://api.github.com/users/cerner/followers","following_url":"https://api.github.com/users/cerner/following{/other_user}","gists_url":"https://api.github.com/users/cerner/gists{/gist_id}","starred_url":"https://api.github.com/users/cerner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cerner/subscriptions","organizations_url":"https://api.github.com/users/cerner/orgs","repos_url":"https://api.github.com/users/cerner/repos","events_url":"https://api.github.com/users/cerner/events{/privacy}","received_events_url":"https://api.github.com/users/cerner/received_events","type":"Organization","site_admin":false},"repo":{"id":24943819,"name":"cerner_splunk","full_name":"cerner/cerner_splunk","owner":{"login":"cerner","id":1873208,"avatar_url":"https://avatars.githubusercontent.com/u/1873208?v=3","gravatar_id":"","url":"https://api.github.com/users/cerner","html_url":"https://github.com/cerner","followers_url":"https://api.github.com/users/cerner/followers","following_url":"https://api.github.com/users/cerner/following{/other_user}","gists_url":"https://api.github.com/users/cerner/gists{/gist_id}","starred_url":"https://api.github.com/users/cerner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cerner/subscriptions","organizations_url":"https://api.github.com/users/cerner/orgs","repos_url":"https://api.github.com/users/cerner/repos","events_url":"https://api.github.com/users/cerner/events{/privacy}","received_events_url":"https://api.github.com/users/cerner/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cerner/cerner_splunk","description":"Cerner's Splunk Cookbook","fork":false,"url":"https://api.github.com/repos/cerner/cerner_splunk","forks_url":"https://api.github.com/repos/cerner/cerner_splunk/forks","keys_url":"https://api.github.com/repos/cerner/cerner_splunk/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cerner/cerner_splunk/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cerner/cerner_splunk/teams","hooks_url":"https://api.github.com/repos/cerner/cerner_splunk/hooks","issue_events_url":"https://api.github.com/repos/cerner/cerner_splunk/issues/events{/number}","events_url":"https://api.github.com/repos/cerner/cerner_splunk/events","assignees_url":"https://api.github.com/repos/cerner/cerner_splunk/assignees{/user}","branches_url":"https://api.github.com/repos/cerner/cerner_splunk/branches{/branch}","tags_url":"https://api.github.com/repos/cerner/cerner_splunk/tags","blobs_url":"https://api.github.com/repos/cerner/cerner_splunk/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cerner/cerner_splunk/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cerner/cerner_splunk/git/refs{/sha}","trees_url":"https://api.github.com/repos/cerner/cerner_splunk/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cerner/cerner_splunk/statuses/{sha}","languages_url":"https://api.github.com/repos/cerner/cerner_splunk/languages","stargazers_url":"https://api.github.com/repos/cerner/cerner_splunk/stargazers","contributors_url":"https://api.github.com/repos/cerner/cerner_splunk/contributors","subscribers_url":"https://api.github.com/repos/cerner/cerner_splunk/subscribers","subscription_url":"https://api.github.com/repos/cerner/cerner_splunk/subscription","commits_url":"https://api.github.com/repos/cerner/cerner_splunk/commits{/sha}","git_commits_url":"https://api.github.com/repos/cerner/cerner_splunk/git/commits{/sha}","comments_url":"https://api.github.com/repos/cerner/cerner_splunk/comments{/number}","issue_comment_url":"https://api.github.com/repos/cerner/cerner_splunk/issues/comments{/number}","contents_url":"https://api.github.com/repos/cerner/cerner_splunk/contents/{+path}","compare_url":"https://api.github.com/repos/cerner/cerner_splunk/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cerner/cerner_splunk/merges","archive_url":"https://api.github.com/repos/cerner/cerner_splunk/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cerner/cerner_splunk/downloads","issues_url":"https://api.github.com/repos/cerner/cerner_splunk/issues{/number}","pulls_url":"https://api.github.com/repos/cerner/cerner_splunk/pulls{/number}","milestones_url":"https://api.github.com/repos/cerner/cerner_splunk/milestones{/number}","notifications_url":"https://api.github.com/repos/cerner/cerner_splunk/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cerner/cerner_splunk/labels{/name}","releases_url":"https://api.github.com/repos/cerner/cerner_splunk/releases{/id}","created_at":"2014-10-08T14:13:04Z","updated_at":"2015-02-24T14:38:35Z","pushed_at":"2015-02-12T22:50:56Z","git_url":"git://github.com/cerner/cerner_splunk.git","ssh_url":"git@github.com:cerner/cerner_splunk.git","clone_url":"https://github.com/cerner/cerner_splunk.git","svn_url":"https://github.com/cerner/cerner_splunk","homepage":null,"size":601,"stargazers_count":4,"watchers_count":4,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":4,"mirror_url":null,"open_issues_count":12,"forks":4,"open_issues":12,"watchers":4,"default_branch":"stable"}},"_links":{"self":{"href":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48"},"html":{"href":"https://github.com/cerner/cerner_splunk/pull/48"},"issue":{"href":"https://api.github.com/repos/cerner/cerner_splunk/issues/48"},"comments":{"href":"https://api.github.com/repos/cerner/cerner_splunk/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/cerner/cerner_splunk/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cerner/cerner_splunk/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/cerner/cerner_splunk/statuses/a44768b5e83fabfe91ba8c0859698fab79b9f73b"}}}}