Skip to content

Cleanup impersonating code - #13630

Merged
openshift-bot merged 1 commit into
openshift:masterfrom
enj:enj/f/impersonating_clean/11647
Apr 6, 2017
Merged

openshift-bot merged 1 commit into
openshift:masterfrom
enj:enj/f/impersonating_clean/11647

Conversation

@enj

@enj enj commented Apr 5, 2017

Copy link
Copy Markdown
Contributor

I broke this out of #11647 since it was getting a bit large. @mfojtik @soltysh can one of you take a look?

[test][testextended][extended:core(templates)]

cc @jim-minter since this touches broker stuff (should have no change in functionality).

Signed-off-by: Monis Khan [email protected]

Comment thread pkg/auth/client/impersonate.go Outdated
return config
}

// NewImpersonatingOpenShiftClient returns an OS client that will impersonate a user, including user, groups, and scopes

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/OS/OpenShift/ but maybe we should call it Origin?


func NewTemplateInstanceController(restconfig *restclient.Config) *TemplateInstanceController {
c := TemplateInstanceController{restconfig: restconfig, templateclient: templateclientset.NewForConfigOrDie(restconfig)}
func NewTemplateInstanceController(restconfig restclient.Config) *TemplateInstanceController {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is missing godoc entirely, but I blame @jim-minter ;-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this change from a reference to a value arg?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we usually don't pass pointers that can be mutated inside the function and break the other callers?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(for things like client configs ;-)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm. i would have argued we normally pass pointers because it's more efficient.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(and because doing a shallow copy gives you a false sense of security where you can still mutate parts of the original object. at least when you take a pointer you know you need to be careful)

@mfojtik

mfojtik commented Apr 5, 2017

Copy link
Copy Markdown
Contributor

one naming nit, but LGTM otherwise... nice job @enj!

Signed-off-by: Monis Khan <[email protected]>
@enj
enj force-pushed the enj/f/impersonating_clean/11647 branch from 5d516dc to 59965e4 Compare April 5, 2017 13:30
@openshift-bot

Copy link
Copy Markdown
Contributor

Evaluated for origin test up to 59965e4

@openshift-bot

Copy link
Copy Markdown
Contributor

Evaluated for origin testextended up to 59965e4

@openshift-bot

Copy link
Copy Markdown
Contributor

continuous-integration/openshift-jenkins/testextended SUCCESS (https://ci.openshift.redhat.com/jenkins/job/test_pull_request_origin_extended/122/) (Base Commit: 801b564) (Extended Tests: core(templates))

@bparees

bparees commented Apr 5, 2017

Copy link
Copy Markdown
Contributor

aside from some of the changes from pointers to values for reasons that aren't clear to me, this looks ok. (i understand the cases where the type went from struct to interface, but that doesn't appear to be the case for all the changes)

@openshift-bot

Copy link
Copy Markdown
Contributor

@enj

enj commented Apr 5, 2017

Copy link
Copy Markdown
Contributor Author

@bparees

why did this change from a reference to a value arg?

Per David's request #11647 (comment)

Why a pointer? It makes reasoning about whether you're wrapping the same transport deeper and deeper over time harder since I have to find the callers.


hm. i would have argued we normally pass pointers because it's more efficient.

Even though the Config -> Client functions take pointers, they immediately do a shallow copy anyway.

(and because doing a shallow copy gives you a false sense of security where you can still mutate parts of the original object. at least when you take a pointer you know you need to be careful)

I do not really disagree with this. I think the general argument with Config is that all the fields that people want to customize are safe to mutate after a shallow copy.

@soltysh

soltysh commented Apr 6, 2017

Copy link
Copy Markdown
Contributor

LGTM, as well.

@soltysh

soltysh commented Apr 6, 2017

Copy link
Copy Markdown
Contributor

[merge]

@openshift-bot

Copy link
Copy Markdown
Contributor

Evaluated for origin merge up to 59965e4

@openshift-bot

openshift-bot commented Apr 6, 2017 •

Copy link
Copy Markdown
Contributor

continuous-integration/openshift-jenkins/merge SUCCESS (https://ci.openshift.redhat.com/jenkins/job/merge_pull_request_origin/265/) (Base Commit: b7a5b0f) (Image: devenv-rhel7_6119)

@openshift-bot
openshift-bot merged commit 33e1425 into openshift:master Apr 6, 2017
@jim-minter

Copy link
Copy Markdown
Contributor

@enj late reply as was on PTO. The NewImpersonating.*Client.* stuff is great, but what was the rationale for everything else - e.g. removing the kc, oc struct members and replacing them with secretsGetter, localSAR, and the general move from struct types to more specific interfaces?

@enj

enj commented Apr 18, 2017

Copy link
Copy Markdown
Contributor Author

@jim-minter

but what was the rationale for everything else - e.g. removing the kc, oc struct members and replacing them with secretsGetter, localSAR

secretsGetter and localSAR are self documenting - I can instantly tell the subset of actions those struct members could take. It is also trivial for you to add more members as you need other permissions (i.e. start out small and add more, not the other way around).

and the general move from struct types to more specific interfaces?

Nothing should ever use the concrete struct types unless you need to do some hacky manipulations of the fields, which should already tell you that something is wrong. Furthermore, I would expect every single one of these methods to have unit tests. That is physically impossible with the structs - you have use the interfaces to mock things out. See oauthclientregistry.go and oauthclientregistry_test.go for examples.

@jim-minter

Copy link
Copy Markdown
Contributor

thanks @enj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants