vmware / go-vmware-nsxt

golang library for NSX-T REST API
Other
55 stars 29 forks source link

NewAPIClient should fail if session cannot be created #51

Closed embano1 closed 2 years ago

embano1 commented 2 years ago

Describe the bug

Calling nsxt.NewAPIClient(&nsxCfg) with invalid username/password should fail. Instead a warning with a hardcoded logger (see #50 ) is printed:

2022/03/31 10:38:52 Warning: Failed to create session: status code 403

Reproduction steps

1. Call `nsxt.NewAPIClient(&nsxCfg)` with invalid username/password
2. Warning is printed

Expected behavior

nsxt.NewAPIClient(&nsxCfg) with invalid username/password should return an error instead of nil error.

Additional context

No response

embano1 commented 2 years ago

Current workaround seems to manually create session via SkipSessionAuth: true and handling err = nsxt.GetDefaultHeaders(nsxClient)

annakhm commented 2 years ago

You are correct @embano1, however fixing this would change behavior for users. Just to verify - are you seeing change of behavior due to recent PR https://github.com/vmware/go-vmware-nsxt/pull/48?

embano1 commented 2 years ago

Thx!

You are correct @embano1, however fixing this would change behavior for users.

Agree, though I'd argue this change in behavior would be preferred for most users, can be documented and is an explicit opt-in for existing users of the package once they upgrade to this new version.

Just to verify - are you seeing change of behavior due to recent PR https://github.com/vmware/go-vmware-nsxt/pull/48?

Just started using the package (after the PR landed) so can't compare.

annakhm commented 2 years ago

Thanks for your feedback. Since you are a fresh user, have you considered using https://github.com/vmware/vsphere-automation-sdk-go instead? That's an officially supported and up-to-date sdk. This repository, however, is not actively maintained and not recommended for new users.

embano1 commented 2 years ago

Thx for the note, wasn't aware that this repo is supposed to be used only by existing library users.

I just checked the automation-sdk-go and tbh I'm going to stick with this library and my workarounds for now ,)