{"action":"created","comment":{"url":"https://api.github.com/repos/matrix-org/go-neb/pulls/comments/73533981","id":73533981,"diff_hunk":"@@ -268,3 +277,64 @@ func updateRealmTxn(txn *sql.Tx, now time.Time, realm types.AuthRealm) error {\n \t)\n \treturn err\n }\n+\n+const insertAuthSessionSQL = `\n+INSERT INTO auth_sessions(\n+\trealm_id, user_id, session_json, time_added_ms, time_updated_ms\n+) VALUES ($1, $2, $3, $4, $5)\n+`\n+\n+func insertAuthSessionTxn(txn *sql.Tx, now time.Time, session types.AuthSession) error {\n+\tsessionJSON, err := json.Marshal(session)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\tt := now.UnixNano() / 1000000\n+\t_, err = txn.Exec(\n+\t\tinsertAuthSessionSQL,\n+\t\tsession.RealmID(), session.UserID(), sessionJSON, t, t,\n+\t)\n+\treturn err\n+}\n+\n+const selectAuthSessionSQL = `\n+SELECT realm_type, session_json FROM auth_sessions\n+\tJOIN auth_realms ON auth_sessions.realm_id = auth_realms.realm_id\n+\tWHERE auth_sessions.realm_id = $1 AND auth_sessions.user_id = $2\n+`\n+\n+func selectAuthSessionTxn(txn *sql.Tx, realmID, userID string) (types.AuthSession, error) {\n+\tvar realmType string\n+\tvar sessionJSON []byte\n+\trow := txn.QueryRow(selectAuthSessionSQL, realmID, userID)\n+\tif err := row.Scan(&realmType, &sessionJSON); err != nil {\n+\t\treturn nil, err\n+\t}\n+\trealm := types.CreateAuthRealm(realmID, realmType)\n+\tif realm == nil {\n+\t\treturn nil, fmt.Errorf(\"Cannot create realm of type %s\", realmType)\n+\t}","path":"src/github.com/matrix-org/go-neb/database/schema.go","position":57,"original_position":56,"commit_id":"11df0fe3c9f9e6cedeba6e5f5f8a0176ba2ff4c0","original_commit_id":"ed78b0cbcf954f2266c9320556ed80fa37bf10fc","user":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-08-04T14:36:20Z","updated_at":"2016-08-04T14:36:20Z","html_url":"https://github.com/matrix-org/go-neb/pull/8#discussion_r73533981","pull_request_url":"https://api.github.com/repos/matrix-org/go-neb/pulls/8","_links":{"self":{"href":"https://api.github.com/repos/matrix-org/go-neb/pulls/comments/73533981"},"html":{"href":"https://github.com/matrix-org/go-neb/pull/8#discussion_r73533981"},"pull_request":{"href":"https://api.github.com/repos/matrix-org/go-neb/pulls/8"}}},"pull_request":{"url":"https://api.github.com/repos/matrix-org/go-neb/pulls/8","id":80087006,"html_url":"https://github.com/matrix-org/go-neb/pull/8","diff_url":"https://github.com/matrix-org/go-neb/pull/8.diff","patch_url":"https://github.com/matrix-org/go-neb/pull/8.patch","issue_url":"https://api.github.com/repos/matrix-org/go-neb/issues/8","number":8,"state":"open","locked":false,"title":"Add concept of AuthSessions","user":{"login":"Kegsay","id":7190048,"avatar_url":"https://avatars.githubusercontent.com/u/7190048?v=3","gravatar_id":"","url":"https://api.github.com/users/Kegsay","html_url":"https://github.com/Kegsay","followers_url":"https://api.github.com/users/Kegsay/followers","following_url":"https://api.github.com/users/Kegsay/following{/other_user}","gists_url":"https://api.github.com/users/Kegsay/gists{/gist_id}","starred_url":"https://api.github.com/users/Kegsay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Kegsay/subscriptions","organizations_url":"https://api.github.com/users/Kegsay/orgs","repos_url":"https://api.github.com/users/Kegsay/repos","events_url":"https://api.github.com/users/Kegsay/events{/privacy}","received_events_url":"https://api.github.com/users/Kegsay/received_events","type":"User","site_admin":false},"body":"Auth sessions are a single auth process between a user and an auth realm. As\r\nsuch, they are keyed off the tuple of `(user_id, realm_id)`.\r\n\r\nOnly the realm which they belong to knows how to construct them, hence all\r\n\"load\" sections require an `AuthRealm` to be extracted first.\r\n\r\nCurrently I pass in a `json.RawMessage` rather than factory initialise and\r\nclobber public fields based on the JSON, we can always change that if need be\r\nlater down the line.\r\n\r\nOverall, this feels really nice (when starting to add in GH auth, everything I\r\nwanted was already there in the right place waiting for me).","created_at":"2016-08-04T14:22:31Z","updated_at":"2016-08-04T14:36:20Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3dcf0f8b4687d4775d6d1d1517cdd1e4dd13c93","assignee":{"login":"NegativeMjark","id":904009,"avatar_url":"https://avatars.githubusercontent.com/u/904009?v=3","gravatar_id":"","url":"https://api.github.com/users/NegativeMjark","html_url":"https://github.com/NegativeMjark","followers_url":"https://api.github.com/users/NegativeMjark/followers","following_url":"https://api.github.com/users/NegativeMjark/following{/other_user}","gists_url":"https://api.github.com/users/NegativeMjark/gists{/gist_id}","starred_url":"https://api.github.com/users/NegativeMjark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NegativeMjark/subscriptions","organizations_url":"https://api.github.com/users/NegativeMjark/orgs","repos_url":"https://api.github.com/users/NegativeMjark/repos","events_url":"https://api.github.com/users/NegativeMjark/events{/privacy}","received_events_url":"https://api.github.com/users/NegativeMjark/received_events","type":"User","site_admin":false},"assignees":[{"login":"NegativeMjark","id":904009,"avatar_url":"https://avatars.githubusercontent.com/u/904009?v=3","gravatar_id":"","url":"https://api.github.com/users/NegativeMjark","html_url":"https://github.com/NegativeMjark","followers_url":"https://api.github.com/users/NegativeMjark/followers","following_url":"https://api.github.com/users/NegativeMjark/following{/other_user}","gists_url":"https://api.github.com/users/NegativeMjark/gists{/gist_id}","starred_url":"https://api.github.com/users/NegativeMjark/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NegativeMjark/subscriptions","organizations_url":"https://api.github.com/users/NegativeMjark/orgs","repos_url":"https://api.github.com/users/NegativeMjark/repos","events_url":"https://api.github.com/users/NegativeMjark/events{/privacy}","received_events_url":"https://api.github.com/users/NegativeMjark/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/matrix-org/go-neb/pulls/8/commits","review_comments_url":"https://api.github.com/repos/matrix-org/go-neb/pulls/8/comments","review_comment_url":"https://api.github.com/repos/matrix-org/go-neb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/matrix-org/go-neb/issues/8/comments","statuses_url":"https://api.github.com/repos/matrix-org/go-neb/statuses/11df0fe3c9f9e6cedeba6e5f5f8a0176ba2ff4c0","head":{"label":"matrix-org:kegan/auth-session","ref":"kegan/auth-session","sha":"11df0fe3c9f9e6cedeba6e5f5f8a0176ba2ff4c0","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":64469341,"name":"go-neb","full_name":"matrix-org/go-neb","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/go-neb","description":"Extensible matrix bot written in Go","fork":false,"url":"https://api.github.com/repos/matrix-org/go-neb","forks_url":"https://api.github.com/repos/matrix-org/go-neb/forks","keys_url":"https://api.github.com/repos/matrix-org/go-neb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/go-neb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/go-neb/teams","hooks_url":"https://api.github.com/repos/matrix-org/go-neb/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/go-neb/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/go-neb/events","assignees_url":"https://api.github.com/repos/matrix-org/go-neb/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/go-neb/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/go-neb/tags","blobs_url":"https://api.github.com/repos/matrix-org/go-neb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/go-neb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/go-neb/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/go-neb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/go-neb/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/go-neb/languages","stargazers_url":"https://api.github.com/repos/matrix-org/go-neb/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/go-neb/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/go-neb/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/go-neb/subscription","commits_url":"https://api.github.com/repos/matrix-org/go-neb/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/go-neb/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/go-neb/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/go-neb/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/go-neb/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/go-neb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/go-neb/merges","archive_url":"https://api.github.com/repos/matrix-org/go-neb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/go-neb/downloads","issues_url":"https://api.github.com/repos/matrix-org/go-neb/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/go-neb/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/go-neb/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/go-neb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/go-neb/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/go-neb/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/go-neb/deployments","created_at":"2016-07-29T09:39:03Z","updated_at":"2016-08-03T12:55:32Z","pushed_at":"2016-08-04T14:35:56Z","git_url":"git://github.com/matrix-org/go-neb.git","ssh_url":"git@github.com:matrix-org/go-neb.git","clone_url":"https://github.com/matrix-org/go-neb.git","svn_url":"https://github.com/matrix-org/go-neb","homepage":null,"size":2185,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"matrix-org:master","ref":"master","sha":"5711bd0618382138019d25f2aad2c0df780ffef9","user":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"repo":{"id":64469341,"name":"go-neb","full_name":"matrix-org/go-neb","owner":{"login":"matrix-org","id":8418310,"avatar_url":"https://avatars.githubusercontent.com/u/8418310?v=3","gravatar_id":"","url":"https://api.github.com/users/matrix-org","html_url":"https://github.com/matrix-org","followers_url":"https://api.github.com/users/matrix-org/followers","following_url":"https://api.github.com/users/matrix-org/following{/other_user}","gists_url":"https://api.github.com/users/matrix-org/gists{/gist_id}","starred_url":"https://api.github.com/users/matrix-org/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/matrix-org/subscriptions","organizations_url":"https://api.github.com/users/matrix-org/orgs","repos_url":"https://api.github.com/users/matrix-org/repos","events_url":"https://api.github.com/users/matrix-org/events{/privacy}","received_events_url":"https://api.github.com/users/matrix-org/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/matrix-org/go-neb","description":"Extensible matrix bot written in Go","fork":false,"url":"https://api.github.com/repos/matrix-org/go-neb","forks_url":"https://api.github.com/repos/matrix-org/go-neb/forks","keys_url":"https://api.github.com/repos/matrix-org/go-neb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/matrix-org/go-neb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/matrix-org/go-neb/teams","hooks_url":"https://api.github.com/repos/matrix-org/go-neb/hooks","issue_events_url":"https://api.github.com/repos/matrix-org/go-neb/issues/events{/number}","events_url":"https://api.github.com/repos/matrix-org/go-neb/events","assignees_url":"https://api.github.com/repos/matrix-org/go-neb/assignees{/user}","branches_url":"https://api.github.com/repos/matrix-org/go-neb/branches{/branch}","tags_url":"https://api.github.com/repos/matrix-org/go-neb/tags","blobs_url":"https://api.github.com/repos/matrix-org/go-neb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/matrix-org/go-neb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/matrix-org/go-neb/git/refs{/sha}","trees_url":"https://api.github.com/repos/matrix-org/go-neb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/matrix-org/go-neb/statuses/{sha}","languages_url":"https://api.github.com/repos/matrix-org/go-neb/languages","stargazers_url":"https://api.github.com/repos/matrix-org/go-neb/stargazers","contributors_url":"https://api.github.com/repos/matrix-org/go-neb/contributors","subscribers_url":"https://api.github.com/repos/matrix-org/go-neb/subscribers","subscription_url":"https://api.github.com/repos/matrix-org/go-neb/subscription","commits_url":"https://api.github.com/repos/matrix-org/go-neb/commits{/sha}","git_commits_url":"https://api.github.com/repos/matrix-org/go-neb/git/commits{/sha}","comments_url":"https://api.github.com/repos/matrix-org/go-neb/comments{/number}","issue_comment_url":"https://api.github.com/repos/matrix-org/go-neb/issues/comments{/number}","contents_url":"https://api.github.com/repos/matrix-org/go-neb/contents/{+path}","compare_url":"https://api.github.com/repos/matrix-org/go-neb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/matrix-org/go-neb/merges","archive_url":"https://api.github.com/repos/matrix-org/go-neb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/matrix-org/go-neb/downloads","issues_url":"https://api.github.com/repos/matrix-org/go-neb/issues{/number}","pulls_url":"https://api.github.com/repos/matrix-org/go-neb/pulls{/number}","milestones_url":"https://api.github.com/repos/matrix-org/go-neb/milestones{/number}","notifications_url":"https://api.github.com/repos/matrix-org/go-neb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/matrix-org/go-neb/labels{/name}","releases_url":"https://api.github.com/repos/matrix-org/go-neb/releases{/id}","deployments_url":"https://api.github.com/repos/matrix-org/go-neb/deployments","created_at":"2016-07-29T09:39:03Z","updated_at":"2016-08-03T12:55:32Z","pushed_at":"2016-08-04T14:35:56Z","git_url":"git://github.com/matrix-org/go-neb.git","ssh_url":"git@github.com:matrix-org/go-neb.git","clone_url":"https://github.com/matrix-org/go-neb.git","svn_url":"https://github.com/matrix-org/go-neb","homepage":null,"size":2185,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/matrix-org/go-neb/pulls/8"},"html":{"href":"https://github.com/matrix-org/go-neb/pull/8"},"issue":{"href":"https://api.github.com/repos/matrix-org/go-neb/issues/8"},"comments":{"href":"https://api.github.com/repos/matrix-org/go-neb/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/matrix-org/go-neb/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/matrix-org/go-neb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/matrix-org/go-neb/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/matrix-org/go-neb/statuses/11df0fe3c9f9e6cedeba6e5f5f8a0176ba2ff4c0"}}}}
{"actor":{"display_login":"Kegsay"}}