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

Decode BSON documents correctly in API responses #32

Merged
merged 1 commit into from
Feb 10, 2022

Conversation

magnusbaeck
Copy link
Member

Applicable Issues

Fixes #19

Description of the Change

Previously the BSON documents in the result sets were decoded as bson.D when stored in EiffelEvent.Data. This meant that the original objects turned up as slices of objects,

[{"Key": "name", "Value": "foo"]

instead of objects,

{"name": "foo"}

which obviously meant that they were no longer valid Eiffel events. We address this by deriving the EiffelEvent data type from map[string]interface{} which is the same underlying type as bson.M,the unordered map type.

This made the internal/schema package more or less empty so the remaining EiffelEvent definition was moved to internal/database/driverswhere the database driver interface is defined.

When we implement other API endpoints we'll need to access members of the Eiffel events in the responses and there are a few differentways of doing that, but let's deal with that later.

The projections of the MongoDB queries were also adjusted to omit the unwanted _id field.

Adding eiffelevents-sdk-go and running "go mod tidy" resulted in an extra "require" section in go.mod. Not entirely sure why.

Alternate Designs

See associated issue for background.

Benefits

Proper API responses.

Possible Drawbacks

None.

Sign-off

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved.

Signed-off-by: Magnus Bäck <magnus.back@axis.com>

Previously the BSON documents in the result sets were decoded as
bson.D when stored in EiffelEvent.Data. This meant that the original
objects turned up as slices of objects,

    [{"Key": "name", "Value": "foo"]

instead of objects,

    {"name": "foo"}

which obviously meant that they were no longer valid Eiffel events.
We address this by deriving the EiffelEvent data type from
map[string]interface{} which is the same underlying type as bson.M,
the unordered map type.

This made the internal/schema package more or less empty so the
remaining EiffelEvent definition was moved to internal/database/drivers
where the database driver interface is defined.

When we implement other API endpoints we'll need to access members
of the Eiffel events in the responses and there are a few different
ways of doing that, but let's deal with that later.

The projections of the MongoDB queries were also adjusted to omit the
unwanted "_id" field.

Adding eiffelevents-sdk-go and running "go mod tidy" resulted in an
extra "require" section in go.mod. Not entirely sure why.
@magnusbaeck magnusbaeck added the bug Something isn't working label Feb 9, 2022
@magnusbaeck magnusbaeck requested a review from a team as a code owner February 9, 2022 16:13
@magnusbaeck magnusbaeck requested review from t-persson and removed request for a team February 9, 2022 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

/events/$ID endpoint returns event payload with incorrectly marshaled BSON value
2 participants