{"action":"created","comment":{"url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments/28892066","id":28892066,"diff_hunk":"@@ -4,6 +4,60 @@ class API\n \n     module Helpers\n \n+      def protected!\n+        return if authorized?\n+\n+        content_type :json\n+\n+        result = { 'ok' => false }\n+\n+        headers['WWW-Authenticate'] = 'Basic realm=\"Authentication required\"'\n+        halt 401, JSON.pretty_generate(result)\n+      end\n+\n+      def authorized?\n+        @auth ||= Rack::Auth::Basic::Request.new(request.env)\n+\n+        if @auth.provided? and @auth.basic? and @auth.credentials\n+          username, password = @auth.credentials\n+\n+          if authenticate(Vmpooler::API.settings.config[:auth], username, password)\n+            return true\n+          end\n+        end\n+\n+        return false\n+      end\n+\n+      def authenticate(auth, username_str, password_str)\n+        case auth['provider']\n+          when 'ldap'\n+            require 'rubygems'\n+            require 'net/ldap'\n+\n+            ldap = Net::LDAP.new(\n+              :host => auth[:ldap]['host'],\n+              :port => auth[:ldap]['port'] || 389,","path":"lib/vmpooler/api/helpers.rb","position":37,"original_position":37,"commit_id":"bad1ce65a1c324fbc551f959cf17f535258cc6ea","original_commit_id":"bad1ce65a1c324fbc551f959cf17f535258cc6ea","user":{"login":"rji","id":1910193,"avatar_url":"https://avatars.githubusercontent.com/u/1910193?v=3","gravatar_id":"","url":"https://api.github.com/users/rji","html_url":"https://github.com/rji","followers_url":"https://api.github.com/users/rji/followers","following_url":"https://api.github.com/users/rji/following{/other_user}","gists_url":"https://api.github.com/users/rji/gists{/gist_id}","starred_url":"https://api.github.com/users/rji/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rji/subscriptions","organizations_url":"https://api.github.com/users/rji/orgs","repos_url":"https://api.github.com/users/rji/repos","events_url":"https://api.github.com/users/rji/events{/privacy}","received_events_url":"https://api.github.com/users/rji/received_events","type":"User","site_admin":false},"body":"Since we default to TLS below, we probably want the default LDAP port to be 636","created_at":"2015-04-22T16:52:24Z","updated_at":"2015-04-22T16:52:24Z","html_url":"https://github.com/puppetlabs/vmpooler/pull/97#discussion_r28892066","pull_request_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97","_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments/28892066"},"html":{"href":"https://github.com/puppetlabs/vmpooler/pull/97#discussion_r28892066"},"pull_request":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97"}}},"pull_request":{"url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97","id":33815786,"html_url":"https://github.com/puppetlabs/vmpooler/pull/97","diff_url":"https://github.com/puppetlabs/vmpooler/pull/97.diff","patch_url":"https://github.com/puppetlabs/vmpooler/pull/97.patch","issue_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/97","number":97,"state":"open","locked":false,"title":"Add basic HTTP authentication and /token routes","user":{"login":"sschneid","id":20033,"avatar_url":"https://avatars.githubusercontent.com/u/20033?v=3","gravatar_id":"","url":"https://api.github.com/users/sschneid","html_url":"https://github.com/sschneid","followers_url":"https://api.github.com/users/sschneid/followers","following_url":"https://api.github.com/users/sschneid/following{/other_user}","gists_url":"https://api.github.com/users/sschneid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschneid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschneid/subscriptions","organizations_url":"https://api.github.com/users/sschneid/orgs","repos_url":"https://api.github.com/users/sschneid/repos","events_url":"https://api.github.com/users/sschneid/events{/privacy}","received_events_url":"https://api.github.com/users/sschneid/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-04-22T00:13:48Z","updated_at":"2015-04-22T16:52:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"416ddb210e2751b32185d334eaf6c4cf86c34607","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97/commits","review_comments_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97/comments","review_comment_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments{/number}","comments_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/97/comments","statuses_url":"https://api.github.com/repos/puppetlabs/vmpooler/statuses/bad1ce65a1c324fbc551f959cf17f535258cc6ea","head":{"label":"sschneid:basic_auth","ref":"basic_auth","sha":"bad1ce65a1c324fbc551f959cf17f535258cc6ea","user":{"login":"sschneid","id":20033,"avatar_url":"https://avatars.githubusercontent.com/u/20033?v=3","gravatar_id":"","url":"https://api.github.com/users/sschneid","html_url":"https://github.com/sschneid","followers_url":"https://api.github.com/users/sschneid/followers","following_url":"https://api.github.com/users/sschneid/following{/other_user}","gists_url":"https://api.github.com/users/sschneid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschneid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschneid/subscriptions","organizations_url":"https://api.github.com/users/sschneid/orgs","repos_url":"https://api.github.com/users/sschneid/repos","events_url":"https://api.github.com/users/sschneid/events{/privacy}","received_events_url":"https://api.github.com/users/sschneid/received_events","type":"User","site_admin":false},"repo":{"id":21907793,"name":"vmpooler","full_name":"sschneid/vmpooler","owner":{"login":"sschneid","id":20033,"avatar_url":"https://avatars.githubusercontent.com/u/20033?v=3","gravatar_id":"","url":"https://api.github.com/users/sschneid","html_url":"https://github.com/sschneid","followers_url":"https://api.github.com/users/sschneid/followers","following_url":"https://api.github.com/users/sschneid/following{/other_user}","gists_url":"https://api.github.com/users/sschneid/gists{/gist_id}","starred_url":"https://api.github.com/users/sschneid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sschneid/subscriptions","organizations_url":"https://api.github.com/users/sschneid/orgs","repos_url":"https://api.github.com/users/sschneid/repos","events_url":"https://api.github.com/users/sschneid/events{/privacy}","received_events_url":"https://api.github.com/users/sschneid/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sschneid/vmpooler","description":"Provide configurable 'pools' of available (running) virtual machines","fork":true,"url":"https://api.github.com/repos/sschneid/vmpooler","forks_url":"https://api.github.com/repos/sschneid/vmpooler/forks","keys_url":"https://api.github.com/repos/sschneid/vmpooler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sschneid/vmpooler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sschneid/vmpooler/teams","hooks_url":"https://api.github.com/repos/sschneid/vmpooler/hooks","issue_events_url":"https://api.github.com/repos/sschneid/vmpooler/issues/events{/number}","events_url":"https://api.github.com/repos/sschneid/vmpooler/events","assignees_url":"https://api.github.com/repos/sschneid/vmpooler/assignees{/user}","branches_url":"https://api.github.com/repos/sschneid/vmpooler/branches{/branch}","tags_url":"https://api.github.com/repos/sschneid/vmpooler/tags","blobs_url":"https://api.github.com/repos/sschneid/vmpooler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sschneid/vmpooler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sschneid/vmpooler/git/refs{/sha}","trees_url":"https://api.github.com/repos/sschneid/vmpooler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sschneid/vmpooler/statuses/{sha}","languages_url":"https://api.github.com/repos/sschneid/vmpooler/languages","stargazers_url":"https://api.github.com/repos/sschneid/vmpooler/stargazers","contributors_url":"https://api.github.com/repos/sschneid/vmpooler/contributors","subscribers_url":"https://api.github.com/repos/sschneid/vmpooler/subscribers","subscription_url":"https://api.github.com/repos/sschneid/vmpooler/subscription","commits_url":"https://api.github.com/repos/sschneid/vmpooler/commits{/sha}","git_commits_url":"https://api.github.com/repos/sschneid/vmpooler/git/commits{/sha}","comments_url":"https://api.github.com/repos/sschneid/vmpooler/comments{/number}","issue_comment_url":"https://api.github.com/repos/sschneid/vmpooler/issues/comments{/number}","contents_url":"https://api.github.com/repos/sschneid/vmpooler/contents/{+path}","compare_url":"https://api.github.com/repos/sschneid/vmpooler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sschneid/vmpooler/merges","archive_url":"https://api.github.com/repos/sschneid/vmpooler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sschneid/vmpooler/downloads","issues_url":"https://api.github.com/repos/sschneid/vmpooler/issues{/number}","pulls_url":"https://api.github.com/repos/sschneid/vmpooler/pulls{/number}","milestones_url":"https://api.github.com/repos/sschneid/vmpooler/milestones{/number}","notifications_url":"https://api.github.com/repos/sschneid/vmpooler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sschneid/vmpooler/labels{/name}","releases_url":"https://api.github.com/repos/sschneid/vmpooler/releases{/id}","created_at":"2014-07-16T16:07:36Z","updated_at":"2015-04-15T20:02:11Z","pushed_at":"2015-04-22T00:12:48Z","git_url":"git://github.com/sschneid/vmpooler.git","ssh_url":"git@github.com:sschneid/vmpooler.git","clone_url":"https://github.com/sschneid/vmpooler.git","svn_url":"https://github.com/sschneid/vmpooler","homepage":"","size":2123,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":1,"mirror_url":null,"open_issues_count":0,"forks":1,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"puppetlabs:master","ref":"master","sha":"331ac33b539cec2d69e64864aa20788c30464211","user":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"repo":{"id":13072980,"name":"vmpooler","full_name":"puppetlabs/vmpooler","owner":{"login":"puppetlabs","id":234268,"avatar_url":"https://avatars.githubusercontent.com/u/234268?v=3","gravatar_id":"","url":"https://api.github.com/users/puppetlabs","html_url":"https://github.com/puppetlabs","followers_url":"https://api.github.com/users/puppetlabs/followers","following_url":"https://api.github.com/users/puppetlabs/following{/other_user}","gists_url":"https://api.github.com/users/puppetlabs/gists{/gist_id}","starred_url":"https://api.github.com/users/puppetlabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/puppetlabs/subscriptions","organizations_url":"https://api.github.com/users/puppetlabs/orgs","repos_url":"https://api.github.com/users/puppetlabs/repos","events_url":"https://api.github.com/users/puppetlabs/events{/privacy}","received_events_url":"https://api.github.com/users/puppetlabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/puppetlabs/vmpooler","description":"Provide configurable 'pools' of available (running) virtual machines","fork":false,"url":"https://api.github.com/repos/puppetlabs/vmpooler","forks_url":"https://api.github.com/repos/puppetlabs/vmpooler/forks","keys_url":"https://api.github.com/repos/puppetlabs/vmpooler/keys{/key_id}","collaborators_url":"https://api.github.com/repos/puppetlabs/vmpooler/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/puppetlabs/vmpooler/teams","hooks_url":"https://api.github.com/repos/puppetlabs/vmpooler/hooks","issue_events_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/events{/number}","events_url":"https://api.github.com/repos/puppetlabs/vmpooler/events","assignees_url":"https://api.github.com/repos/puppetlabs/vmpooler/assignees{/user}","branches_url":"https://api.github.com/repos/puppetlabs/vmpooler/branches{/branch}","tags_url":"https://api.github.com/repos/puppetlabs/vmpooler/tags","blobs_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/refs{/sha}","trees_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/trees{/sha}","statuses_url":"https://api.github.com/repos/puppetlabs/vmpooler/statuses/{sha}","languages_url":"https://api.github.com/repos/puppetlabs/vmpooler/languages","stargazers_url":"https://api.github.com/repos/puppetlabs/vmpooler/stargazers","contributors_url":"https://api.github.com/repos/puppetlabs/vmpooler/contributors","subscribers_url":"https://api.github.com/repos/puppetlabs/vmpooler/subscribers","subscription_url":"https://api.github.com/repos/puppetlabs/vmpooler/subscription","commits_url":"https://api.github.com/repos/puppetlabs/vmpooler/commits{/sha}","git_commits_url":"https://api.github.com/repos/puppetlabs/vmpooler/git/commits{/sha}","comments_url":"https://api.github.com/repos/puppetlabs/vmpooler/comments{/number}","issue_comment_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues/comments{/number}","contents_url":"https://api.github.com/repos/puppetlabs/vmpooler/contents/{+path}","compare_url":"https://api.github.com/repos/puppetlabs/vmpooler/compare/{base}...{head}","merges_url":"https://api.github.com/repos/puppetlabs/vmpooler/merges","archive_url":"https://api.github.com/repos/puppetlabs/vmpooler/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/puppetlabs/vmpooler/downloads","issues_url":"https://api.github.com/repos/puppetlabs/vmpooler/issues{/number}","pulls_url":"https://api.github.com/repos/puppetlabs/vmpooler/pulls{/number}","milestones_url":"https://api.github.com/repos/puppetlabs/vmpooler/milestones{/number}","notifications_url":"https://api.github.com/repos/puppetlabs/vmpooler/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/puppetlabs/vmpooler/labels{/name}","releases_url":"https://api.github.com/repos/puppetlabs/vmpooler/releases{/id}","created_at":"2013-09-24T18:27:35Z","updated_at":"2015-04-15T19:59:31Z","pushed_at":"2015-04-22T00:13:49Z","git_url":"git://github.com/puppetlabs/vmpooler.git","ssh_url":"git@github.com:puppetlabs/vmpooler.git","clone_url":"https://github.com/puppetlabs/vmpooler.git","svn_url":"https://github.com/puppetlabs/vmpooler","homepage":"","size":2731,"stargazers_count":27,"watchers_count":27,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":11,"mirror_url":null,"open_issues_count":8,"forks":11,"open_issues":8,"watchers":27,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97"},"html":{"href":"https://github.com/puppetlabs/vmpooler/pull/97"},"issue":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/issues/97"},"comments":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/issues/97/comments"},"review_comments":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97/comments"},"review_comment":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/pulls/97/commits"},"statuses":{"href":"https://api.github.com/repos/puppetlabs/vmpooler/statuses/bad1ce65a1c324fbc551f959cf17f535258cc6ea"}}}}