{"action":"created","comment":{"url":"https://api.github.com/repos/mozilla/ssh_scan/pulls/comments/93637489","pull_request_review_id":14169216,"id":93637489,"diff_hunk":"@@ -0,0 +1,60 @@\n+require 'sqlite3'\n+\n+module   SSHScan\n+  module Database\n+    class SQLite\n+      def initialize(opts = {})\n+        database_name = opts[\"database\"][\"name\"]\n+        if File.exist?(database_name)\n+          @db = ::SQLite3::Database.open(database_name)\n+        else\n+          @db = ::SQLite3::Database.new(database_name)\n+          create_schema\n+        end\n+      end\n+\n+      def self.from_config_file(file_string)\n+        opts = YAML.load_file(file_string)\n+        SSHScan::Database::SQLite.new(opts)\n+      end\n+\n+      def create_schema\n+        @db.execute <<-SQL\n+          create table api_schema (\n+            uuid varchar(100),\n+            result json,\n+            worker_id varchar(100),\n+            scanned_on datetime\n+          );\n+        SQL\n+      end\n+\n+      def add_scan(worker_id, uuid, result)\n+        @db.execute \"insert into api_schema values ( ? , ? , ? , ? )\",\n+                    [uuid, result.to_json, worker_id, Time.now.to_s]\n+      end\n+\n+      def delete_scan(uuid)\n+        @db.execute(\n+          \"delete from api_schema where uuid = ?\",\n+          uuid\n+        )\n+      end\n+\n+      def delete_all\n+        @db.execute(\"delete from api_schema\")\n+      end\n+\n+      def find_scan_result(uuid)\n+        scans = []\n+        @db.execute(\n+          \"select * from api_schema where uuid like ( ? )\",\n+          uuid\n+        ) do |row|\n+          scans << row[1]","path":"lib/ssh_scan/database/sqlite_db.rb","position":54,"original_position":54,"commit_id":"bb5c32e62578a4764e42cfa44cf6591bb3df9fce","original_commit_id":"bb5c32e62578a4764e42cfa44cf6591bb3df9fce","user":{"login":"claudijd","id":794283,"avatar_url":"https://avatars.githubusercontent.com/u/794283?v=3","gravatar_id":"","url":"https://api.github.com/users/claudijd","html_url":"https://github.com/claudijd","followers_url":"https://api.github.com/users/claudijd/followers","following_url":"https://api.github.com/users/claudijd/following{/other_user}","gists_url":"https://api.github.com/users/claudijd/gists{/gist_id}","starred_url":"https://api.github.com/users/claudijd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/claudijd/subscriptions","organizations_url":"https://api.github.com/users/claudijd/orgs","repos_url":"https://api.github.com/users/claudijd/repos","events_url":"https://api.github.com/users/claudijd/events{/privacy}","received_events_url":"https://api.github.com/users/claudijd/received_events","type":"User","site_admin":false},"body":"For SQLite abstraction, we return all scans, but for Mongo we return the first scan.  I think we should pick a common behavior and make it consistent between the two.","created_at":"2016-12-22T15:00:55Z","updated_at":"2016-12-22T15:00:55Z","html_url":"https://github.com/mozilla/ssh_scan/pull/291#discussion_r93637489","pull_request_url":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291","_links":{"self":{"href":"https://api.github.com/repos/mozilla/ssh_scan/pulls/comments/93637489"},"html":{"href":"https://github.com/mozilla/ssh_scan/pull/291#discussion_r93637489"},"pull_request":{"href":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291"}}},"pull_request":{"url":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291","id":97812535,"html_url":"https://github.com/mozilla/ssh_scan/pull/291","diff_url":"https://github.com/mozilla/ssh_scan/pull/291.diff","patch_url":"https://github.com/mozilla/ssh_scan/pull/291.patch","issue_url":"https://api.github.com/repos/mozilla/ssh_scan/issues/291","number":291,"state":"open","locked":false,"title":"Add MongoDb as a default database","user":{"login":"royalharsh","id":3523733,"avatar_url":"https://avatars.githubusercontent.com/u/3523733?v=3","gravatar_id":"","url":"https://api.github.com/users/royalharsh","html_url":"https://github.com/royalharsh","followers_url":"https://api.github.com/users/royalharsh/followers","following_url":"https://api.github.com/users/royalharsh/following{/other_user}","gists_url":"https://api.github.com/users/royalharsh/gists{/gist_id}","starred_url":"https://api.github.com/users/royalharsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/royalharsh/subscriptions","organizations_url":"https://api.github.com/users/royalharsh/orgs","repos_url":"https://api.github.com/users/royalharsh/repos","events_url":"https://api.github.com/users/royalharsh/events{/privacy}","received_events_url":"https://api.github.com/users/royalharsh/received_events","type":"User","site_admin":false},"body":"https://github.com/mozilla/ssh_scan/issues/287 \r\nNow, we have to use `save=true` to save the results in the database and we can select database type by specifying `db=sqlite`, otherwise, it defaults to `db=mongodb`.\r\n\r\nFor example,\r\n```bash\r\ncurl -k -X POST https://127.0.0.1:8000/api/v1/scan -d \"target=ssh.mozilla.com&db=sqlite&save=true\"\r\n```","created_at":"2016-12-13T18:54:41Z","updated_at":"2016-12-22T15:00:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7385204c5201fd295c75f538e18ed20a7d87570b","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291/commits","review_comments_url":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291/comments","review_comment_url":"https://api.github.com/repos/mozilla/ssh_scan/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mozilla/ssh_scan/issues/291/comments","statuses_url":"https://api.github.com/repos/mozilla/ssh_scan/statuses/bb5c32e62578a4764e42cfa44cf6591bb3df9fce","head":{"label":"royalharsh:mongo_db","ref":"mongo_db","sha":"bb5c32e62578a4764e42cfa44cf6591bb3df9fce","user":{"login":"royalharsh","id":3523733,"avatar_url":"https://avatars.githubusercontent.com/u/3523733?v=3","gravatar_id":"","url":"https://api.github.com/users/royalharsh","html_url":"https://github.com/royalharsh","followers_url":"https://api.github.com/users/royalharsh/followers","following_url":"https://api.github.com/users/royalharsh/following{/other_user}","gists_url":"https://api.github.com/users/royalharsh/gists{/gist_id}","starred_url":"https://api.github.com/users/royalharsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/royalharsh/subscriptions","organizations_url":"https://api.github.com/users/royalharsh/orgs","repos_url":"https://api.github.com/users/royalharsh/repos","events_url":"https://api.github.com/users/royalharsh/events{/privacy}","received_events_url":"https://api.github.com/users/royalharsh/received_events","type":"User","site_admin":false},"repo":{"id":65627205,"name":"ssh_scan","full_name":"royalharsh/ssh_scan","owner":{"login":"royalharsh","id":3523733,"avatar_url":"https://avatars.githubusercontent.com/u/3523733?v=3","gravatar_id":"","url":"https://api.github.com/users/royalharsh","html_url":"https://github.com/royalharsh","followers_url":"https://api.github.com/users/royalharsh/followers","following_url":"https://api.github.com/users/royalharsh/following{/other_user}","gists_url":"https://api.github.com/users/royalharsh/gists{/gist_id}","starred_url":"https://api.github.com/users/royalharsh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/royalharsh/subscriptions","organizations_url":"https://api.github.com/users/royalharsh/orgs","repos_url":"https://api.github.com/users/royalharsh/repos","events_url":"https://api.github.com/users/royalharsh/events{/privacy}","received_events_url":"https://api.github.com/users/royalharsh/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/royalharsh/ssh_scan","description":"A prototype SSH configuration and policy scanner","fork":true,"url":"https://api.github.com/repos/royalharsh/ssh_scan","forks_url":"https://api.github.com/repos/royalharsh/ssh_scan/forks","keys_url":"https://api.github.com/repos/royalharsh/ssh_scan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/royalharsh/ssh_scan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/royalharsh/ssh_scan/teams","hooks_url":"https://api.github.com/repos/royalharsh/ssh_scan/hooks","issue_events_url":"https://api.github.com/repos/royalharsh/ssh_scan/issues/events{/number}","events_url":"https://api.github.com/repos/royalharsh/ssh_scan/events","assignees_url":"https://api.github.com/repos/royalharsh/ssh_scan/assignees{/user}","branches_url":"https://api.github.com/repos/royalharsh/ssh_scan/branches{/branch}","tags_url":"https://api.github.com/repos/royalharsh/ssh_scan/tags","blobs_url":"https://api.github.com/repos/royalharsh/ssh_scan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/royalharsh/ssh_scan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/royalharsh/ssh_scan/git/refs{/sha}","trees_url":"https://api.github.com/repos/royalharsh/ssh_scan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/royalharsh/ssh_scan/statuses/{sha}","languages_url":"https://api.github.com/repos/royalharsh/ssh_scan/languages","stargazers_url":"https://api.github.com/repos/royalharsh/ssh_scan/stargazers","contributors_url":"https://api.github.com/repos/royalharsh/ssh_scan/contributors","subscribers_url":"https://api.github.com/repos/royalharsh/ssh_scan/subscribers","subscription_url":"https://api.github.com/repos/royalharsh/ssh_scan/subscription","commits_url":"https://api.github.com/repos/royalharsh/ssh_scan/commits{/sha}","git_commits_url":"https://api.github.com/repos/royalharsh/ssh_scan/git/commits{/sha}","comments_url":"https://api.github.com/repos/royalharsh/ssh_scan/comments{/number}","issue_comment_url":"https://api.github.com/repos/royalharsh/ssh_scan/issues/comments{/number}","contents_url":"https://api.github.com/repos/royalharsh/ssh_scan/contents/{+path}","compare_url":"https://api.github.com/repos/royalharsh/ssh_scan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/royalharsh/ssh_scan/merges","archive_url":"https://api.github.com/repos/royalharsh/ssh_scan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/royalharsh/ssh_scan/downloads","issues_url":"https://api.github.com/repos/royalharsh/ssh_scan/issues{/number}","pulls_url":"https://api.github.com/repos/royalharsh/ssh_scan/pulls{/number}","milestones_url":"https://api.github.com/repos/royalharsh/ssh_scan/milestones{/number}","notifications_url":"https://api.github.com/repos/royalharsh/ssh_scan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/royalharsh/ssh_scan/labels{/name}","releases_url":"https://api.github.com/repos/royalharsh/ssh_scan/releases{/id}","deployments_url":"https://api.github.com/repos/royalharsh/ssh_scan/deployments","created_at":"2016-08-13T16:48:58Z","updated_at":"2016-08-13T16:48:59Z","pushed_at":"2016-12-21T11:44:50Z","git_url":"git://github.com/royalharsh/ssh_scan.git","ssh_url":"git@github.com:royalharsh/ssh_scan.git","clone_url":"https://github.com/royalharsh/ssh_scan.git","svn_url":"https://github.com/royalharsh/ssh_scan","homepage":"","size":390,"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":"mozilla:master","ref":"master","sha":"919d99271f10aa2144498c98d5ef622b8aec9969","user":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"repo":{"id":50693175,"name":"ssh_scan","full_name":"mozilla/ssh_scan","owner":{"login":"mozilla","id":131524,"avatar_url":"https://avatars.githubusercontent.com/u/131524?v=3","gravatar_id":"","url":"https://api.github.com/users/mozilla","html_url":"https://github.com/mozilla","followers_url":"https://api.github.com/users/mozilla/followers","following_url":"https://api.github.com/users/mozilla/following{/other_user}","gists_url":"https://api.github.com/users/mozilla/gists{/gist_id}","starred_url":"https://api.github.com/users/mozilla/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mozilla/subscriptions","organizations_url":"https://api.github.com/users/mozilla/orgs","repos_url":"https://api.github.com/users/mozilla/repos","events_url":"https://api.github.com/users/mozilla/events{/privacy}","received_events_url":"https://api.github.com/users/mozilla/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mozilla/ssh_scan","description":"A prototype SSH configuration and policy scanner (Blog: https://mozilla.github.io/ssh_scan/)","fork":false,"url":"https://api.github.com/repos/mozilla/ssh_scan","forks_url":"https://api.github.com/repos/mozilla/ssh_scan/forks","keys_url":"https://api.github.com/repos/mozilla/ssh_scan/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mozilla/ssh_scan/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mozilla/ssh_scan/teams","hooks_url":"https://api.github.com/repos/mozilla/ssh_scan/hooks","issue_events_url":"https://api.github.com/repos/mozilla/ssh_scan/issues/events{/number}","events_url":"https://api.github.com/repos/mozilla/ssh_scan/events","assignees_url":"https://api.github.com/repos/mozilla/ssh_scan/assignees{/user}","branches_url":"https://api.github.com/repos/mozilla/ssh_scan/branches{/branch}","tags_url":"https://api.github.com/repos/mozilla/ssh_scan/tags","blobs_url":"https://api.github.com/repos/mozilla/ssh_scan/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mozilla/ssh_scan/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mozilla/ssh_scan/git/refs{/sha}","trees_url":"https://api.github.com/repos/mozilla/ssh_scan/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mozilla/ssh_scan/statuses/{sha}","languages_url":"https://api.github.com/repos/mozilla/ssh_scan/languages","stargazers_url":"https://api.github.com/repos/mozilla/ssh_scan/stargazers","contributors_url":"https://api.github.com/repos/mozilla/ssh_scan/contributors","subscribers_url":"https://api.github.com/repos/mozilla/ssh_scan/subscribers","subscription_url":"https://api.github.com/repos/mozilla/ssh_scan/subscription","commits_url":"https://api.github.com/repos/mozilla/ssh_scan/commits{/sha}","git_commits_url":"https://api.github.com/repos/mozilla/ssh_scan/git/commits{/sha}","comments_url":"https://api.github.com/repos/mozilla/ssh_scan/comments{/number}","issue_comment_url":"https://api.github.com/repos/mozilla/ssh_scan/issues/comments{/number}","contents_url":"https://api.github.com/repos/mozilla/ssh_scan/contents/{+path}","compare_url":"https://api.github.com/repos/mozilla/ssh_scan/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mozilla/ssh_scan/merges","archive_url":"https://api.github.com/repos/mozilla/ssh_scan/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mozilla/ssh_scan/downloads","issues_url":"https://api.github.com/repos/mozilla/ssh_scan/issues{/number}","pulls_url":"https://api.github.com/repos/mozilla/ssh_scan/pulls{/number}","milestones_url":"https://api.github.com/repos/mozilla/ssh_scan/milestones{/number}","notifications_url":"https://api.github.com/repos/mozilla/ssh_scan/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mozilla/ssh_scan/labels{/name}","releases_url":"https://api.github.com/repos/mozilla/ssh_scan/releases{/id}","deployments_url":"https://api.github.com/repos/mozilla/ssh_scan/deployments","created_at":"2016-01-29T21:39:15Z","updated_at":"2016-12-19T23:12:35Z","pushed_at":"2016-12-21T21:30:11Z","git_url":"git://github.com/mozilla/ssh_scan.git","ssh_url":"git@github.com:mozilla/ssh_scan.git","clone_url":"https://github.com/mozilla/ssh_scan.git","svn_url":"https://github.com/mozilla/ssh_scan","homepage":"","size":3343,"stargazers_count":101,"watchers_count":101,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":19,"mirror_url":null,"open_issues_count":30,"forks":19,"open_issues":30,"watchers":101,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291"},"html":{"href":"https://github.com/mozilla/ssh_scan/pull/291"},"issue":{"href":"https://api.github.com/repos/mozilla/ssh_scan/issues/291"},"comments":{"href":"https://api.github.com/repos/mozilla/ssh_scan/issues/291/comments"},"review_comments":{"href":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291/comments"},"review_comment":{"href":"https://api.github.com/repos/mozilla/ssh_scan/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mozilla/ssh_scan/pulls/291/commits"},"statuses":{"href":"https://api.github.com/repos/mozilla/ssh_scan/statuses/bb5c32e62578a4764e42cfa44cf6591bb3df9fce"}}}}
{"actor":{"display_login":"claudijd"}}