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

Add geojson support for XYPoint #162

Merged
merged 3 commits into from
Oct 19, 2022
Merged

Conversation

heemin32
Copy link
Collaborator

@heemin32 heemin32 commented Oct 11, 2022

See #152

Signed-off-by: Heemin Kim heemin@amazon.com

Description

Supports GeoJson Point type in XYPoint field

Issues Resolved

#152

Check List

  • Commits are signed per the DCO using --signoff

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

@VijayanB
Copy link
Member

Description has to be changed to xy_point not geo_point :)

@heemin32
Copy link
Collaborator Author

Description has to be changed to xy_point not geo_point :)

Copy&Paste error. Thanks!

throws IOException {
try (XContentSubParser subParser = new XContentSubParser(parser)) {
if (subParser.nextToken() != XContentParser.Token.FIELD_NAME) {
throw new OpenSearchParseException(ERR_MSG_INVALID_TOKEN, subParser.currentToken());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's not safe to return user input as part of the output, learned from the last pentest. I suggest minimize error message to just "token not allowed" and add logger with all required details.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you share what security risk this might contain?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure, in my report they have call it "User Input Reflected on Error" and marked it as "Medium" severity

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @martin-gaievski . subParser.currentToken() is not random user input. It is enum defined in XContentParser.Token. So, I think there is no security risk returning it.


private static XYPoint parseGeoPointObjectBasicFields(final XContentParser parser, final XYPoint point) throws IOException {
HashMap<String, Double> data = new HashMap<>();
for (int i = 0; i < 2; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better introduce/use constant IMO

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This number is specific to this method. Let me use variable instead to make its meaning to be explicit.

if (parser.currentToken() == XContentParser.Token.START_ARRAY) {
return parseXYPointArray(parser, ignoreZValue, x, y);
String field = parser.currentName();
if (X_PARAMETER.equals(field) == false && Y_PARAMETER.equals(field) == false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume syntax with "==" is for better readability, correct?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. OpenSearch's standard convention is avoiding negation like !X_PARAMETER.equals(field)

try {
data.put(field, parser.doubleValue(true));
} catch (NumberFormatException e) {
throw new OpenSearchParseException("[{}] and [{}] must be valid double values", e, X_PARAMETER, Y_PARAMETER);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be consistent to create anew constant for error message here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message is used only in this method. I don't think it is worth to make is as a constant?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaving it up to you, but I would make it a constant anyway. From my experience it helps to avoid creating multiple identical messages with slightly different wording. If all messages are in one place chance is higher that next person will reuse one from the list.

Signed-off-by: Heemin Kim <heemin@amazon.com>
Signed-off-by: Heemin Kim <heemin@amazon.com>
@heemin32 heemin32 force-pushed the geojson branch 2 times, most recently from b46c3b6 to a724add Compare October 13, 2022 23:59
Copy link
Collaborator

@navneet1v navneet1v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment.

@heemin32 heemin32 force-pushed the geojson branch 2 times, most recently from 5b92ffd to b86c3c0 Compare October 19, 2022 21:31
Signed-off-by: Heemin Kim <heemin@amazon.com>
@heemin32 heemin32 added backport 2.x Backport PR to 2.x branch enhancement New feature or request and removed backport 2.x Backport PR to 2.x branch labels Oct 19, 2022
@heemin32 heemin32 merged commit 63c97b0 into opensearch-project:main Oct 19, 2022
@heemin32 heemin32 added the backport 2.x Backport PR to 2.x branch label Oct 19, 2022
@opensearch-trigger-bot
Copy link

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 1

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-2.x 2.x
# Navigate to the new working tree
cd .worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-162-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 63c97b083f137a035563710c67c57fc23b9493f4
# Push it to GitHub
git push --set-upstream origin backport/backport-162-to-2.x
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-162-to-2.x.

heemin32 added a commit to heemin32/geospatial that referenced this pull request Oct 19, 2022
* Add geojson support for XYPoint

Signed-off-by: Heemin Kim <heemin@amazon.com>
(cherry picked from commit 63c97b0)
heemin32 added a commit that referenced this pull request Oct 19, 2022
* Add geojson support for XYPoint

Signed-off-by: Heemin Kim <heemin@amazon.com>
(cherry picked from commit 63c97b0)
@heemin32 heemin32 deleted the geojson branch October 24, 2022 22:01
@heemin32 heemin32 added the v2.4.0 'Issues and PRs related to version v2.4.0' label Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport PR to 2.x branch enhancement New feature or request v2.4.0 'Issues and PRs related to version v2.4.0'
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants