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

feat: Add Client for File Service #65

Merged
merged 46 commits into from
Sep 17, 2024
Merged

Conversation

santhoshramaraj
Copy link
Member

@santhoshramaraj santhoshramaraj commented Jul 1, 2024

What does this Pull Request accomplish?

  • Add Client for the File Service
  • Add support for basic File Service APIs
  • Add a basic back-off-retry mechanism for FileClient
    @retry(when=retry.when.status(429), stop=retry.stop.after_attempt(5))
    class FileClient(BaseClient):
    Uplink uses exponential backoff by default.

Why should this Pull Request be merged?

Improve Developer Experience by using nisystemlink-clients instead of systemlink-sdk, which is installed with the SystemLink Client application.

What testing has been done?

  • Integration tests were implemented and tested against the test tier.
  • Manual testing of back-off-retry logic by commenting out the logic and run integration tests on dev machine against test tier.

@santhoshramaraj santhoshramaraj added the enhancement New feature or request label Aug 5, 2024
@santhoshramaraj santhoshramaraj changed the title feat: Client for File Service feat: Add Client for File Service Aug 12, 2024
examples/file/download_file.py Outdated Show resolved Hide resolved
nisystemlink/clients/file/_file_client.py Show resolved Hide resolved
nisystemlink/clients/file/models/_file_metadata.py Outdated Show resolved Hide resolved
nisystemlink/clients/file/models/_file_metadata.py Outdated Show resolved Hide resolved
tests/integration/file/test_file_client.py Outdated Show resolved Hide resolved
tests/integration/file/test_file_client.py Outdated Show resolved Hide resolved
tests/integration/file/test_file_client.py Outdated Show resolved Hide resolved
tests/integration/file/test_file_client.py Outdated Show resolved Hide resolved
@santhoshramaraj
Copy link
Member Author

@adamarnesen refactored and added all key APIs for FileClient

nisystemlink/clients/file/_file_client.py Outdated Show resolved Hide resolved
return IteratorFileLike(response.iter_content(chunk_size=4096))


@retry(when=retry.when.status(429), stop=retry.stop.after_attempt(5))
Copy link
Contributor

Choose a reason for hiding this comment

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

@spanglerco Do you know if we have guidance/conventions for HTTP resilience strategies? How many times should we retry?

nisystemlink/clients/file/_file_client.py Show resolved Hide resolved
class FileQueryResponse(JsonModel):
"""The result of a file query"""

field_links: Dict[str, Link] = Field(alias="_links")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why can't we just call this field links? Also, I wonder if we should even return these links to users. The only way you could use them is by making a manual HTTP request, which kind of defeats the purpose of having the client.

Copy link
Member Author

Choose a reason for hiding this comment

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

The bottleneck to leave out _links is that the conftest.py forbids extra fields in the response compared to the Pydantic model.

JsonModel.Config.extra = Extra.forbid

nisystemlink/clients/file/models/_file_query_response.py Outdated Show resolved Hide resolved
nisystemlink/clients/file/_file_client.py Show resolved Hide resolved
nisystemlink/clients/file/_file_client.py Outdated Show resolved Hide resolved
nisystemlink/clients/file/_file_client.py Outdated Show resolved Hide resolved
nisystemlink/clients/file/_file_client.py Outdated Show resolved Hide resolved
Example - {"Name": "myfile.txt", "MyProperty": "Value"}
"""

meta_data_revision: Optional[int] = Field(None, alias="metaDataRevision", example=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

metadata isn't typically broken into two words

Copy link
Member Author

Choose a reason for hiding this comment

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

It looks like the API implemented it as metaDataRevision and hence only meta_data_revision will result in a working automatic case conversion.

nisystemlink/clients/file/models/_operations.py Outdated Show resolved Hide resolved
return parts[-1]


def rename_file(client: FileClient, file_id: str, name: str) -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Our clients have been mostly 1 to 1 with the HTTP API, but I think I'd rather this be a method on the FileClient itself instead of a separate function.

tests/integration/file/test_file_client.py Show resolved Hide resolved
@santhoshramaraj santhoshramaraj merged commit ebdc4c1 into master Sep 17, 2024
6 checks passed
@santhoshramaraj santhoshramaraj deleted the users/sramaraj/file-client branch September 17, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants