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

IdentityServicesEngineAPI Class: Add username as property #21

Closed
netgab opened this issue Feb 22, 2022 · 7 comments
Closed

IdentityServicesEngineAPI Class: Add username as property #21

netgab opened this issue Feb 22, 2022 · 7 comments

Comments

@netgab
Copy link

netgab commented Feb 22, 2022

Is your feature request related to a problem? Please describe.
When sharing an instance of the IdentityServicesEngineAPI in various classes, the used parameters in the constructor __init__ might not be accessible in other classes or methods (e.g. when passing the instance as a method parameter). Especially when catching exceptions some of the instance parameters might be helpful for meaningful error messages (e.g. on a 401 error add the username in the exception message)

Describe the solution you'd like
It would be helpful to have all properties (ok - we might discuss about the password) used in the constructor as getter (and possibly setter) properties.

@wastorga
Copy link
Collaborator

Hi, @netgab. I am currently working on the changes for the properties.
For the API-related exceptions, would it suffice if the SDK returned the request headers?

@netgab
Copy link
Author

netgab commented Feb 23, 2022

Hi, @wastorga ,

For the API-related exceptions, would it suffice if the SDK returned the request headers?

No need for this... This was not my intention in this enhancement request.
However, it would be nice to have the headers of the request as an attribute/property in ApiError.

@wastorga
Copy link
Collaborator

wastorga commented Feb 23, 2022

Hi, @netgab. This is what the next release would look like regarding the properties.

https://ciscoisesdk.readthedocs.io/en/develop/api/api.html#ciscoisesdk.IdentityServicesEngineAPI

The password and encoded_auth have special methods, is_* and change_*.

@wastorga
Copy link
Collaborator

The ApiError would look like this:

In [15]: try:
    ...:     r2 = api.endpoint.delete_by_id(id=r1_id)
    ...: except ciscoisesdk.ApiError as e:
    ...:     print(e)
    ...:     print(e.additional_data)
    ...:     print(e.request.headers)
[401] - Authentication credentials were missing or incorrect.
Check ApiError.additional_data for more info.

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
Username: username
Password: password

{'User-Agent': 'python-requests/2.27.1', 'Accept-Encoding': 'gzip, deflate', 'Accept': 'application/json', 'Connection': 'keep-alive', 'authorization': 'Basic dXNlcm5hbWU6cGFzc3dvcmQ=', 'Content-type': 'application/json;charset=utf-8', 'Content-Length': '0'}

@wastorga
Copy link
Collaborator

Finally, this is a more detailed example of how to use it

api = IdentityServicesEngineAPI(verify=False, debug=True, uses_csrf_token=True)
api.username = "username"
assert api.username == "username"
api.change_password("password")
assert api.is_password("password")
api.reinitialize()  # Distribute our changes reinitializing the IdentityServicesEngineAPI

api2 = IdentityServicesEngineAPI(verify=False, debug=True, perform_initialize=False)
api2.uses_csrf_token = True
api2.debug = False
api2.reinitialize()  # Distribute our changes initializing the IdentityServicesEngineAPI

@wastorga
Copy link
Collaborator

The ciscoisesdk v1.5.0 is up. Feel free to test it and close or comment if necessary.

@netgab
Copy link
Author

netgab commented Feb 25, 2022

Thank you!

@netgab netgab closed this as completed Feb 25, 2022
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

No branches or pull requests

2 participants