{"action":"created","comment":{"url":"https://api.github.com/repos/santiment/sanbase2/pulls/comments/199708574","pull_request_review_id":133878095,"id":199708574,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDE5OTcwODU3NA==","diff_hunk":"@@ -0,0 +1,96 @@\n+defmodule Sanbase.Auth.Apikey do\n+  @moduledoc ~s\"\"\"\n+  Apikey combines and exposes in a transparent manner all the operations with the\n+  apikeys.\n+\n+  Let's get some of the terminology straight:\n+  - User Token (or simply token) is a random string saved plain text in the database.\n+  The UT *is not* not the apikey and the apikey cannot be generated by knowing only the UT\n+  - Apikey is generated by a secret key and a UT. The enduser gets this apikey that will\n+  be used in the communication. By an apikey we can retrieve the owner (user) of it.\n+  \"\"\"\n+\n+  require Logger\n+\n+  alias Sanbase.Auth.{\n+    Hmac,\n+    UserApikeyToken,\n+    User\n+  }\n+\n+  defguard is_non_empty_string(str) when is_binary(str) and str != \"\"\n+\n+  @doc ~s\"\"\"\n+  Returns the User struct connected to the given apikey.\n+  Split the apikey by \"_\" and use the first part as a user id. Look for all\n+  user tokens for that ID and check if the apikey is generated from any of the\n+  tokens\n+  \"\"\"\n+  @spec apikey_to_user(String.t()) :: {:ok, %User{}} | {:error, String.t()}\n+  def apikey_to_user(apikey) do\n+    with {:ok, {token, _rest}} <- Hmac.split_apikey(apikey),\n+         true <- UserApikeyToken.has_token?(token),","path":"lib/sanbase/auth/apikey/apikey.ex","position":32,"original_position":32,"commit_id":"b52bfd6f4f81a6e917fc098f8851f9acd2db8acf","original_commit_id":"b52bfd6f4f81a6e917fc098f8851f9acd2db8acf","user":{"login":"tspenov","id":122794,"node_id":"MDQ6VXNlcjEyMjc5NA==","avatar_url":"https://avatars0.githubusercontent.com/u/122794?v=4","gravatar_id":"","url":"https://api.github.com/users/tspenov","html_url":"https://github.com/tspenov","followers_url":"https://api.github.com/users/tspenov/followers","following_url":"https://api.github.com/users/tspenov/following{/other_user}","gists_url":"https://api.github.com/users/tspenov/gists{/gist_id}","starred_url":"https://api.github.com/users/tspenov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tspenov/subscriptions","organizations_url":"https://api.github.com/users/tspenov/orgs","repos_url":"https://api.github.com/users/tspenov/repos","events_url":"https://api.github.com/users/tspenov/events{/privacy}","received_events_url":"https://api.github.com/users/tspenov/received_events","type":"User","site_admin":false},"body":"I think on the next row `Hmac.apikey_valid?` is checking for `UserApikeyToken.has_token?` ?","created_at":"2018-07-03T07:33:02Z","updated_at":"2018-07-03T07:44:29Z","html_url":"https://github.com/santiment/sanbase2/pull/520#discussion_r199708574","pull_request_url":"https://api.github.com/repos/santiment/sanbase2/pulls/520","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/santiment/sanbase2/pulls/comments/199708574"},"html":{"href":"https://github.com/santiment/sanbase2/pull/520#discussion_r199708574"},"pull_request":{"href":"https://api.github.com/repos/santiment/sanbase2/pulls/520"}}},"pull_request":{"url":"https://api.github.com/repos/santiment/sanbase2/pulls/520","id":198034514,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk4MDM0NTE0","html_url":"https://github.com/santiment/sanbase2/pull/520","diff_url":"https://github.com/santiment/sanbase2/pull/520.diff","patch_url":"https://github.com/santiment/sanbase2/pull/520.patch","issue_url":"https://api.github.com/repos/santiment/sanbase2/issues/520","number":520,"state":"open","locked":false,"title":"Implement apikey","user":{"login":"IvanIvanoff","id":6518376,"node_id":"MDQ6VXNlcjY1MTgzNzY=","avatar_url":"https://avatars3.githubusercontent.com/u/6518376?v=4","gravatar_id":"","url":"https://api.github.com/users/IvanIvanoff","html_url":"https://github.com/IvanIvanoff","followers_url":"https://api.github.com/users/IvanIvanoff/followers","following_url":"https://api.github.com/users/IvanIvanoff/following{/other_user}","gists_url":"https://api.github.com/users/IvanIvanoff/gists{/gist_id}","starred_url":"https://api.github.com/users/IvanIvanoff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IvanIvanoff/subscriptions","organizations_url":"https://api.github.com/users/IvanIvanoff/orgs","repos_url":"https://api.github.com/users/IvanIvanoff/repos","events_url":"https://api.github.com/users/IvanIvanoff/events{/privacy}","received_events_url":"https://api.github.com/users/IvanIvanoff/received_events","type":"User","site_admin":false},"body":"#### Summary\r\n\r\nThat's how I would approach the apikey implementation given that we want to implement authentication and not authorization at this moment. Check the Hmac module doc for more info\r\n\r\nQuick guide to how it works:\r\n0. Have a secret key, that will be a k8s/tf secret.\r\n1. Generate an user token - random string and save it plain text in the db\r\n2. Generate the apikey as follows - `apikey = concat(user_token, \"_\" , hmac(secret_key, user_token))`\r\n\r\n<!-- (What does this pull request do in general terms?) -->\r\n\r\n[//]: # (#### Related PRs)\r\n<!-- (List of related PR in correct order) -->\r\n\r\n#### Additional deploy notes\r\nThe https://github.com/santiment/devops/pull/281 PR that adds the secret key should be merged first\r\n<!-- (Notes regarding deployment the contained body of work.) -->\r\n\r\n[//]: # (#### Screenshots)\r\n<!-- (if appropriate) -->\r\n","created_at":"2018-06-28T13:42:39Z","updated_at":"2018-07-03T07:44:29Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e8a45b4d4adbf040877c45662bed5be3252209b0","assignee":null,"assignees":[],"requested_reviewers":[{"login":"valo","id":47639,"node_id":"MDQ6VXNlcjQ3NjM5","avatar_url":"https://avatars2.githubusercontent.com/u/47639?v=4","gravatar_id":"","url":"https://api.github.com/users/valo","html_url":"https://github.com/valo","followers_url":"https://api.github.com/users/valo/followers","following_url":"https://api.github.com/users/valo/following{/other_user}","gists_url":"https://api.github.com/users/valo/gists{/gist_id}","starred_url":"https://api.github.com/users/valo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/valo/subscriptions","organizations_url":"https://api.github.com/users/valo/orgs","repos_url":"https://api.github.com/users/valo/repos","events_url":"https://api.github.com/users/valo/events{/privacy}","received_events_url":"https://api.github.com/users/valo/received_events","type":"User","site_admin":false},{"login":"LucoLe","id":5284935,"node_id":"MDQ6VXNlcjUyODQ5MzU=","avatar_url":"https://avatars3.githubusercontent.com/u/5284935?v=4","gravatar_id":"","url":"https://api.github.com/users/LucoLe","html_url":"https://github.com/LucoLe","followers_url":"https://api.github.com/users/LucoLe/followers","following_url":"https://api.github.com/users/LucoLe/following{/other_user}","gists_url":"https://api.github.com/users/LucoLe/gists{/gist_id}","starred_url":"https://api.github.com/users/LucoLe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/LucoLe/subscriptions","organizations_url":"https://api.github.com/users/LucoLe/orgs","repos_url":"https://api.github.com/users/LucoLe/repos","events_url":"https://api.github.com/users/LucoLe/events{/privacy}","received_events_url":"https://api.github.com/users/LucoLe/received_events","type":"User","site_admin":false}],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/santiment/sanbase2/pulls/520/commits","review_comments_url":"https://api.github.com/repos/santiment/sanbase2/pulls/520/comments","review_comment_url":"https://api.github.com/repos/santiment/sanbase2/pulls/comments{/number}","comments_url":"https://api.github.com/repos/santiment/sanbase2/issues/520/comments","statuses_url":"https://api.github.com/repos/santiment/sanbase2/statuses/b52bfd6f4f81a6e917fc098f8851f9acd2db8acf","head":{"label":"santiment:implement-apikey","ref":"implement-apikey","sha":"b52bfd6f4f81a6e917fc098f8851f9acd2db8acf","user":{"login":"santiment","id":24846876,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI0ODQ2ODc2","avatar_url":"https://avatars1.githubusercontent.com/u/24846876?v=4","gravatar_id":"","url":"https://api.github.com/users/santiment","html_url":"https://github.com/santiment","followers_url":"https://api.github.com/users/santiment/followers","following_url":"https://api.github.com/users/santiment/following{/other_user}","gists_url":"https://api.github.com/users/santiment/gists{/gist_id}","starred_url":"https://api.github.com/users/santiment/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santiment/subscriptions","organizations_url":"https://api.github.com/users/santiment/orgs","repos_url":"https://api.github.com/users/santiment/repos","events_url":"https://api.github.com/users/santiment/events{/privacy}","received_events_url":"https://api.github.com/users/santiment/received_events","type":"Organization","site_admin":false},"repo":{"id":106712767,"node_id":"MDEwOlJlcG9zaXRvcnkxMDY3MTI3Njc=","name":"sanbase2","full_name":"santiment/sanbase2","owner":{"login":"santiment","id":24846876,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI0ODQ2ODc2","avatar_url":"https://avatars1.githubusercontent.com/u/24846876?v=4","gravatar_id":"","url":"https://api.github.com/users/santiment","html_url":"https://github.com/santiment","followers_url":"https://api.github.com/users/santiment/followers","following_url":"https://api.github.com/users/santiment/following{/other_user}","gists_url":"https://api.github.com/users/santiment/gists{/gist_id}","starred_url":"https://api.github.com/users/santiment/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santiment/subscriptions","organizations_url":"https://api.github.com/users/santiment/orgs","repos_url":"https://api.github.com/users/santiment/repos","events_url":"https://api.github.com/users/santiment/events{/privacy}","received_events_url":"https://api.github.com/users/santiment/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/santiment/sanbase2","description":"The source code of the Sanbase application in Santiment LLC","fork":false,"url":"https://api.github.com/repos/santiment/sanbase2","forks_url":"https://api.github.com/repos/santiment/sanbase2/forks","keys_url":"https://api.github.com/repos/santiment/sanbase2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/santiment/sanbase2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/santiment/sanbase2/teams","hooks_url":"https://api.github.com/repos/santiment/sanbase2/hooks","issue_events_url":"https://api.github.com/repos/santiment/sanbase2/issues/events{/number}","events_url":"https://api.github.com/repos/santiment/sanbase2/events","assignees_url":"https://api.github.com/repos/santiment/sanbase2/assignees{/user}","branches_url":"https://api.github.com/repos/santiment/sanbase2/branches{/branch}","tags_url":"https://api.github.com/repos/santiment/sanbase2/tags","blobs_url":"https://api.github.com/repos/santiment/sanbase2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/santiment/sanbase2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/santiment/sanbase2/git/refs{/sha}","trees_url":"https://api.github.com/repos/santiment/sanbase2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/santiment/sanbase2/statuses/{sha}","languages_url":"https://api.github.com/repos/santiment/sanbase2/languages","stargazers_url":"https://api.github.com/repos/santiment/sanbase2/stargazers","contributors_url":"https://api.github.com/repos/santiment/sanbase2/contributors","subscribers_url":"https://api.github.com/repos/santiment/sanbase2/subscribers","subscription_url":"https://api.github.com/repos/santiment/sanbase2/subscription","commits_url":"https://api.github.com/repos/santiment/sanbase2/commits{/sha}","git_commits_url":"https://api.github.com/repos/santiment/sanbase2/git/commits{/sha}","comments_url":"https://api.github.com/repos/santiment/sanbase2/comments{/number}","issue_comment_url":"https://api.github.com/repos/santiment/sanbase2/issues/comments{/number}","contents_url":"https://api.github.com/repos/santiment/sanbase2/contents/{+path}","compare_url":"https://api.github.com/repos/santiment/sanbase2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/santiment/sanbase2/merges","archive_url":"https://api.github.com/repos/santiment/sanbase2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/santiment/sanbase2/downloads","issues_url":"https://api.github.com/repos/santiment/sanbase2/issues{/number}","pulls_url":"https://api.github.com/repos/santiment/sanbase2/pulls{/number}","milestones_url":"https://api.github.com/repos/santiment/sanbase2/milestones{/number}","notifications_url":"https://api.github.com/repos/santiment/sanbase2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/santiment/sanbase2/labels{/name}","releases_url":"https://api.github.com/repos/santiment/sanbase2/releases{/id}","deployments_url":"https://api.github.com/repos/santiment/sanbase2/deployments","created_at":"2017-10-12T15:42:11Z","updated_at":"2018-07-02T14:23:25Z","pushed_at":"2018-07-02T19:50:13Z","git_url":"git://github.com/santiment/sanbase2.git","ssh_url":"git@github.com:santiment/sanbase2.git","clone_url":"https://github.com/santiment/sanbase2.git","svn_url":"https://github.com/santiment/sanbase2","homepage":"https://sanbase-low.santiment.net","size":10169,"stargazers_count":28,"watchers_count":28,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":4,"open_issues":6,"watchers":28,"default_branch":"master"}},"base":{"label":"santiment:master","ref":"master","sha":"367aa4a2b0740fdcb84605c133dc6aba2be62903","user":{"login":"santiment","id":24846876,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI0ODQ2ODc2","avatar_url":"https://avatars1.githubusercontent.com/u/24846876?v=4","gravatar_id":"","url":"https://api.github.com/users/santiment","html_url":"https://github.com/santiment","followers_url":"https://api.github.com/users/santiment/followers","following_url":"https://api.github.com/users/santiment/following{/other_user}","gists_url":"https://api.github.com/users/santiment/gists{/gist_id}","starred_url":"https://api.github.com/users/santiment/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santiment/subscriptions","organizations_url":"https://api.github.com/users/santiment/orgs","repos_url":"https://api.github.com/users/santiment/repos","events_url":"https://api.github.com/users/santiment/events{/privacy}","received_events_url":"https://api.github.com/users/santiment/received_events","type":"Organization","site_admin":false},"repo":{"id":106712767,"node_id":"MDEwOlJlcG9zaXRvcnkxMDY3MTI3Njc=","name":"sanbase2","full_name":"santiment/sanbase2","owner":{"login":"santiment","id":24846876,"node_id":"MDEyOk9yZ2FuaXphdGlvbjI0ODQ2ODc2","avatar_url":"https://avatars1.githubusercontent.com/u/24846876?v=4","gravatar_id":"","url":"https://api.github.com/users/santiment","html_url":"https://github.com/santiment","followers_url":"https://api.github.com/users/santiment/followers","following_url":"https://api.github.com/users/santiment/following{/other_user}","gists_url":"https://api.github.com/users/santiment/gists{/gist_id}","starred_url":"https://api.github.com/users/santiment/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/santiment/subscriptions","organizations_url":"https://api.github.com/users/santiment/orgs","repos_url":"https://api.github.com/users/santiment/repos","events_url":"https://api.github.com/users/santiment/events{/privacy}","received_events_url":"https://api.github.com/users/santiment/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/santiment/sanbase2","description":"The source code of the Sanbase application in Santiment LLC","fork":false,"url":"https://api.github.com/repos/santiment/sanbase2","forks_url":"https://api.github.com/repos/santiment/sanbase2/forks","keys_url":"https://api.github.com/repos/santiment/sanbase2/keys{/key_id}","collaborators_url":"https://api.github.com/repos/santiment/sanbase2/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/santiment/sanbase2/teams","hooks_url":"https://api.github.com/repos/santiment/sanbase2/hooks","issue_events_url":"https://api.github.com/repos/santiment/sanbase2/issues/events{/number}","events_url":"https://api.github.com/repos/santiment/sanbase2/events","assignees_url":"https://api.github.com/repos/santiment/sanbase2/assignees{/user}","branches_url":"https://api.github.com/repos/santiment/sanbase2/branches{/branch}","tags_url":"https://api.github.com/repos/santiment/sanbase2/tags","blobs_url":"https://api.github.com/repos/santiment/sanbase2/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/santiment/sanbase2/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/santiment/sanbase2/git/refs{/sha}","trees_url":"https://api.github.com/repos/santiment/sanbase2/git/trees{/sha}","statuses_url":"https://api.github.com/repos/santiment/sanbase2/statuses/{sha}","languages_url":"https://api.github.com/repos/santiment/sanbase2/languages","stargazers_url":"https://api.github.com/repos/santiment/sanbase2/stargazers","contributors_url":"https://api.github.com/repos/santiment/sanbase2/contributors","subscribers_url":"https://api.github.com/repos/santiment/sanbase2/subscribers","subscription_url":"https://api.github.com/repos/santiment/sanbase2/subscription","commits_url":"https://api.github.com/repos/santiment/sanbase2/commits{/sha}","git_commits_url":"https://api.github.com/repos/santiment/sanbase2/git/commits{/sha}","comments_url":"https://api.github.com/repos/santiment/sanbase2/comments{/number}","issue_comment_url":"https://api.github.com/repos/santiment/sanbase2/issues/comments{/number}","contents_url":"https://api.github.com/repos/santiment/sanbase2/contents/{+path}","compare_url":"https://api.github.com/repos/santiment/sanbase2/compare/{base}...{head}","merges_url":"https://api.github.com/repos/santiment/sanbase2/merges","archive_url":"https://api.github.com/repos/santiment/sanbase2/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/santiment/sanbase2/downloads","issues_url":"https://api.github.com/repos/santiment/sanbase2/issues{/number}","pulls_url":"https://api.github.com/repos/santiment/sanbase2/pulls{/number}","milestones_url":"https://api.github.com/repos/santiment/sanbase2/milestones{/number}","notifications_url":"https://api.github.com/repos/santiment/sanbase2/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/santiment/sanbase2/labels{/name}","releases_url":"https://api.github.com/repos/santiment/sanbase2/releases{/id}","deployments_url":"https://api.github.com/repos/santiment/sanbase2/deployments","created_at":"2017-10-12T15:42:11Z","updated_at":"2018-07-02T14:23:25Z","pushed_at":"2018-07-02T19:50:13Z","git_url":"git://github.com/santiment/sanbase2.git","ssh_url":"git@github.com:santiment/sanbase2.git","clone_url":"https://github.com/santiment/sanbase2.git","svn_url":"https://github.com/santiment/sanbase2","homepage":"https://sanbase-low.santiment.net","size":10169,"stargazers_count":28,"watchers_count":28,"language":"Elixir","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":6,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":4,"open_issues":6,"watchers":28,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/santiment/sanbase2/pulls/520"},"html":{"href":"https://github.com/santiment/sanbase2/pull/520"},"issue":{"href":"https://api.github.com/repos/santiment/sanbase2/issues/520"},"comments":{"href":"https://api.github.com/repos/santiment/sanbase2/issues/520/comments"},"review_comments":{"href":"https://api.github.com/repos/santiment/sanbase2/pulls/520/comments"},"review_comment":{"href":"https://api.github.com/repos/santiment/sanbase2/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/santiment/sanbase2/pulls/520/commits"},"statuses":{"href":"https://api.github.com/repos/santiment/sanbase2/statuses/b52bfd6f4f81a6e917fc098f8851f9acd2db8acf"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tspenov"}}