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

Extend type of Chart ref to work with OCI protocol correctly #2

Open
NikPaushkin opened this issue Jan 3, 2023 · 4 comments
Open

Comments

@NikPaushkin
Copy link

HTTP links are only allowed now here https://github.com/stackhpc/pyhelm3/blob/main/pyhelm3/models.py#L185. Could use simple str type or implement a custom one since Pydantic (and nobody tbh) doesn't know what OCI protocol is.

@NikPaushkin
Copy link
Author

@mkjpryor Hey, do you accept any pull requests?

@mkjpryor
Copy link
Collaborator

mkjpryor commented Jul 6, 2023

@NikPaushkin We would welcome a PR to implement this!

Rather than accepting all strings, you should be able to define an OCI URI using stricturl in Pydantic, which can then be added to the union. Something like:

OciUrl = stricturl(allowed_schemes = {"oci"})

This would be my preferred method.

https://docs.pydantic.dev/1.10/usage/types/#urls

denis-ikomia added a commit to denis-ikomia/pyhelm3 that referenced this issue Jan 19, 2024
@nalyat
Copy link

nalyat commented Oct 10, 2024

@mkjpryor any feedback on the PR? Is there a reason not to merge this one? There's multiple PR's referencing the same issue(#4)

@isbalashov
Copy link

For anyone looking for a workaround consider monkeypatching Client.get_chart(). Here is what I came up with:

from pyhelm3 import Client, Chart
import typing as t
from typing_extensions import Annotated
from pydantic import (
    Field,
    DirectoryPath,
    FilePath,
    HttpUrl,
)

Name = Annotated[str, Field(pattern=r"^[a-z0-9-]+$")]
OCIPath = Annotated[str, Field(pattern=r"oci:\/\/*")]

class OCIChart(Chart):
    ref: t.Union[DirectoryPath, FilePath, HttpUrl, OCIPath, Name] = Field(
        ...,
    )

async def get_chart_oci(self, chart_ref, *, devel=False, repo=None, version=None):
    metadata = await self._command.show_chart(
        chart_ref,
        devel=devel,
        repo=repo,
        version=version
    )
    return OCIChart(
        _command=self._command,
        ref=chart_ref,
        repo=repo,
        metadata=metadata
    )


# Monkey patch the get_chart method of the Client class
Client.get_chart = get_chart_oci
client = Client()

voidlily pushed a commit to GSA-TTS/pyhelm3 that referenced this issue Dec 9, 2024
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

No branches or pull requests

4 participants