Adding logout function and context manager into Authentication class #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi,
I hope the maintainers accept PRs for this repository still. I recently received a suggestion from Cisco TAC that an issue could potentially be being caused by an API account not terminating its sessions properly. This API account is heavily used and with sessions not being terminated there is a high amount of active authenticated sessions waiting for the standard 30 minute time out. We use this SDK quite heavily in some services and I noticed there is currently no built in way to trigger a logout, so I'm submitting a PR for one.
The logout function is relatively similar to the login function with some subtle differences:
This function can be called directly if the user initiated the class and called login after the fact. However if the user followed the example and called login directly without storing the initiated class the user can pass an optional "session" argument to specify the session they wish to terminate (they would not need to pass credentials on the logout call).
This correctly terminates the session on the vManage.
The authentication class also includes a context manager to control the session within the context to allow for properly closing the session on an error.
This then allows the user to control their connection with a with statement instead:
Hopefully the PR is okay, if theres anything that needs changing or their are suggested improvements just let me know.
Cheers