{"action":"created","comment":{"url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/comments/29331145","id":29331145,"diff_hunk":"@@ -13,10 +13,32 @@\n require 'json'\n require 'proxy/error'\n require 'proxy/request'\n+require 'smart_proxy_openscap/openscap_exception'\n \n module Proxy::OpenSCAP\n   extend ::Proxy::Log\n \n+  def self.get_policy_content(policy_id)\n+    policy_store_dir = File.join(Proxy::OpenSCAP::Plugin.settings.contentdir, policy_id.to_s)\n+    policy_scap_file = File.join(policy_store_dir, \"#{policy_id}_scap_content.xml\")\n+    FileUtils.mkdir_p(policy_store_dir) # will fail silently if exists\n+\n+    return File.open(policy_scap_file, 'rb').read if File.file?(policy_scap_file) && !File.zero?(policy_scap_file)\n+\n+    lock = Proxy::HttpDownloads.try_locking(policy_scap_file)\n+\n+    response = fetch_scap_content_xml(policy_id, policy_scap_file)\n+    if lock.nil?\n+      return response\n+    else\n+      File.open(policy_scap_file, 'wb') do |file|\n+        file << response\n+      end\n+      Proxy::HttpDownloads.unlock(lock)","path":"lib/smart_proxy_openscap/openscap_lib.rb","position":25,"original_position":25,"commit_id":"fe16fa073b7659eee8e07d81c52b4468a8ec4b30","original_commit_id":"fe16fa073b7659eee8e07d81c52b4468a8ec4b30","user":{"login":"witlessbird","id":8957,"avatar_url":"https://avatars.githubusercontent.com/u/8957?v=3","gravatar_id":"","url":"https://api.github.com/users/witlessbird","html_url":"https://github.com/witlessbird","followers_url":"https://api.github.com/users/witlessbird/followers","following_url":"https://api.github.com/users/witlessbird/following{/other_user}","gists_url":"https://api.github.com/users/witlessbird/gists{/gist_id}","starred_url":"https://api.github.com/users/witlessbird/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/witlessbird/subscriptions","organizations_url":"https://api.github.com/users/witlessbird/orgs","repos_url":"https://api.github.com/users/witlessbird/repos","events_url":"https://api.github.com/users/witlessbird/events{/privacy}","received_events_url":"https://api.github.com/users/witlessbird/received_events","type":"User","site_admin":false},"body":"You should release the lock in ```ensure``` block, it will stick around should file creation fail.","created_at":"2015-04-29T12:37:18Z","updated_at":"2015-04-29T12:37:18Z","html_url":"https://github.com/OpenSCAP/smart_proxy_openscap/pull/10#discussion_r29331145","pull_request_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10","_links":{"self":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/comments/29331145"},"html":{"href":"https://github.com/OpenSCAP/smart_proxy_openscap/pull/10#discussion_r29331145"},"pull_request":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10","id":33616718,"html_url":"https://github.com/OpenSCAP/smart_proxy_openscap/pull/10","diff_url":"https://github.com/OpenSCAP/smart_proxy_openscap/pull/10.diff","patch_url":"https://github.com/OpenSCAP/smart_proxy_openscap/pull/10.patch","issue_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues/10","number":10,"state":"open","locked":false,"title":"serve as proxy to scap content","user":{"login":"shlomizadok","id":433583,"avatar_url":"https://avatars.githubusercontent.com/u/433583?v=3","gravatar_id":"","url":"https://api.github.com/users/shlomizadok","html_url":"https://github.com/shlomizadok","followers_url":"https://api.github.com/users/shlomizadok/followers","following_url":"https://api.github.com/users/shlomizadok/following{/other_user}","gists_url":"https://api.github.com/users/shlomizadok/gists{/gist_id}","starred_url":"https://api.github.com/users/shlomizadok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shlomizadok/subscriptions","organizations_url":"https://api.github.com/users/shlomizadok/orgs","repos_url":"https://api.github.com/users/shlomizadok/repos","events_url":"https://api.github.com/users/shlomizadok/events{/privacy}","received_events_url":"https://api.github.com/users/shlomizadok/received_events","type":"User","site_admin":false},"body":"Serves as proxy to foreman and fetch scap content xml.\r\ndependent on: https://github.com/OpenSCAP/foreman_openscap/pull/97\r\n\r\n**Should be merged also to master branch**","created_at":"2015-04-19T10:31:57Z","updated_at":"2015-04-29T12:37:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ed455eb82ebbd37481c443edaeb40853444401b7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10/commits","review_comments_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10/comments","review_comment_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/comments{/number}","comments_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues/10/comments","statuses_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/statuses/fe16fa073b7659eee8e07d81c52b4468a8ec4b30","head":{"label":"shlomizadok:proxy_scap_content","ref":"proxy_scap_content","sha":"fe16fa073b7659eee8e07d81c52b4468a8ec4b30","user":{"login":"shlomizadok","id":433583,"avatar_url":"https://avatars.githubusercontent.com/u/433583?v=3","gravatar_id":"","url":"https://api.github.com/users/shlomizadok","html_url":"https://github.com/shlomizadok","followers_url":"https://api.github.com/users/shlomizadok/followers","following_url":"https://api.github.com/users/shlomizadok/following{/other_user}","gists_url":"https://api.github.com/users/shlomizadok/gists{/gist_id}","starred_url":"https://api.github.com/users/shlomizadok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shlomizadok/subscriptions","organizations_url":"https://api.github.com/users/shlomizadok/orgs","repos_url":"https://api.github.com/users/shlomizadok/repos","events_url":"https://api.github.com/users/shlomizadok/events{/privacy}","received_events_url":"https://api.github.com/users/shlomizadok/received_events","type":"User","site_admin":false},"repo":{"id":27426452,"name":"smart_proxy_openscap","full_name":"shlomizadok/smart_proxy_openscap","owner":{"login":"shlomizadok","id":433583,"avatar_url":"https://avatars.githubusercontent.com/u/433583?v=3","gravatar_id":"","url":"https://api.github.com/users/shlomizadok","html_url":"https://github.com/shlomizadok","followers_url":"https://api.github.com/users/shlomizadok/followers","following_url":"https://api.github.com/users/shlomizadok/following{/other_user}","gists_url":"https://api.github.com/users/shlomizadok/gists{/gist_id}","starred_url":"https://api.github.com/users/shlomizadok/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shlomizadok/subscriptions","organizations_url":"https://api.github.com/users/shlomizadok/orgs","repos_url":"https://api.github.com/users/shlomizadok/repos","events_url":"https://api.github.com/users/shlomizadok/events{/privacy}","received_events_url":"https://api.github.com/users/shlomizadok/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/shlomizadok/smart_proxy_openscap","description":"OpenSCAP plug-in for Foreman's smart-proxy.","fork":true,"url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap","forks_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/forks","keys_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/teams","hooks_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/hooks","issue_events_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/issues/events{/number}","events_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/events","assignees_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/assignees{/user}","branches_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/branches{/branch}","tags_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/tags","blobs_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/git/refs{/sha}","trees_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/statuses/{sha}","languages_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/languages","stargazers_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/stargazers","contributors_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/contributors","subscribers_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/subscribers","subscription_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/subscription","commits_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/commits{/sha}","git_commits_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/git/commits{/sha}","comments_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/comments{/number}","issue_comment_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/issues/comments{/number}","contents_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/contents/{+path}","compare_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/merges","archive_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/downloads","issues_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/issues{/number}","pulls_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/pulls{/number}","milestones_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/milestones{/number}","notifications_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/labels{/name}","releases_url":"https://api.github.com/repos/shlomizadok/smart_proxy_openscap/releases{/id}","created_at":"2014-12-02T10:04:55Z","updated_at":"2015-04-16T13:47:47Z","pushed_at":"2015-04-21T18:31:32Z","git_url":"git://github.com/shlomizadok/smart_proxy_openscap.git","ssh_url":"git@github.com:shlomizadok/smart_proxy_openscap.git","clone_url":"https://github.com/shlomizadok/smart_proxy_openscap.git","svn_url":"https://github.com/shlomizadok/smart_proxy_openscap","homepage":"","size":155,"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":"OpenSCAP:maint-foreman17","ref":"maint-foreman17","sha":"7c01b52c03876c24dd6213a28869b5aadec1de79","user":{"login":"OpenSCAP","id":7439934,"avatar_url":"https://avatars.githubusercontent.com/u/7439934?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenSCAP","html_url":"https://github.com/OpenSCAP","followers_url":"https://api.github.com/users/OpenSCAP/followers","following_url":"https://api.github.com/users/OpenSCAP/following{/other_user}","gists_url":"https://api.github.com/users/OpenSCAP/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenSCAP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenSCAP/subscriptions","organizations_url":"https://api.github.com/users/OpenSCAP/orgs","repos_url":"https://api.github.com/users/OpenSCAP/repos","events_url":"https://api.github.com/users/OpenSCAP/events{/privacy}","received_events_url":"https://api.github.com/users/OpenSCAP/received_events","type":"Organization","site_admin":false},"repo":{"id":21616058,"name":"smart_proxy_openscap","full_name":"OpenSCAP/smart_proxy_openscap","owner":{"login":"OpenSCAP","id":7439934,"avatar_url":"https://avatars.githubusercontent.com/u/7439934?v=3","gravatar_id":"","url":"https://api.github.com/users/OpenSCAP","html_url":"https://github.com/OpenSCAP","followers_url":"https://api.github.com/users/OpenSCAP/followers","following_url":"https://api.github.com/users/OpenSCAP/following{/other_user}","gists_url":"https://api.github.com/users/OpenSCAP/gists{/gist_id}","starred_url":"https://api.github.com/users/OpenSCAP/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/OpenSCAP/subscriptions","organizations_url":"https://api.github.com/users/OpenSCAP/orgs","repos_url":"https://api.github.com/users/OpenSCAP/repos","events_url":"https://api.github.com/users/OpenSCAP/events{/privacy}","received_events_url":"https://api.github.com/users/OpenSCAP/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/OpenSCAP/smart_proxy_openscap","description":"OpenSCAP plug-in for Foreman's smart-proxy.","fork":false,"url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap","forks_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/forks","keys_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/keys{/key_id}","collaborators_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/teams","hooks_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/hooks","issue_events_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues/events{/number}","events_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/events","assignees_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/assignees{/user}","branches_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/branches{/branch}","tags_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/tags","blobs_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/git/refs{/sha}","trees_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/git/trees{/sha}","statuses_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/statuses/{sha}","languages_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/languages","stargazers_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/stargazers","contributors_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/contributors","subscribers_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/subscribers","subscription_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/subscription","commits_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/commits{/sha}","git_commits_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/git/commits{/sha}","comments_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/comments{/number}","issue_comment_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues/comments{/number}","contents_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/contents/{+path}","compare_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/compare/{base}...{head}","merges_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/merges","archive_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/downloads","issues_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues{/number}","pulls_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls{/number}","milestones_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/milestones{/number}","notifications_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/labels{/name}","releases_url":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/releases{/id}","created_at":"2014-07-08T14:36:02Z","updated_at":"2015-03-25T16:11:36Z","pushed_at":"2015-04-21T18:31:32Z","git_url":"git://github.com/OpenSCAP/smart_proxy_openscap.git","ssh_url":"git@github.com:OpenSCAP/smart_proxy_openscap.git","clone_url":"https://github.com/OpenSCAP/smart_proxy_openscap.git","svn_url":"https://github.com/OpenSCAP/smart_proxy_openscap","homepage":"","size":605,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":1,"forks":5,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10"},"html":{"href":"https://github.com/OpenSCAP/smart_proxy_openscap/pull/10"},"issue":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues/10"},"comments":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/OpenSCAP/smart_proxy_openscap/statuses/fe16fa073b7659eee8e07d81c52b4468a8ec4b30"}}}}