Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add Basic Authentication to HTTP extension #19

Merged
merged 2 commits into from
Feb 27, 2023
Merged

lib: add Basic Authentication to HTTP extension #19

merged 2 commits into from
Feb 27, 2023

Conversation

efd6
Copy link
Collaborator

@efd6 efd6 commented Feb 21, 2023

Previously, the only way to enable Basic Authentication was to manually construct a request object, adding the Authorization header appropriately and then using do_request. This change allows users to specify a Basic Authentication user/pass for all request using the head, get and post functions. Requests returned by request, get_request and post_request are not affected by the state of the Basic Authentication parameter as they can be easily altered using the wither pattern shown in the request documentation example.

No validation of the state of the auth parameter is made and this is the responsibility of the caller of lib.HTTP/lib.HTTPWithContext.

For elastic/beats#34609

@efd6 efd6 added the enhancement New feature or request label Feb 21, 2023
@efd6 efd6 requested a review from a team February 21, 2023 00:58
@efd6 efd6 self-assigned this Feb 21, 2023
@efd6 efd6 requested a review from andrewkroh February 21, 2023 01:15
@efd6
Copy link
Collaborator Author

efd6 commented Feb 21, 2023

Query whether it's worth adding a function to add the basic auth header into requests.

Previously, the only way to enable Basic Authentication was to manually
construct a request object, adding the Authorization header appropriately
and then using do_request. This change allows users to specify a Basic
Authentication user/pass for all request using the head, get and post
functions. Requests returned by request, get_request and post_request
are not affected by the state of the Basic Authentication parameter as
they can be easily altered using the wither pattern shown in the request
documentation example.

No validation of the state of the auth parameter is made and this is the
responsibility of the caller of lib.HTTP/lib.HTTPWithContext.
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

Query whether it's worth adding a function to add the basic auth header into requests.

The sounds like a nice little simplification for the users.

This convenience method allows users to directly add basic auth to an
existing constructed request map without needing to use a wither
pattern.

Also update the wither pattern example to correctly reflect the actions
that need to be done if using that approach.
@efd6 efd6 requested a review from andrewkroh February 27, 2023 22:23
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM

@efd6 efd6 merged commit bdd74dd into dev Feb 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants