Skip to content

Update ldas.py#42

Merged
timcera merged 2 commits into
timcera:mainfrom
tbongiov:main
May 29, 2026
Merged

Update ldas.py#42
timcera merged 2 commits into
timcera:mainfrom
tbongiov:main

Conversation

@tbongiov
Copy link
Copy Markdown
Contributor

@tbongiov tbongiov commented May 29, 2026

Fixed token-remove expires statement from token

Summary by Sourcery

Bug Fixes:

  • Strip expiry and other metadata from the raw token string before using it in LDAS time series requests.

Fixed token-remove expires statement from token
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 29, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the LDAS token handling so that only the core token value (without the leading fields and trailing character) is used after retrieval, before constructing the time series request URL.

Flow diagram for updated LDAS token handling

flowchart TD
    A["Retrieve raw token string<br>from HTTP response"] --> B[Replace double quotes in token]
    B --> C["Split token by colon<br>using split(':')"]
    C --> D[Select element index 2]
    D --> E["Remove last character<br>using slice :-1"]
    E --> F["Use cleaned token<br>for time_series_url requests"]
Loading

File-Level Changes

Change Details Files
Normalize the LDAS authentication token after it is retrieved from the HTTP response.
  • Post-process the token string returned from the request by splitting on ':' and selecting the third segment
  • Strip the last character from the selected token segment before further use in the function
src/tsgettoolbox/functions/ldas.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The token = token.split(':')[2][:-1] parsing is quite brittle (assumes a specific format and at least three segments); consider validating the format and handling unexpected cases or using a structured parser if available.
  • If the token format can change or include additional colons, a more robust approach (e.g., splitting once on a known prefix or using regex to extract the token value) would reduce the risk of index or slicing errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `token = token.split(':')[2][:-1]` parsing is quite brittle (assumes a specific format and at least three segments); consider validating the format and handling unexpected cases or using a structured parser if available.
- If the token format can change or include additional colons, a more robust approach (e.g., splitting once on a known prefix or using regex to extract the token value) would reduce the risk of index or slicing errors.

## Individual Comments

### Comment 1
<location path="src/tsgettoolbox/functions/ldas.py" line_range="1145" />
<code_context>
         allow_redirects=True,
     ).text.replace('"', "")
-
+    token=token.split(':')[2][:-1]
     time_series_url = "https://api.giovanni.earthdata.nasa.gov/timeseries"

</code_context>
<issue_to_address>
**issue (bug_risk):** The token parsing logic is brittle and may raise on unexpected formats.

This line assumes the token string always has at least three colon-separated parts and blindly strips the last character. If the format changes (different colon count, trailing whitespace, or missing colon), it may raise IndexError or corrupt the token. Please make the parsing more defensive, e.g., validate the split result, use `partition`/`rpartition`, and trim whitespace instead of slicing by index.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/tsgettoolbox/functions/ldas.py Outdated
Fix token extraction by parsing JSON
@timcera timcera merged commit 15a34b0 into timcera:main May 29, 2026
77 of 85 checks passed
@timcera
Copy link
Copy Markdown
Owner

timcera commented May 29, 2026

Thank you! Folded this change into commits on the "develop" branch.

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.

2 participants