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

Base ConnectionConfigModel Not Deserializing #363

Closed
treyhendon opened this issue Sep 17, 2024 · 15 comments
Closed

Base ConnectionConfigModel Not Deserializing #363

treyhendon opened this issue Sep 17, 2024 · 15 comments

Comments

@treyhendon
Copy link

return JsonSerializer.Deserialize<PostgreSQLConnectionConfigModel>(jsonString);

PostgreSQLConnectionConfigModel is properly being deserialized, but base properties from ConnectionConfigModel (i.e. connection_url, username, password) are null in the returned Secret<ConnectionConfigModel>.

@treyhendon
Copy link
Author

I'm debugging through locally to try to find a solution. Posting here in case you know a quick fix. Thanks!

@rajanadar
Copy link
Owner

Are all base properties null?

The System.Text.Json custom converters seem to be problematic if used via attributes. (vs programmatically)
I'll also debug further. dotnet/runtime#46372

@treyhendon
Copy link
Author

Any base property that didn't have a default in the class appears null, yes. I do see the value in the jsonString from the API response.

@treyhendon
Copy link
Author

I followed your comment in the ConnectionConfigModel class and saw that .net issue about STJ. I was testing different forms of attribute references to see if I could force the base model to deserialize first, but so far no luck.

@treyhendon
Copy link
Author

As an example, here's what I get in jsonString:

{"allowed_roles":["api-sample","api-sample-migration"],"connection_details":{"connection_url":"postgresql://{{username}}:{{password}}@myserver.svc.cluster.local:5432/sample?sslmode=require","username":"myuser"},"password_policy":"","plugin_name":"postgresql-database-plugin","plugin_version":"","root_credentials_rotate_statements":[]}

I made a temp obj variable to capture the deserialzed value:
image

@rajanadar
Copy link
Owner

thanks , that is very helpful. I think it is not a deser issue. The structure of the connection object between the write and read seems to be different. The read structure is as follows: https://developer.hashicorp.com/vault/api-docs/secret/databases#sample-response

Thats the problem. I'll release a fix with the right model tomorrow.

@treyhendon
Copy link
Author

Oh! I think I see it. The JSON structure is slightly different than expected.

{
	"allowed_roles": [
		"api-sample",
		"api-sample-migration"
	],
	"connection_details": {
		"connection_url": "postgresql://{{username}}:{{password}}@myserver.svc.cluster.local:5432/sample?sslmode=require",
		"username": "myuser"
	},
	"password_policy": "",
	"plugin_name": "postgresql-database-plugin",
	"plugin_version": "",
	"root_credentials_rotate_statements": []
}

Looks like ConnectionDetails would hold ConnectionUrl, Username, Password, etc

@rajanadar
Copy link
Owner

@treyhendon I prepared a local fix. Which version of .NET are you using? i'll give you a DLL for temp testing here, before releasing a nuget

@rajanadar rajanadar reopened this Sep 17, 2024
@treyhendon
Copy link
Author

I'm using .net 8. Thanks!

@rajanadar
Copy link
Owner

please use this dll and let me know.
VaultSharp-1.17.5.1-For-Test-.NET 8.zip

@treyhendon
Copy link
Author

I actually just pulled your master branch and was able to successfully test! I'll download the dll and try that as well. Thanks!

@rajanadar
Copy link
Owner

Ah cool. I forget that folks can easily build from the project as well.

@treyhendon
Copy link
Author

I can also confirm the .net 8 dll is a success. Thanks again for such a quick response!

@rajanadar
Copy link
Owner

Cool, good to hear. I'll publish the official nuget in a day. It's my bad, I overlooked the read Api response model.

@rajanadar
Copy link
Owner

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