Skip to content

Add RecordsAPI with write operations#2501

Open
Magssch wants to merge 3 commits intomainfrom
feat/records-api
Open

Add RecordsAPI with write operations#2501
Magssch wants to merge 3 commits intomainfrom
feat/records-api

Conversation

@Magssch
Copy link
Contributor

@Magssch Magssch commented Feb 12, 2026

Description

Add client API layer for CDF Records, supporting ingest, upsert, and delete operations scoped to streams. This is the first step toward records upload support in the toolkit. Download support to follow later.

Bump

  • Patch
  • Skip

@gemini-code-assist
Copy link
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

@Magssch
Copy link
Contributor Author

Magssch commented Feb 12, 2026

/gemini review

@Magssch Magssch requested review from a team as code owners February 12, 2026 09:12
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the RecordsAPI to enable ingest, upsert, and delete operations for records within CDF streams. A critical finding is a path traversal vulnerability in the ingest, upsert, and delete methods. This occurs because the stream_id is used to construct the API endpoint URL without proper encoding, potentially allowing an attacker to manipulate the request path. Despite this, the implementation is well-structured, includes necessary client API layers, new resource classes (RecordIdentifier, RecordSource, RecordRequest, RecordResponse), and dedicated unit tests, adhering well to the repository's style guide. Other aspects, such as data models and client initialization, appear secure.


def ingest(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
"""Ingest records into a stream.

Copy link
Contributor

Choose a reason for hiding this comment

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

security-high high

The stream_id parameter is directly concatenated into the URL path using an f-string. This can lead to path traversal vulnerabilities if the stream_id contains characters like ../. An attacker could potentially manipulate the URL to hit unintended API endpoints. It is recommended to URL-encode the stream_id using urllib.parse.quote(stream_id, safe='') to ensure it is treated as a single path segment. Note: You will need to import quote from urllib.parse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd lean towards this not really being a issue due to the worst case scenario being a malformed / invalid API request that would be rejected anyways

endpoint = f"/streams/{stream_id}/records"
self._request_no_response(items, "create", endpoint=endpoint)

def upsert(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
Copy link
Collaborator

@doctrino doctrino Feb 12, 2026

Choose a reason for hiding this comment

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

I try to use create,retrieve, delete, update as far as possible even for upsert endpoints.

Suggested change
def upsert(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
def update(self, stream_id: str, items: Sequence[RecordRequest]) -> None:

endpoint = f"/streams/{stream_id}/records"
self._request_no_response(items, "create", endpoint=endpoint)

def upsert(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Lets move stream_id innto the RecordRequest, see how it is solved for RawAPI

Comment on lines +41 to +51
def upsert(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
"""Upsert records into a stream (create or update).

Args:
stream_id: The external ID of the stream to upsert records into.
items: Sequence of RecordRequest items to upsert.
"""
endpoint = f"/streams/{stream_id}/records/upsert"
self._request_no_response(items, "upsert", endpoint=endpoint)

def delete(self, stream_id: str, items: Sequence[RecordIdentifier]) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same here, move stream_id into RecordIdentifier.

) -> PagedResponse[RecordResponse]:
return PagedResponse[RecordResponse].model_validate_json(response.body)

def ingest(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Try to standardize

Suggested change
def ingest(self, stream_id: str, items: Sequence[RecordRequest]) -> None:
def create(self, stream_id: str, items: Sequence[RecordRequest]) -> None:

Copy link
Collaborator

@doctrino doctrino left a comment

Choose a reason for hiding this comment

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

You also need to create smoke tests for records.

One questions. The difference between ingest and upsert is that one allows pre-existing records?

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