Skip to content

Conversation

@huntc
Copy link

@huntc huntc commented Oct 28, 2016

Reduce the requests made to HEAD requests in order to determine the type of authentication required, and actually authenticate. Once authenticated, then make the request. This strategy preserves the content of the request object, particularly when they contains stream objects as in the case of multipart/formdata requests.

Fixes #818

Reduce the requests made to HEAD requests in order to determine the type of authentication required, and actually authenticate. Once authenticated, then make the request. This strategy preserves the content of the request object, particularly when they contains stream objects as in the case of multipart/formdata requests.
@mesosphere-ci
Copy link
Collaborator

Can one of the admins verify this patch?

@huntc
Copy link
Author

huntc commented Oct 28, 2016

@tamarrow Any chance you could look at this and advise on if/when a release/merge would be possible? Thanks.

Copy link
Contributor

@tamarrow-zz tamarrow-zz left a comment

Choose a reason for hiding this comment

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

Thanks for the pr @huntc! Looks good, just a few comments. Once you make those changes and tests pass we can merge. A release will likely happen next week.

test_marathon.test_add_app_through_http failed: https://teamcity.mesosphere.io/viewLog.html?buildId=459433&buildTypeId=DcosIo_DcosCli_Ci&guest=1
Looks like we need to add a HEAD request handler: https://github.com/dcos/dcos-cli/blob/master/cli/tests/integrations/test_marathon.py#L830

dcos/http.py Outdated
else:
auth = AUTH_CREDS[creds]

# try request again, with auth
Copy link
Contributor

Choose a reason for hiding this comment

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

we should remove this comment

Copy link
Author

Choose a reason for hiding this comment

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

ok

dcos/http.py Outdated
raise DCOSException(msg)

if response.status_code == 401:
raise DCOSAuthenticationException(response)
Copy link
Contributor

Choose a reason for hiding this comment

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

we don't want to raise here anymore since we are looping outside this function.

Copy link
Author

Choose a reason for hiding this comment

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

I left it there because the prev implementation was responsible for throwing it ie I've preserved its contract. I don't think it is good to rely on the outer behaviour unless otherwise specified in its contract.

That said, I'll change it if that's what you want. Please confirm.

Copy link
Contributor

@tamarrow-zz tamarrow-zz Oct 28, 2016

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

We can update the pydoc with this information

Copy link
Author

Choose a reason for hiding this comment

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

Looking further, I guess it is an internal function so perhaps no need to doc further. I'll remove the raising of the exception.

dcos/http.py Outdated

response = _request(method, url, is_success, timeout,
verify=verify, **kwargs)
response = _request('head', url, is_success, timeout,
Copy link
Contributor

Choose a reason for hiding this comment

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

lets add a comment to explain why we are requesting with `head.

Copy link
Author

Choose a reason for hiding this comment

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

Will do. I will enhance the pydoc with this info.

@tamarrow-zz
Copy link
Contributor

ok to test

dcos/http.py Outdated
verify=verify)
i = 0
while i < 3 and response.status_code == 401:
auth_response = _request_with_auth(response, 'head', url, is_success,
Copy link
Contributor

Choose a reason for hiding this comment

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

lets just name this response

Copy link
Author

Choose a reason for hiding this comment

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

You don't want to overwrite the orig response given that the www-authenticate header will be lost.

@huntc
Copy link
Author

huntc commented Oct 28, 2016

PR feedback incorporated. I previously ran tox in order to test things so it was unexpected to see that the integration tests also required running. Also, I'm unable to get the integration tests running locally so hopefully the change that I made there is sufficient.

@huntc
Copy link
Author

huntc commented Oct 28, 2016

@tamarrow I may need your help in getting the integration tests done. Thanks.

BTW things are now working well with my DC/OS CLI sub command integration given these changes. I've been using the changes here against our production environment.

@tamarrow-zz
Copy link
Contributor

Yay, glad to hear it!

Re: integration tests: test_http_auth.test_request_with_bad_auth_basic needs to be updated because we changed http._request_with_auth

@huntc
Copy link
Author

huntc commented Oct 29, 2016

I'm really sorry to ask - would you mind updating the CLI tests (I'm unable to run them locally)... I'm having great difficulty running them and I feel that we're going to play ping-pong here otherwise. Sorry again to ask. I've granted you access to my repo so that you can push changes there.

huntc added a commit to huntc/conductr-cli that referenced this pull request Oct 31, 2016
Eliminates our dependency on the DC/OS lib until the day that dcos/dcos-cli#823 gets merged and we have a new lib.
huntc added a commit to huntc/conductr-cli that referenced this pull request Oct 31, 2016
Eliminates our dependency on the DC/OS lib until the day that dcos/dcos-cli#823 gets merged and we have a new lib.
@tamarrow-zz
Copy link
Contributor

@huntc happy to help, I'll get to it as soon as I can. If you want to talk about difficulties with running the tests locally, free free to join our open slack account: http://chat.mesosphere.com/ and we can chat there.

@huntc
Copy link
Author

huntc commented Oct 31, 2016

Thanks! I'll post my troubles to your gitter channel today.

On 1 Nov. 2016, at 03:29, tamarrow [email protected] wrote:

@huntc happy to help, I'll get to it as soon as I can. If you want to talk about difficulties with running the tests locally, free free to join our open slack account: http://chat.mesosphere.com/ and we can chat there.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

huntc added a commit to huntc/conductr-cli that referenced this pull request Nov 1, 2016
Eliminates our dependency on the DC/OS lib until the day that dcos/dcos-cli#823 gets merged and we have a new lib.
dcos_url = config.get_config_val("core.dcos_url")
auth_url = urllib.parse.urljoin(dcos_url, 'exhibitor/')
response = _request(
'GET', auth_url, is_success, timeout, verify=verify, **kwargs)
Copy link
Author

Choose a reason for hiding this comment

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

I'd still use a HEAD here - it is cheaper given the lack of content in reply. You'll still get the headers you need, and your service can potentially optimise in terms of handling HEAD.

i = 0
while i < 3 and response.status_code == 401:
auth_response = _request_with_auth(
response, 'GET', auth_url, is_success, timeout,
Copy link
Author

@huntc huntc Nov 2, 2016

Choose a reason for hiding this comment

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

Also, HEAD should be cheaper as mentioned. HEAD should always be interchangeable with GET.

Copy link
Author

@huntc huntc left a comment

Choose a reason for hiding this comment

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

All I'd suggest is changing to HEAD in place of GET.

One more thing: I'm unsure how "cheap" the Exhibitor URL is... it appears to render some state. You probably want something static, perhaps even an icon or something. This request will occur often.

@tamarrow-zz
Copy link
Contributor

@huntc see #824

@tamarrow-zz
Copy link
Contributor

Closing since this bug is fixed with #824

@tamarrow-zz tamarrow-zz closed this Nov 3, 2016
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.

3 participants