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

Allow specifying a Timeout value #240

Merged
merged 3 commits into from
Mar 20, 2024
Merged

Conversation

gdbarron
Copy link
Collaborator

closes #237

@gdbarron gdbarron linked an issue Dec 15, 2023 that may be closed by this pull request
@gdbarron gdbarron requested a review from Saadi6 December 15, 2023 19:07
@gdbarron gdbarron added the enhancement New feature or request label Dec 15, 2023
Copy link
Collaborator

@Saadi6 Saadi6 left a comment

Choose a reason for hiding this comment

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

Without wrapping New-VenafiSession in try catch statement and using 1 sec timeout resulted in an incomplete VenafiSesison object. It was missing version and custom field definitions but token was present and useable.

VERBOSE: {"Body":"{\"ConfigClass\":\"Application Base\"}","ContentType":"application/json","Method":"Post","TimeoutSec":1,"Headers":{"Authorization":"***hidden***"},"Uri":"https://tls.bigsur.local/vedsdk/Metadata/GetItemsForClass","UseBasicParsing":true}
VERBOSE: Response status code 0
PS /Users/saad.humayun> $VenafiSession                       

Platform             : VDC
AuthType             : Token
Expires              : 12/23/2023 4:23:14 PM
TimeoutSec           : 1
SkipCertificateCheck : False
Version              : 
CustomField          : 
Server               : https://tls.bigsur.local
Key                  : 
Token                : @{Server=https://tls.bigsur.local; AccessToken=System.Management.Automation.PSCredential; RefreshToken=; Scope=System.Collections.Hashtable; 
                       Identity=AD+BigSur:efd2ab3ac8f73a40ba4865ea5da1c035; TokenType=Bearer; ClientId=xxxxx; Expires=12/23/2023 4:23:14 PM; RefreshExpires=}

Wrapping New-VenafiSession in try catch statement returns an error upon first timeout.

VERBOSE: {"ContentType":"application/json","Method":"Get","TimeoutSec":1,"Headers":{"Authorization":"***hidden***"},"Uri":"https://tls.bigsur.local/vedsdk/SystemStatus/Version","UseBasicParsing":true}
VERBOSE: Response status code 0
Exception: untitled:Untitled-1:8:5
Line |
   8 |      throw $_.Exception.Message
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Getting the version failed with the following error: The request was canceled due to the configured HttpClient.Timeout of 1 seconds elapsing..  This
     | feature was introduced in v18.3.

A new session with a reasonable timeout specified has everything as expected.

While this behaviour is as expected, it may confuse someone using a low timeout value without try catch, while using a function that happens to make several calls to Venafi API before a result is returned.

I suggest throwing an error when any call times out or adding a note in documentation that some errors due to low timeout value might be hidden if try and catch is not used.

Copy link
Collaborator

Saadi6 commented Dec 17, 2023

comments submitted in review on GitHub

@gdbarron
Copy link
Collaborator Author

If someone uses a low timeout without error handling and an incomplete session is created, why doesn't the first call post New-VenafiSession fail? I would think it would just as the calls to get version and CF info did. Also, I would expect there to be errors for failure to retrieve version and CF, those are just not terminating errors so New-VenafiSession completes and does not stop the script.

Trying to understand the suggestion a bit deeper. Is it to update Invoke-VenafiRestMethod to throw a terminating error whenever an api call fails, or just fails on timeout, or not terminating? Or is the suggestion isolated to New-VenafiSession? Or something else?

@gdbarron
Copy link
Collaborator Author

gdbarron commented Feb 8, 2024

@Saadi6?

@Saadi6
Copy link
Collaborator

Saadi6 commented Feb 9, 2024

Excuse the late response. Without error handling while calling New-VenafiSession with a very short timeout value a terminating error does not occur, even though some of the background HTTP calls made by VenafiPS (such as gathering custom fields) while creating the session object did timeout.

Wrapping New-VenafiSession in try catch statement - as one should - throws an error when any background HTTP request times out and an incomplete, yet semi-useable VenafiSession is not returned.

Yes, if possible, Invoke-VenafiRestMethod can be updated to throw a terminating error only incase of timeout error. There might other implications if terminating error is thrown for all types of error by Invoke-VenafiRestMethod.

However, given that you don't know someone might use VenafiPS in their own code, just a warning/suggestion to always use error handling - when a timeout value is specified - would also be sufficient IMHO.

Copy link
Collaborator

@Saadi6 Saadi6 left a comment

Choose a reason for hiding this comment

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

Timeout feature works

@gdbarron gdbarron merged commit 02f9ca0 into main Mar 20, 2024
5 checks passed
@gdbarron gdbarron deleted the 237-allow-specifying-a-timeout-value branch March 20, 2024 02:21
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.

Allow specifying a Timeout value
2 participants