{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/60664728","id":60664728,"diff_hunk":"@@ -0,0 +1,217 @@\n+package auth\n+\n+import (\n+\t\"errors\"\n+\t\"sync\"\n+\n+\t\"github.com/golang/glog\"\n+\n+\tkapi \"k8s.io/kubernetes/pkg/api\"\n+\t\"k8s.io/kubernetes/pkg/api/unversioned\"\n+\t\"k8s.io/kubernetes/pkg/auth/user\"\n+\t\"k8s.io/kubernetes/pkg/storage/etcd\"\n+\tutilruntime \"k8s.io/kubernetes/pkg/util/runtime\"\n+\t\"k8s.io/kubernetes/pkg/util/sets\"\n+\t\"k8s.io/kubernetes/pkg/watch\"\n+\n+\tprojectapi \"github.com/openshift/origin/pkg/project/api\"\n+\tprojectcache \"github.com/openshift/origin/pkg/project/cache\"\n+)\n+\n+type CacheWatcher interface {\n+\t// GroupMembershipChanged is called serialially for all changes for all watchers.  This method MUST NOT BLOCK.\n+\t// The serial nature makes reasoning about the code easy, but if you block in this method you will doom all watchers.\n+\tGroupMembershipChanged(namespaceName string, latestUsers, latestGroups, removedUsers, removedGroups, addedUsers, addedGroups sets.String)\n+}\n+\n+type WatchableCache interface {\n+\t// RemoveWatcher removes a watcher\n+\tRemoveWatcher(CacheWatcher)\n+\t// List returns the set of namespace names the user has access to view\n+\tList(userInfo user.Info) (*kapi.NamespaceList, error)\n+}\n+\n+// userProjectWatcher converts a native etcd watch to a watch.Interface.\n+type userProjectWatcher struct {\n+\tusername string\n+\tgroups   []string\n+\n+\t// cacheIncoming is a buffered channel used for notification to watcher.  If the buffer fills up,\n+\t// then the watcher will be removed and the connection will be broken.\n+\tcacheIncoming chan watch.Event\n+\t// cacheError is a cached channel that is put to serialially.  In theory, only one item will\n+\t// ever be placed on it.\n+\tcacheError chan error\n+\n+\t// outgoing is the unbuffered `ResultChan` use for the watch.  Backups of this channel will block\n+\t// the default `emit` call.  That's why cacheError is a buffered channel.\n+\toutgoing chan watch.Event\n+\t// userStop lets a user stop his watch.\n+\tuserStop chan struct{}\n+\n+\t// stopped prevents closing closed channels\n+\tstopped bool\n+\t// stopLock keeps parallel stops from doing crazy things\n+\tstopLock sync.Mutex\n+\n+\t// Injectable for testing. Send the event down the outgoing channel.\n+\temit func(watch.Event)\n+\n+\tprojectCache *projectcache.ProjectCache\n+\tauthCache    WatchableCache\n+\n+\tknownProjects sets.String\n+}\n+\n+var (\n+\twatchChannelHWM etcd.HighWaterMark\n+)\n+\n+func NewUserProjectWatcher(username string, groups []string, projectCache *projectcache.ProjectCache, authCache WatchableCache) *userProjectWatcher {\n+\tuserInfo := &user.DefaultInfo{Name: username, Groups: groups}\n+\tnamespaces, _ := authCache.List(userInfo)\n+\tknownProjects := sets.String{}\n+\tfor _, namespace := range namespaces.Items {\n+\t\tknownProjects.Insert(namespace.Name)\n+\t}\n+\n+\tw := &userProjectWatcher{\n+\t\tusername: username,\n+\t\tgroups:   groups,\n+\n+\t\tcacheIncoming: make(chan watch.Event, 1000),\n+\t\tcacheError:    make(chan error, 1),\n+\t\toutgoing:      make(chan watch.Event),\n+\t\tuserStop:      make(chan struct{}),\n+\n+\t\tprojectCache:  projectCache,\n+\t\tauthCache:     authCache,\n+\t\tknownProjects: knownProjects,\n+\t}\n+\tw.emit = func(e watch.Event) {\n+\t\tw.outgoing <- e\n+\t}\n+\treturn w\n+}\n+\n+func (w *userProjectWatcher) GroupMembershipChanged(namespaceName string, latestUsers, lastestGroups, removedUsers, removedGroups, addedUsers, addedGroups sets.String) {\n+\tremoved := removedUsers.Has(w.username) || removedGroups.HasAny(w.groups...)\n+\tadded := addedUsers.Has(w.username) || addedGroups.HasAny(w.groups...)","path":"pkg/project/auth/watch.go","position":99,"original_position":99,"commit_id":"1f0ca6079384d328a12ee4bf38c978fa0f7e9537","original_commit_id":"1f0ca6079384d328a12ee4bf38c978fa0f7e9537","user":{"login":"liggitt","id":980082,"avatar_url":"https://avatars.githubusercontent.com/u/980082?v=3","gravatar_id":"","url":"https://api.github.com/users/liggitt","html_url":"https://github.com/liggitt","followers_url":"https://api.github.com/users/liggitt/followers","following_url":"https://api.github.com/users/liggitt/following{/other_user}","gists_url":"https://api.github.com/users/liggitt/gists{/gist_id}","starred_url":"https://api.github.com/users/liggitt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liggitt/subscriptions","organizations_url":"https://api.github.com/users/liggitt/orgs","repos_url":"https://api.github.com/users/liggitt/repos","events_url":"https://api.github.com/users/liggitt/events{/privacy}","received_events_url":"https://api.github.com/users/liggitt/received_events","type":"User","site_admin":false},"body":"do you even need to track `added` (I'm not seeing it used apart from `hasAccess`)?","created_at":"2016-04-21T22:21:50Z","updated_at":"2016-04-21T22:21:50Z","html_url":"https://github.com/openshift/origin/pull/6828#discussion_r60664728","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/6828","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/60664728"},"html":{"href":"https://github.com/openshift/origin/pull/6828#discussion_r60664728"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/6828"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/6828","id":57134160,"html_url":"https://github.com/openshift/origin/pull/6828","diff_url":"https://github.com/openshift/origin/pull/6828.diff","patch_url":"https://github.com/openshift/origin/pull/6828.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/6828","number":6828,"state":"open","locked":false,"title":"make project cache watchable","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"body":"@jwforres @spadgett Let me know if this is useful to you before I make it fully operable.  This is **not** a normal watch, it is a watch of the project cache.  This means:\r\n\r\n 1. You will be notified when a user gains access to a project\r\n 1. You will be notified when a user loses access to a project\r\n 1. You will be notified when a project you have access to changes\r\n 3. You cannot start watching from a resource version.  You always start from \"now\".\r\n","created_at":"2016-01-25T21:35:17Z","updated_at":"2016-04-21T22:21:50Z","closed_at":null,"merged_at":null,"merge_commit_sha":"20fffd79a3423450949ab6fd9a3fcc65361c8986","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/6828/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/6828/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/6828/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/1f0ca6079384d328a12ee4bf38c978fa0f7e9537","head":{"label":"deads2k:watch-projects","ref":"watch-projects","sha":"1f0ca6079384d328a12ee4bf38c978fa0f7e9537","user":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"repo":{"id":24424126,"name":"origin","full_name":"deads2k/origin","owner":{"login":"deads2k","id":8225098,"avatar_url":"https://avatars.githubusercontent.com/u/8225098?v=3","gravatar_id":"","url":"https://api.github.com/users/deads2k","html_url":"https://github.com/deads2k","followers_url":"https://api.github.com/users/deads2k/followers","following_url":"https://api.github.com/users/deads2k/following{/other_user}","gists_url":"https://api.github.com/users/deads2k/gists{/gist_id}","starred_url":"https://api.github.com/users/deads2k/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deads2k/subscriptions","organizations_url":"https://api.github.com/users/deads2k/orgs","repos_url":"https://api.github.com/users/deads2k/repos","events_url":"https://api.github.com/users/deads2k/events{/privacy}","received_events_url":"https://api.github.com/users/deads2k/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/deads2k/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/deads2k/origin","forks_url":"https://api.github.com/repos/deads2k/origin/forks","keys_url":"https://api.github.com/repos/deads2k/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/deads2k/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/deads2k/origin/teams","hooks_url":"https://api.github.com/repos/deads2k/origin/hooks","issue_events_url":"https://api.github.com/repos/deads2k/origin/issues/events{/number}","events_url":"https://api.github.com/repos/deads2k/origin/events","assignees_url":"https://api.github.com/repos/deads2k/origin/assignees{/user}","branches_url":"https://api.github.com/repos/deads2k/origin/branches{/branch}","tags_url":"https://api.github.com/repos/deads2k/origin/tags","blobs_url":"https://api.github.com/repos/deads2k/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/deads2k/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/deads2k/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/deads2k/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/deads2k/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/deads2k/origin/languages","stargazers_url":"https://api.github.com/repos/deads2k/origin/stargazers","contributors_url":"https://api.github.com/repos/deads2k/origin/contributors","subscribers_url":"https://api.github.com/repos/deads2k/origin/subscribers","subscription_url":"https://api.github.com/repos/deads2k/origin/subscription","commits_url":"https://api.github.com/repos/deads2k/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/deads2k/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/deads2k/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/deads2k/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/deads2k/origin/contents/{+path}","compare_url":"https://api.github.com/repos/deads2k/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/deads2k/origin/merges","archive_url":"https://api.github.com/repos/deads2k/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/deads2k/origin/downloads","issues_url":"https://api.github.com/repos/deads2k/origin/issues{/number}","pulls_url":"https://api.github.com/repos/deads2k/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/deads2k/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/deads2k/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/deads2k/origin/labels{/name}","releases_url":"https://api.github.com/repos/deads2k/origin/releases{/id}","deployments_url":"https://api.github.com/repos/deads2k/origin/deployments","created_at":"2014-09-24T17:02:12Z","updated_at":"2016-01-11T17:58:27Z","pushed_at":"2016-04-21T20:26:16Z","git_url":"git://github.com/deads2k/origin.git","ssh_url":"git@github.com:deads2k/origin.git","clone_url":"https://github.com/deads2k/origin.git","svn_url":"https://github.com/deads2k/origin","homepage":"https://openshift.github.io","size":256031,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"openshift:master","ref":"master","sha":"de5b801e8d196384bae034405f28b7b6771bf6f0","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":22442668,"name":"origin","full_name":"openshift/origin","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/origin","description":"The Continuous Application Platform - build, deploy, and manage cloud-native and legacy applications on Kubernetes and Docker","fork":false,"url":"https://api.github.com/repos/openshift/origin","forks_url":"https://api.github.com/repos/openshift/origin/forks","keys_url":"https://api.github.com/repos/openshift/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/origin/teams","hooks_url":"https://api.github.com/repos/openshift/origin/hooks","issue_events_url":"https://api.github.com/repos/openshift/origin/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/origin/events","assignees_url":"https://api.github.com/repos/openshift/origin/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/origin/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/origin/tags","blobs_url":"https://api.github.com/repos/openshift/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/origin/languages","stargazers_url":"https://api.github.com/repos/openshift/origin/stargazers","contributors_url":"https://api.github.com/repos/openshift/origin/contributors","subscribers_url":"https://api.github.com/repos/openshift/origin/subscribers","subscription_url":"https://api.github.com/repos/openshift/origin/subscription","commits_url":"https://api.github.com/repos/openshift/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/origin/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/origin/merges","archive_url":"https://api.github.com/repos/openshift/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/origin/downloads","issues_url":"https://api.github.com/repos/openshift/origin/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/origin/labels{/name}","releases_url":"https://api.github.com/repos/openshift/origin/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/origin/deployments","created_at":"2014-07-30T20:04:05Z","updated_at":"2016-04-21T19:37:44Z","pushed_at":"2016-04-21T22:13:08Z","git_url":"git://github.com/openshift/origin.git","ssh_url":"git@github.com:openshift/origin.git","clone_url":"https://github.com/openshift/origin.git","svn_url":"https://github.com/openshift/origin","homepage":"http://www.openshift.org","size":331387,"stargazers_count":1240,"watchers_count":1240,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":750,"mirror_url":null,"open_issues_count":1032,"forks":750,"open_issues":1032,"watchers":1240,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/6828"},"html":{"href":"https://github.com/openshift/origin/pull/6828"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/6828"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/6828/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/6828/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/6828/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/1f0ca6079384d328a12ee4bf38c978fa0f7e9537"}}}}