PAPP-36780 cert based auth#58
PAPP-36780 cert based auth#58NiemySpiewak-splunk wants to merge 4 commits intomsankowska/PSAAS-24763-porting_HTTP_to_SDKfrom
Conversation
package/src/helpers.py
Outdated
| cert_bytes = base64.b64decode(asset.public_cert) | ||
| key_bytes = base64.b64decode(asset.private_key) |
There was a problem hiding this comment.
I'd move those 2 lines outside of try, at this point we don't have anything to delete
package/src/request_maker.py
Outdated
| ): | ||
| logger.warning( | ||
| "Request failed with 401, token might be expired. Forcing a refresh." | ||
| cert_manager = temp_cert_files(asset) if (asset.client_cert and asset.client_key) else nullcontext() |
There was a problem hiding this comment.
why are we checking for client_key and client_cert when temp_cert_files uses different params of an Asset?
Btw does the temp_cert_files need the whole asset? I think we might be good with just cert params ;)
also it would be cleaener to be able to use it just like with temp_cert_files(cert ,key) as cert_param:
...
package/src/request_maker.py
Outdated
| with cert_manager as cert_param: | ||
| retries = 1 | ||
| response = None | ||
|
|
||
| while retries >= 0: | ||
| auth_method = get_auth_method(asset, soar) | ||
| auth_object, final_headers = auth_method.create_auth(parsed_headers) | ||
|
|
||
| try: | ||
| response = requests.request( |
There was a problem hiding this comment.
I think we have kind of scope creep here, block inside a block inside another block.
Any ideas how we can get around that?
| break | ||
|
|
||
| except requests.exceptions.RequestException as e: | ||
| if isinstance(auth_method, OAuth) and e.response and e.response.status_code == 401 and retries > 0: |
There was a problem hiding this comment.
This looks like an old version of the base branch. This should be
if isinstance(auth_method, OAuth) and retries > 0: see https://github.com/splunk-soar-connectors/http_app/blob/msankowska/PSAAS-24763-porting_HTTP_to_SDK/src/request_maker.py#L82
you probably need to merge the base branch with this branch and fix any merge conflicts
93b37f3 to
59500e8
Compare
| "Request failed with 401, token might be expired. Forcing a refresh." | ||
| body = UnicodeDammit(body).unicode_markup.encode("utf-8") if isinstance(body, str) else body | ||
|
|
||
| with temp_cert_files(asset.public_cert, asset.private_key) as cert_param: |
There was a problem hiding this comment.
This seems like somewhat of an anti-pattern. It implies that we can have token based auth and then get_auth_method can still return a different type of auth. We're implementing standalone cert based auth. Let's change this logic by creating a CertBasedAuth class that inherits Authorization in auth.py, then have get_auth_method return CertBasedAuth is asset.public_cert and asset.private_key are present.
I also think we shouldn't surround the entire function with a context manager when it's not going to be used most of the time. Lets do something like this
| with temp_cert_files(asset.public_cert, asset.private_key) as cert_param: | |
| auth_method = get_auth_method(asset, soar) | |
| if isinstance(auth_method, CertificateAuth): | |
| return _execute_certificate_request(auth_method, full_url, method, body, verify, parsed_headers, output, asset, soar) | |
| else: | |
| return _execute_standard_request(auth_method, full_url, method, body, verify, parsed_headers, output, asset, soar) |
_execute_certificate_request would then make certificate based requests and _execute_standard_request would be responsible for everything else
| cert_bytes = base64.b64decode(asset.public_cert) | ||
| key_bytes = base64.b64decode(asset.private_key) |
There was a problem hiding this comment.
shouldn't these use cert_b64 and key_b64 respectively
a7a9822 to
ee75fbf
Compare
Features
List any features you're adding to this app (e.g. new actions, parameters, auth methods, etc.)
Manual Documentation
Have you made any changes that should be documented in manual_readme_content.md? NO
The following changes require documentation in
manual_readme_content.md: