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

Added timezone information to the available fields #33

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

skinny
Copy link

@skinny skinny commented Apr 1, 2024

My use case also uses the timezone information (available on ipinfo.io) but was not yet available in this self hosted soltution. This PR downloads the City geo database and uses that to return a "best guess" timezone for the users IP.

Summary by CodeRabbit

  • New Features
    • Integrated GeoLite2-City database to enhance geo-location services.
    • Added a new /timezone endpoint for retrieving user time zone information.
    • Updated the /json endpoint to include timezone information in responses.
    • Improved Dockerfile to automate GeoLite2-City database setup.
    • Enhanced nginx configuration to utilize GeoLite2-City.mmdb for accurate time zone retrieval.

Copy link

coderabbitai bot commented Apr 1, 2024

Walkthrough

The recent updates enhance the application's geolocation capabilities by integrating the GeoLite2-City database into the Docker setup, and configuring nginx to utilize this database for time zone information retrieval. A new endpoint and additional response fields have been introduced to provide users with time zone data based on their IP addresses, enriching the application's geospatial functionalities.

Changes

Files Change Summary
Dockerfile, nginx/conf.d/geoip2.conf Added steps for downloading, verifying, and extracting the GeoLite2-City database in the Dockerfile. Added functionality to load and use the GeoLite2-City.mmdb database for time zone retrieval in nginx configuration.

🌍🐰✨
In the world of code, where data streams flow,
A rabbit hopped in, with updates in tow.
"Behold," it said, "for time zones we cater,
With GeoLite2-City, we're now the navigator.
Through nginx paths, our journey we chart,
Bringing time zones close, though miles apart."
🌐🕒💫
🐇📦🔍

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@skinny skinny changed the title feat: add timezone information to the available fields Added timezone information to the available fields Apr 1, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between f6845af and ec894c4.
Files selected for processing (3)
  • Dockerfile (1 hunks)
  • nginx/conf.d/geoip2.conf (1 hunks)
  • nginx/conf.d/ipinfo.conf (2 hunks)
Additional Context Used
Additional comments not posted (3)
nginx/conf.d/geoip2.conf (1)

15-18: The addition of the GeoLite2-City.mmdb database configuration for retrieving timezone information is correctly implemented and aligns with the PR's objectives. However, for maintainability, consider externalizing configurable values such as the database path and auto-reload interval into a separate configuration file or environment variables. This approach can simplify future updates or changes to these settings.

nginx/conf.d/ipinfo.conf (2)

53-55: The addition of the /timezone endpoint is correctly implemented and serves the PR's objective of making timezone information accessible. Well done!


64-64: The modification to the /json endpoint to include the timezone field is correctly implemented and aligns with the PR's objectives. This enhances the endpoint's utility by providing additional valuable information.

Comment on lines +22 to +26
RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz
RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256
RUN sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256
RUN sha256sum -c GeoLite2-City.tar.gz.sha256
RUN tar xvf GeoLite2-City.tar.gz --strip 1
Copy link

Choose a reason for hiding this comment

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

The steps for handling the GeoLite2-City database are correctly implemented, ensuring secure download, verification, and extraction. To optimize the Dockerfile and reduce the number of layers, consider combining these RUN commands into a single RUN command using && to chain the commands together. This can improve the build performance and reduce the image size.

-RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz
-RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256
-RUN sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256
-RUN sha256sum -c GeoLite2-City.tar.gz.sha256
-RUN tar xvf GeoLite2-City.tar.gz --strip 1
+RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz && \
+    wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 && \
+    sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256 && \
+    sha256sum -c GeoLite2-City.tar.gz.sha256 && \
+    tar xvf GeoLite2-City.tar.gz --strip 1

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz
RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256
RUN sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256
RUN sha256sum -c GeoLite2-City.tar.gz.sha256
RUN tar xvf GeoLite2-City.tar.gz --strip 1
RUN wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz" -O GeoLite2-City.tar.gz && \
wget "${MAXMIND_BASE_URL}edition_id=GeoLite2-City&suffix=tar.gz.sha256" -O GeoLite2-City.tar.gz.sha256 && \
sed 's/GeoLite2-City_[0-9]*.tar.gz/GeoLite2-City.tar.gz/g' -i GeoLite2-City.tar.gz.sha256 && \
sha256sum -c GeoLite2-City.tar.gz.sha256 && \
tar xvf GeoLite2-City.tar.gz --strip 1

Copy link
Owner

@PeterDaveHello PeterDaveHello left a comment

Choose a reason for hiding this comment

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

Cool, thanks for your contribution, @skinny. Please allow me to do some tests, and then we can merge it!

