{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/28740169","id":28740169,"diff_hunk":"@@ -4,96 +4,104 @@ import (\n \t\"fmt\"\n \n \tkapi \"github.com/GoogleCloudPlatform/kubernetes/pkg/api\"\n-\tkerrors \"github.com/GoogleCloudPlatform/kubernetes/pkg/api/errors\"\n \t\"github.com/GoogleCloudPlatform/kubernetes/pkg/fields\"\n \t\"github.com/GoogleCloudPlatform/kubernetes/pkg/labels\"\n+\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/registry/generic\"\n \t\"github.com/GoogleCloudPlatform/kubernetes/pkg/runtime\"\n \t\"github.com/GoogleCloudPlatform/kubernetes/pkg/util\"\n-\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/watch\"\n+\t\"github.com/GoogleCloudPlatform/kubernetes/pkg/util/fielderrors\"\n \n \tauthorizationapi \"github.com/openshift/origin/pkg/authorization/api\"\n \t\"github.com/openshift/origin/pkg/authorization/api/validation\"\n )\n \n-// REST implements the RESTStorage interface in terms of an Registry.\n-type REST struct {\n-\tregistry Registry\n+// strategy implements behavior for nodes\n+type strategy struct {\n+\truntime.ObjectTyper\n }\n \n-// NewREST creates a new REST for policyBindings.\n-func NewREST(registry Registry) *REST {\n-\treturn &REST{registry}\n+// Strategy is the default logic that applies when creating and updating PolicyBinding objects.\n+var Strategy = strategy{kapi.Scheme}\n+\n+// NamespaceScoped is true for policybindings.\n+func (strategy) NamespaceScoped() bool {\n+\treturn true\n }\n \n-// New creates a new PolicyBinding object\n-func (r *REST) New() runtime.Object {\n-\treturn &authorizationapi.PolicyBinding{}\n+// AllowCreateOnUpdate is false for policybindings.\n+func (strategy) AllowCreateOnUpdate() bool {\n+\treturn false\n }\n \n-func (r *REST) NewList() runtime.Object {\n-\treturn &authorizationapi.PolicyBindingList{}\n+func (strategy) GenerateName(base string) string {\n+\treturn base\n }\n \n-// List obtains a list of PolicyBindings that match selector.\n-func (r *REST) List(ctx kapi.Context, label labels.Selector, field fields.Selector) (runtime.Object, error) {\n-\tpolicyBindings, err := r.registry.ListPolicyBindings(ctx, label, field)\n-\tif err != nil {\n-\t\treturn nil, err\n-\t}\n-\treturn policyBindings, err\n+// PrepareForCreate clears fields that are not allowed to be set by end users on creation.\n+func (strategy) PrepareForCreate(obj runtime.Object) {\n+\tbinding := obj.(*authorizationapi.PolicyBinding)\n \n+\tbinding.Name = binding.PolicyRef.Namespace\n+\tscrubBindingRefs(binding)\n }\n \n-// Get obtains the policyBinding specified by its id.\n-func (r *REST) Get(ctx kapi.Context, id string) (runtime.Object, error) {\n-\tpolicyBinding, err := r.registry.GetPolicyBinding(ctx, id)\n-\tif err != nil {\n-\t\treturn nil, err\n+func scrubBindingRefs(binding *authorizationapi.PolicyBinding) {\n+\tbinding.PolicyRef = kapi.ObjectReference{Namespace: binding.PolicyRef.Namespace}\n+\n+\tfor roleBindingKey, roleBinding := range binding.RoleBindings {\n+\t\troleBinding.RoleRef = kapi.ObjectReference{Namespace: binding.PolicyRef.Namespace, Name: roleBinding.RoleRef.Name}\n+\t\tbinding.RoleBindings[roleBindingKey] = roleBinding\n \t}\n-\treturn policyBinding, err\n }\n \n-// Delete asynchronously deletes the PolicyBinding specified by its id.\n-func (r *REST) Delete(ctx kapi.Context, id string) (runtime.Object, error) {\n-\treturn &kapi.Status{Status: kapi.StatusSuccess}, r.registry.DeletePolicyBinding(ctx, id)\n+// PrepareForUpdate clears fields that are not allowed to be set by end users on update.\n+func (strategy) PrepareForUpdate(obj, old runtime.Object) {\n+\tbinding := obj.(*authorizationapi.PolicyBinding)\n+\n+\tscrubBindingRefs(binding)\n }\n \n-// Create registers a given new PolicyBinding instance to r.registry.\n-func (r *REST) Create(ctx kapi.Context, obj runtime.Object) (runtime.Object, error) {\n-\tpolicyBinding, ok := obj.(*authorizationapi.PolicyBinding)\n-\tif !ok {\n-\t\treturn nil, fmt.Errorf(\"not an policyBinding: %#v\", obj)\n-\t}\n-\tif !kapi.ValidNamespace(ctx, &policyBinding.ObjectMeta) {\n-\t\treturn nil, kerrors.NewConflict(\"policyBinding\", policyBinding.Namespace, fmt.Errorf(\"PolicyBinding.Namespace does not match the provided context\"))\n-\t}\n+// Validate validates a new policyBinding.\n+func (strategy) Validate(ctx kapi.Context, obj runtime.Object) fielderrors.ValidationErrorList {\n+\treturn validation.ValidatePolicyBinding(obj.(*authorizationapi.PolicyBinding))\n+}\n \n-\tkapi.FillObjectMetaSystemFields(ctx, &policyBinding.ObjectMeta)\n-\tpolicyBinding.Name = policyBinding.PolicyRef.Namespace\n-\tpolicyBinding.LastModified = util.Now()\n-\tif errs := validation.ValidatePolicyBinding(policyBinding); len(errs) > 0 {\n-\t\treturn nil, kerrors.NewInvalid(\"policyBinding\", policyBinding.Name, errs)\n-\t}\n+// ValidateUpdate is the default update validation for an end user.\n+func (strategy) ValidateUpdate(ctx kapi.Context, obj, old runtime.Object) fielderrors.ValidationErrorList {\n+\treturn validation.ValidatePolicyBindingUpdate(old.(*authorizationapi.PolicyBinding), obj.(*authorizationapi.PolicyBinding))\n+}\n \n-\tif err := r.registry.CreatePolicyBinding(ctx, policyBinding); err != nil {\n-\t\treturn nil, err\n+// Matcher returns a generic matcher for a given label and field selector.\n+func Matcher(label labels.Selector, field fields.Selector) generic.Matcher {\n+\treturn &generic.SelectionPredicate{\n+\t\tLabel: label,\n+\t\tField: field,\n+\t\tGetAttrs: func(obj runtime.Object) (labels.Set, fields.Set, error) {\n+\t\t\tpolicyBinding, ok := obj.(*authorizationapi.PolicyBinding)\n+\t\t\tif !ok {\n+\t\t\t\treturn nil, nil, fmt.Errorf(\"not a policyBinding\")\n+\t\t\t}\n+\t\t\treturn labels.Set(policyBinding.ObjectMeta.Labels), SelectableFields(policyBinding), nil\n+\t\t},\n \t}\n-\treturn r.Get(ctx, policyBinding.Name)\n }\n \n-// Watch begins watching for new, changed, or deleted PolicyBindings.\n-func (r *REST) Watch(ctx kapi.Context, label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error) {\n-\treturn r.registry.WatchPolicyBindings(ctx, label, field, resourceVersion)\n+// SelectableFields returns a label set that represents the object\n+func SelectableFields(policyBinding *authorizationapi.PolicyBinding) fields.Set {\n+\treturn fields.Set{\n+\t\t\"name\":                policyBinding.Name,\n+\t\t\"policyRef.Namespace\": policyBinding.PolicyRef.Namespace,","path":"pkg/authorization/registry/policybinding/rest.go","position":140,"original_position":140,"commit_id":"bd9b971f70c109bd9f01030ad20fdab8928d4a57","original_commit_id":"bd9b971f70c109bd9f01030ad20fdab8928d4a57","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":"lowercase `namespace`?","created_at":"2015-04-20T23:58:23Z","updated_at":"2015-04-20T23:58:23Z","html_url":"https://github.com/openshift/origin/pull/1754#discussion_r28740169","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/1754","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/28740169"},"html":{"href":"https://github.com/openshift/origin/pull/1754#discussion_r28740169"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/1754"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/1754","id":33387815,"html_url":"https://github.com/openshift/origin/pull/1754","diff_url":"https://github.com/openshift/origin/pull/1754.diff","patch_url":"https://github.com/openshift/origin/pull/1754.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/1754","number":1754,"state":"open","locked":false,"title":"migrate policy to new rest storage","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":"switching to the generic etcd registry and the new registry/storage split\r\n\r\n@liggitt review.","created_at":"2015-04-15T19:24:51Z","updated_at":"2015-04-20T23:58:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"266d87d1bff9d9396372862419b93c96e4226ab6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/1754/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/1754/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/1754/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/bd9b971f70c109bd9f01030ad20fdab8928d4a57","head":{"label":"deads2k:deads-move-to-registry","ref":"deads-move-to-registry","sha":"bd9b971f70c109bd9f01030ad20fdab8928d4a57","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}","created_at":"2014-09-24T17:02:12Z","updated_at":"2015-04-20T20:16:39Z","pushed_at":"2015-04-20T20:21:01Z","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":80458,"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":"59c9aa081881ffa08ccc7642dabe96a05a095adf","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":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","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}","created_at":"2014-07-30T20:04:05Z","updated_at":"2015-04-20T21:56:34Z","pushed_at":"2015-04-20T22:24:51Z","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":120011,"stargazers_count":374,"watchers_count":374,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":189,"mirror_url":null,"open_issues_count":208,"forks":189,"open_issues":208,"watchers":374,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/1754"},"html":{"href":"https://github.com/openshift/origin/pull/1754"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/1754"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/1754/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/1754/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/1754/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/bd9b971f70c109bd9f01030ad20fdab8928d4a57"}}}}