{"action":"created","comment":{"url":"https://api.github.com/repos/theforeman/foreman-docker/pulls/comments/103987262","pull_request_review_id":24795311,"id":103987262,"diff_hunk":"@@ -1,26 +1,85 @@\n module Service\n   class RegistryApi\n-    DEFAULTS = { :url => 'http://localhost:5000' }\n-    attr_reader :config\n+    DOCKER_HUB = 'https://registry.hub.docker.com/'\n+    DEFAULTS = {\n+      url: 'http://localhost:5000',\n+      connection: { omit_default_port: true }\n+    }\n+\n+    attr_accessor :config, :url\n \n     def initialize(params = {})\n-      config = DEFAULTS.merge(params)\n-      uri = URI(config.delete(:url))\n-      uri.user = config.delete(:user) unless config[:user].blank?\n-      uri.password = config.delete(:password) unless config[:password].blank?\n-      @config = config.merge(:url => uri.to_s)\n+      self.config = DEFAULTS.merge(params)\n+      self.url = config[:url]\n+      @user = config[:user] unless config[:user].blank?\n+      @password = config[:password] unless config[:password].blank?\n+\n+      Docker.logger = Rails.logger if Rails.env.development?\n+    end\n+\n+    def connection\n+      @connection ||= ::Docker::Connection.new(url, credentials)\n+    end\n+\n+    def get(path, params = nil)\n+      response = connection.get('/', params,\n+                                DEFAULTS[:connection].merge({ path: \"#{path}\" }))\n+      response = JSON.parse(response) rescue\n+      response\n+    end\n+\n+    # Since the Registry API v2 does not support a search the v1 endpoint is used\n+    # Newer registries will fail, the v2 catalog endpoint is used\n+    def search(query)\n+      get('/v1/search', { q: query })\n+    rescue\n+      { 'results' => catalog(query) }\n+    end\n+\n+    # Some Registries might have this endpoint not implemented/enabled\n+    def catalog(query)\n+      get('/v2/_catalog')['repositories'].select do |image|\n+        image =~ /^#{query}/\n+      end.map { |image_name| { 'name' => image_name } }\n+    end\n+\n+    def tags(image_name, query = nil)\n+      result = get_tags(image_name)\n+      result = result.keys.map { |t| {'name' => t.to_s } } if result.is_a? Hash\n+      result = filter_tags(result, query) if query\n+      result\n+    end\n+\n+    def ok?\n+      get('/v1/').match(\"Docker Registry API\")","path":"app/models/service/registry_api.rb","position":61,"original_position":61,"commit_id":"aa8de13a6153fee1728625c891da8e1f8000f371","original_commit_id":"aa8de13a6153fee1728625c891da8e1f8000f371","user":{"login":"dLobatog","id":598891,"avatar_url":"https://avatars1.githubusercontent.com/u/598891?v=3","gravatar_id":"","url":"https://api.github.com/users/dLobatog","html_url":"https://github.com/dLobatog","followers_url":"https://api.github.com/users/dLobatog/followers","following_url":"https://api.github.com/users/dLobatog/following{/other_user}","gists_url":"https://api.github.com/users/dLobatog/gists{/gist_id}","starred_url":"https://api.github.com/users/dLobatog/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dLobatog/subscriptions","organizations_url":"https://api.github.com/users/dLobatog/orgs","repos_url":"https://api.github.com/users/dLobatog/repos","events_url":"https://api.github.com/users/dLobatog/events{/privacy}","received_events_url":"https://api.github.com/users/dLobatog/received_events","type":"User","site_admin":false},"body":"frozen string(s) ","created_at":"2017-03-02T17:52:22Z","updated_at":"2017-03-02T17:55:50Z","html_url":"https://github.com/theforeman/foreman-docker/pull/184#discussion_r103987262","pull_request_url":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184","_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman-docker/pulls/comments/103987262"},"html":{"href":"https://github.com/theforeman/foreman-docker/pull/184#discussion_r103987262"},"pull_request":{"href":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184"}}},"pull_request":{"url":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184","id":108404049,"html_url":"https://github.com/theforeman/foreman-docker/pull/184","diff_url":"https://github.com/theforeman/foreman-docker/pull/184.diff","patch_url":"https://github.com/theforeman/foreman-docker/pull/184.patch","issue_url":"https://api.github.com/repos/theforeman/foreman-docker/issues/184","number":184,"state":"open","locked":false,"title":"Fixes #14175 - Add support for Docker Registry v2","user":{"login":"bastilian","id":7757,"avatar_url":"https://avatars2.githubusercontent.com/u/7757?v=3","gravatar_id":"","url":"https://api.github.com/users/bastilian","html_url":"https://github.com/bastilian","followers_url":"https://api.github.com/users/bastilian/followers","following_url":"https://api.github.com/users/bastilian/following{/other_user}","gists_url":"https://api.github.com/users/bastilian/gists{/gist_id}","starred_url":"https://api.github.com/users/bastilian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastilian/subscriptions","organizations_url":"https://api.github.com/users/bastilian/orgs","repos_url":"https://api.github.com/users/bastilian/repos","events_url":"https://api.github.com/users/bastilian/events{/privacy}","received_events_url":"https://api.github.com/users/bastilian/received_events","type":"User","site_admin":false},"body":"This adds more functionality to RegisrtyApi and queries /v2/ endpoints in case requests to v1 of the registry API fail.\r\n\r\nFor now only public registries not requiring authentication are supported. \r\nThe change to support authenticated v2-only registries is a topic on it's own and i wanted to keep this out of here and first have general support for the endpoints\r\n\r\nGitLab implements the same authentication as Docker Hub using the same endpoints to get an OAuth token to use for authenticating requests. \r\n\r\nI still need to investigate further on the details to follow up with a PR, after #183 is fully merged, that adds the possibility to choose either OAuth-type authentication or plain basic HTTP auth as it is now with v1 endpoints that support it.\r\n","created_at":"2017-02-28T20:06:16Z","updated_at":"2017-03-02T17:55:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49ce886f2e1270fd6786c8490d7895c73296a73f","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184/commits","review_comments_url":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184/comments","review_comment_url":"https://api.github.com/repos/theforeman/foreman-docker/pulls/comments{/number}","comments_url":"https://api.github.com/repos/theforeman/foreman-docker/issues/184/comments","statuses_url":"https://api.github.com/repos/theforeman/foreman-docker/statuses/aa8de13a6153fee1728625c891da8e1f8000f371","head":{"label":"bastilian:fix/14175-PR","ref":"fix/14175-PR","sha":"aa8de13a6153fee1728625c891da8e1f8000f371","user":{"login":"bastilian","id":7757,"avatar_url":"https://avatars2.githubusercontent.com/u/7757?v=3","gravatar_id":"","url":"https://api.github.com/users/bastilian","html_url":"https://github.com/bastilian","followers_url":"https://api.github.com/users/bastilian/followers","following_url":"https://api.github.com/users/bastilian/following{/other_user}","gists_url":"https://api.github.com/users/bastilian/gists{/gist_id}","starred_url":"https://api.github.com/users/bastilian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastilian/subscriptions","organizations_url":"https://api.github.com/users/bastilian/orgs","repos_url":"https://api.github.com/users/bastilian/repos","events_url":"https://api.github.com/users/bastilian/events{/privacy}","received_events_url":"https://api.github.com/users/bastilian/received_events","type":"User","site_admin":false},"repo":{"id":81959667,"name":"foreman-docker","full_name":"bastilian/foreman-docker","owner":{"login":"bastilian","id":7757,"avatar_url":"https://avatars2.githubusercontent.com/u/7757?v=3","gravatar_id":"","url":"https://api.github.com/users/bastilian","html_url":"https://github.com/bastilian","followers_url":"https://api.github.com/users/bastilian/followers","following_url":"https://api.github.com/users/bastilian/following{/other_user}","gists_url":"https://api.github.com/users/bastilian/gists{/gist_id}","starred_url":"https://api.github.com/users/bastilian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bastilian/subscriptions","organizations_url":"https://api.github.com/users/bastilian/orgs","repos_url":"https://api.github.com/users/bastilian/repos","events_url":"https://api.github.com/users/bastilian/events{/privacy}","received_events_url":"https://api.github.com/users/bastilian/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bastilian/foreman-docker","description":"This plugin enables management of Docker containers and images in Foreman","fork":true,"url":"https://api.github.com/repos/bastilian/foreman-docker","forks_url":"https://api.github.com/repos/bastilian/foreman-docker/forks","keys_url":"https://api.github.com/repos/bastilian/foreman-docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bastilian/foreman-docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bastilian/foreman-docker/teams","hooks_url":"https://api.github.com/repos/bastilian/foreman-docker/hooks","issue_events_url":"https://api.github.com/repos/bastilian/foreman-docker/issues/events{/number}","events_url":"https://api.github.com/repos/bastilian/foreman-docker/events","assignees_url":"https://api.github.com/repos/bastilian/foreman-docker/assignees{/user}","branches_url":"https://api.github.com/repos/bastilian/foreman-docker/branches{/branch}","tags_url":"https://api.github.com/repos/bastilian/foreman-docker/tags","blobs_url":"https://api.github.com/repos/bastilian/foreman-docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bastilian/foreman-docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bastilian/foreman-docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/bastilian/foreman-docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bastilian/foreman-docker/statuses/{sha}","languages_url":"https://api.github.com/repos/bastilian/foreman-docker/languages","stargazers_url":"https://api.github.com/repos/bastilian/foreman-docker/stargazers","contributors_url":"https://api.github.com/repos/bastilian/foreman-docker/contributors","subscribers_url":"https://api.github.com/repos/bastilian/foreman-docker/subscribers","subscription_url":"https://api.github.com/repos/bastilian/foreman-docker/subscription","commits_url":"https://api.github.com/repos/bastilian/foreman-docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/bastilian/foreman-docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/bastilian/foreman-docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/bastilian/foreman-docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/bastilian/foreman-docker/contents/{+path}","compare_url":"https://api.github.com/repos/bastilian/foreman-docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bastilian/foreman-docker/merges","archive_url":"https://api.github.com/repos/bastilian/foreman-docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bastilian/foreman-docker/downloads","issues_url":"https://api.github.com/repos/bastilian/foreman-docker/issues{/number}","pulls_url":"https://api.github.com/repos/bastilian/foreman-docker/pulls{/number}","milestones_url":"https://api.github.com/repos/bastilian/foreman-docker/milestones{/number}","notifications_url":"https://api.github.com/repos/bastilian/foreman-docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bastilian/foreman-docker/labels{/name}","releases_url":"https://api.github.com/repos/bastilian/foreman-docker/releases{/id}","deployments_url":"https://api.github.com/repos/bastilian/foreman-docker/deployments","created_at":"2017-02-14T15:31:02Z","updated_at":"2017-02-14T15:31:04Z","pushed_at":"2017-02-28T19:24:36Z","git_url":"git://github.com/bastilian/foreman-docker.git","ssh_url":"git@github.com:bastilian/foreman-docker.git","clone_url":"https://github.com/bastilian/foreman-docker.git","svn_url":"https://github.com/bastilian/foreman-docker","homepage":"http://theforeman.org","size":570,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"theforeman:master","ref":"master","sha":"ae6e223e866147b69c7a5ab45f04c68e459a9711","user":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars1.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"repo":{"id":18068681,"name":"foreman-docker","full_name":"theforeman/foreman-docker","owner":{"login":"theforeman","id":1439844,"avatar_url":"https://avatars1.githubusercontent.com/u/1439844?v=3","gravatar_id":"","url":"https://api.github.com/users/theforeman","html_url":"https://github.com/theforeman","followers_url":"https://api.github.com/users/theforeman/followers","following_url":"https://api.github.com/users/theforeman/following{/other_user}","gists_url":"https://api.github.com/users/theforeman/gists{/gist_id}","starred_url":"https://api.github.com/users/theforeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/theforeman/subscriptions","organizations_url":"https://api.github.com/users/theforeman/orgs","repos_url":"https://api.github.com/users/theforeman/repos","events_url":"https://api.github.com/users/theforeman/events{/privacy}","received_events_url":"https://api.github.com/users/theforeman/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/theforeman/foreman-docker","description":"This plugin enables management of Docker containers and images in Foreman","fork":false,"url":"https://api.github.com/repos/theforeman/foreman-docker","forks_url":"https://api.github.com/repos/theforeman/foreman-docker/forks","keys_url":"https://api.github.com/repos/theforeman/foreman-docker/keys{/key_id}","collaborators_url":"https://api.github.com/repos/theforeman/foreman-docker/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/theforeman/foreman-docker/teams","hooks_url":"https://api.github.com/repos/theforeman/foreman-docker/hooks","issue_events_url":"https://api.github.com/repos/theforeman/foreman-docker/issues/events{/number}","events_url":"https://api.github.com/repos/theforeman/foreman-docker/events","assignees_url":"https://api.github.com/repos/theforeman/foreman-docker/assignees{/user}","branches_url":"https://api.github.com/repos/theforeman/foreman-docker/branches{/branch}","tags_url":"https://api.github.com/repos/theforeman/foreman-docker/tags","blobs_url":"https://api.github.com/repos/theforeman/foreman-docker/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/theforeman/foreman-docker/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/theforeman/foreman-docker/git/refs{/sha}","trees_url":"https://api.github.com/repos/theforeman/foreman-docker/git/trees{/sha}","statuses_url":"https://api.github.com/repos/theforeman/foreman-docker/statuses/{sha}","languages_url":"https://api.github.com/repos/theforeman/foreman-docker/languages","stargazers_url":"https://api.github.com/repos/theforeman/foreman-docker/stargazers","contributors_url":"https://api.github.com/repos/theforeman/foreman-docker/contributors","subscribers_url":"https://api.github.com/repos/theforeman/foreman-docker/subscribers","subscription_url":"https://api.github.com/repos/theforeman/foreman-docker/subscription","commits_url":"https://api.github.com/repos/theforeman/foreman-docker/commits{/sha}","git_commits_url":"https://api.github.com/repos/theforeman/foreman-docker/git/commits{/sha}","comments_url":"https://api.github.com/repos/theforeman/foreman-docker/comments{/number}","issue_comment_url":"https://api.github.com/repos/theforeman/foreman-docker/issues/comments{/number}","contents_url":"https://api.github.com/repos/theforeman/foreman-docker/contents/{+path}","compare_url":"https://api.github.com/repos/theforeman/foreman-docker/compare/{base}...{head}","merges_url":"https://api.github.com/repos/theforeman/foreman-docker/merges","archive_url":"https://api.github.com/repos/theforeman/foreman-docker/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/theforeman/foreman-docker/downloads","issues_url":"https://api.github.com/repos/theforeman/foreman-docker/issues{/number}","pulls_url":"https://api.github.com/repos/theforeman/foreman-docker/pulls{/number}","milestones_url":"https://api.github.com/repos/theforeman/foreman-docker/milestones{/number}","notifications_url":"https://api.github.com/repos/theforeman/foreman-docker/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/theforeman/foreman-docker/labels{/name}","releases_url":"https://api.github.com/repos/theforeman/foreman-docker/releases{/id}","deployments_url":"https://api.github.com/repos/theforeman/foreman-docker/deployments","created_at":"2014-03-24T16:08:03Z","updated_at":"2017-02-15T07:27:33Z","pushed_at":"2017-02-28T20:06:17Z","git_url":"git://github.com/theforeman/foreman-docker.git","ssh_url":"git@github.com:theforeman/foreman-docker.git","clone_url":"https://github.com/theforeman/foreman-docker.git","svn_url":"https://github.com/theforeman/foreman-docker","homepage":"http://theforeman.org","size":504,"stargazers_count":91,"watchers_count":91,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":45,"mirror_url":null,"open_issues_count":3,"forks":45,"open_issues":3,"watchers":91,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184"},"html":{"href":"https://github.com/theforeman/foreman-docker/pull/184"},"issue":{"href":"https://api.github.com/repos/theforeman/foreman-docker/issues/184"},"comments":{"href":"https://api.github.com/repos/theforeman/foreman-docker/issues/184/comments"},"review_comments":{"href":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184/comments"},"review_comment":{"href":"https://api.github.com/repos/theforeman/foreman-docker/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/theforeman/foreman-docker/pulls/184/commits"},"statuses":{"href":"https://api.github.com/repos/theforeman/foreman-docker/statuses/aa8de13a6153fee1728625c891da8e1f8000f371"}}}}
{"actor":{"display_login":"dLobatog"}}