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

add support for using elastic cloud api key for auth #33

Merged
merged 1 commit into from
Jul 25, 2024

Conversation

fruch
Copy link
Owner

@fruch fruch commented Jul 24, 2024

@fruch fruch requested a review from tchaikov July 24, 2024 08:03
Copy link

codecov bot commented Jul 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.57%. Comparing base (8b9f722) to head (acc04be).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #33      +/-   ##
==========================================
+ Coverage   92.36%   92.57%   +0.21%     
==========================================
  Files           1        1              
  Lines         275      283       +8     
==========================================
+ Hits          254      262       +8     
  Misses         21       21              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Collaborator

@tchaikov tchaikov left a comment

Choose a reason for hiding this comment

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

left a couple comments.

@@ -192,8 +205,13 @@ def __init__(self, config):
self.is_slave = False

@property
def es_auth(self):
return self.es_username, self.es_password
def es_auth_args(self) -> dict[str, Any]:
Copy link
Collaborator

Choose a reason for hiding this comment

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

IIUC, this function always returns a dict[str, dict[str, str]]. if that's the case, probably we can just use dict[str, dict[str, str]] here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

it can return dict[str, tuple[str]], but is not important, it can return any request parameter and I don't want to document it all

tests/test_elk_reporter.py Show resolved Hide resolved
@@ -283,7 +301,7 @@ def report_test(self, item_report, outcome, old_report=None):
outcome=outcome,
duration=item_report.duration,
markers=item_report.keywords,
**self.session_data
**self.session_data,
Copy link
Collaborator

Choose a reason for hiding this comment

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

okay..

def es_auth_args(self) -> dict[str, Any]:
output = {}
if self.es_api_key:
output.update(dict(headers={"Authorization": f"ApiKey {self.es_api_key}"}))
Copy link
Collaborator

Choose a reason for hiding this comment

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

probably we can just return output here? IMHO, API key is more secure than username and password. if that's the case, we could just put

if self.es_api_key:
    headers = {"Authorization": f"ApiKey {self.es_api_key}"}
    return {"headers": headers}

Copy link
Owner Author

Choose a reason for hiding this comment

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

that was I did in the beginning, pylint wasn't happy about multiple returns within if/else

yes we can end up with both headers, don't know what would be the behavior of ES in this case

but I'll test it

didn't yet integrated with dtest, I'll try this to see if it work, or we need to prevent user for supplying both key and user/pass

Copy link
Owner Author

Choose a reason for hiding this comment

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

I've change back, after testing, if both header passed down, and one is wrong you fail to connect
so api key comes first, if both are defined.

raising exception if both set, in __init__ would be enough, cause in most usages we change those on runtime, after we retrieve the credentials, and never passing them with command line or configuration file.

I think that's good enough, and no need to go overboard with guardrailing this.

@fruch
Copy link
Owner Author

fruch commented Jul 24, 2024

Did integration test with a code base that uses this package,
and it's works as expected

@fruch fruch self-assigned this Jul 24, 2024
Copy link
Collaborator

@tchaikov tchaikov left a comment

Choose a reason for hiding this comment

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

lgtm

@fruch fruch merged commit 6ee3e1b into master Jul 25, 2024
7 checks passed
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.

2 participants