@@ -11,3 +11,9 @@ geoip2 /usr/share/GeoIP/GeoLite2-ASN.mmdb {
$ip_aso source=$remote_addr autonomous_system_organization;
$ip_as_build_epoch metadata build_epoch;
}

geoip2 /usr/share/GeoIP/GeoLite2-City.mmdb {
auto_reload 1d; # Automatically reload the database daily
Copy link
Owner

Choose a reason for hiding this comment

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

We don't need those additional comments just for the city database, so let's maintain consistency here.

auto_reload 1d; # Automatically reload the database daily
$ip_time_zone source=$remote_addr location time_zone; # Retrieve the time zone
}

Copy link
Owner

Choose a reason for hiding this comment

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

This additional newline should also been removed.

Copy link
Owner

@PeterDaveHello PeterDaveHello left a comment

Choose a reason for hiding this comment

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

We should add some documentation about the timezone feature in the README file, allowing users to understand how to utilize this new functionality.

e.g.

$ curl https://ipinfo.tw/timezone
Asia/Taipei

{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","timezone":"Asia/Tokyo","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between ec894c4 and 219b674.
Files selected for processing (1)
  • nginx/conf.d/geoip2.conf (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • nginx/conf.d/geoip2.conf

@skinny
Copy link
Author

skinny commented Apr 2, 2024

@PeterDaveHello removed the comments, newlines and added a bit of documentation on the timezone field

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 219b674 and 6ebdb16.
Files selected for processing (1)
  • README.md (3 hunks)
Additional comments not posted (5)
README.md (5)

58-58: The server's response now includes timezone information, which is a significant enhancement. It's crucial to ensure that this new feature is well-documented and that examples are provided to guide users on how to use it effectively.


63-63: The JSON response example is clear and informative, showing the new timezone information. This addition enhances the usability of the service for clients that require timezone data.


78-78: The addition of a /timezone endpoint is a valuable feature for users specifically interested in timezone information. It's important to ensure that this endpoint is tested thoroughly to maintain the reliability of the service.


101-103: Providing an example of the /timezone endpoint usage is helpful for users. It might be beneficial to include more examples or scenarios where this endpoint could be particularly useful, enhancing the documentation's comprehensiveness.


55-66: > 📝 NOTE

This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [134-134]

When instructing users to build their own image with a docker build command, it's mentioned to use a MAXMIND_LICENSE_KEY. It would be helpful to emphasize the importance of keeping this key secure and not exposing it in publicly accessible places, such as GitHub repositories.

Comment on lines 55 to 66
- `wget -qO- https://ipinfo.tw`
- `curl https://ipinfo.tw`

Without any specified URI, the server will return IP address, country, AS, and user agent.
Without any specified URI, the server will return IP address, country, timezone, AS, and user agent.

If you prefer to receive a machine-readable result, use path `/json` (without trailing slash), e.g. `https://ipinfo.tw/json`, the result will look like:

```json
{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"}
{"ip":"3.115.123.234","country_code":"JP","country_name":"Japan","timezone":"Asia/Tokyo","asn":"16509","as_desc":"Amazon.com, Inc.","user_agent":"curl/7.58.0"}
```

#### Endpoints
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [29-29]

The description of the demo setup mentions "an reverse proxy" which should be corrected to "a reverse proxy" for grammatical accuracy.

- this demo is behind an reverse proxy with https enabled
+ this demo is behind a reverse proxy with https enabled

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [29-29]

There's a minor typographical error with "http traffic" which should be capitalized as "HTTP traffic" for consistency with standard terminology.

- http traffic will be redirected to use https
+ HTTP traffic will be redirected to use https

📝 NOTE
This review was outside the diff hunks, and no overlapping diff hunk was found. Original lines [49-49]

The phrase "pass the it to the container" seems to contain an extra word. It should be corrected for clarity.

- set up an `X-Real-IP` header and pass the it to the container
+ set up an `X-Real-IP` header and pass it to the container

@PeterDaveHello PeterDaveHello self-requested a review April 2, 2024 17:19
README.md Outdated
@@ -46,7 +46,7 @@ Run the server daemon via docker:
docker run -d --name ipinfo.tw -p 80:8080 peterdavehello/ipinfo.tw:latest
```

If you want to put this container behind reverse proxy, set up an `X-Real-IP` header and pass the it to the container, so that it can use the header as the IP of the client.
If you want to put this container behind reverse proxy, set up an `X-Real-IP` header and pass it to the container, so that it can use the header as the IP of the client.
Copy link
Owner

Choose a reason for hiding this comment

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

This is not related to the changes in the PR, we should leave it alone.

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 this pull request may close these issues.

None yet

2 participants