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

Can't provide customRole.actions[*].resources[*].collection as empty string #263

Closed
Freyert opened this issue Oct 27, 2021 · 1 comment · Fixed by #264
Closed

Can't provide customRole.actions[*].resources[*].collection as empty string #263

Freyert opened this issue Oct 27, 2021 · 1 comment · Fixed by #264

Comments

@Freyert
Copy link
Contributor

Freyert commented Oct 27, 2021

Describe the bug
Because the SDK uses value types instead of pointer types for type Resource.(Db|Collection) users of the SDK will not be able to send empty strings for fields such as collection or db as they will be fully omitted when serialized to JSON.

I've put together an example in "The Go Playground" to demonstrate the issue: https://play.golang.org/p/OHNEv_7HIcc

{"actions":[{"action":"DROP_INDEX","resources":

[{"db":"admin"}]}], //<--- should have "collection": ""

"inheritedRoles":null,"roleName":"500Error"}

Expected behavior
If I set Resource.Collection = "" I should have "collection": "" in the JSON output.

{"actions":[{"action":"DROP_INDEX","resources":

[{"db":"admin", "collection": "" }]}], // "collection": "" exists

"inheritedRoles":null,"roleName":"500Error"}

Logs
https://play.golang.org/p/OHNEv_7HIcc

Desktop (please complete the following information):

  • OS: [e.g. macOS]
  • Lib Version [e.g. 0.6.0]

Additional context
This should be an issue everywhere the SDK is being used. For example, I think it will be an issue here in the terraform provider:

https://github.com/mongodb/terraform-provider-mongodbatlas/blob/master/mongodbatlas/resource_mongodbatlas_custom_db_role.go#L118

@Freyert
Copy link
Contributor Author

Freyert commented Oct 27, 2021

Working with pointer values and structs can be fairly frustrating because you can't directly set a &"" in a struct without first assigning "" to a variable.

The aws-sdk-go gets around this by providing a function that takes a string and returns a pointer (aws.String)

I've wondered why they do that for the longest time and now I know :D

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

Successfully merging a pull request may close this issue.

1 participant