|
15 | 15 |
|
16 | 16 | from dreadnode.api.models import ( |
17 | 17 | AccessRefreshTokenResponse, |
| 18 | + ContainerRegistryCredentials, |
18 | 19 | DeviceCodeResponse, |
19 | 20 | ExportFormat, |
20 | 21 | GithubTokenResponse, |
21 | 22 | MetricAggregationType, |
22 | 23 | Project, |
23 | 24 | RawRun, |
24 | 25 | RawTask, |
| 26 | + RegistryImageDetails, |
25 | 27 | Run, |
26 | 28 | RunSummary, |
27 | 29 | StatusFilter, |
@@ -710,3 +712,55 @@ def get_user_data_credentials(self) -> UserDataCredentials: |
710 | 712 | """ |
711 | 713 | response = self._request("GET", "/user-data/credentials") |
712 | 714 | return UserDataCredentials(**response.json()) |
| 715 | + |
| 716 | + # Container registry access |
| 717 | + |
| 718 | + def get_container_registry_credentials(self) -> ContainerRegistryCredentials: |
| 719 | + """ |
| 720 | + Retrieves container registry credentials for Docker image access. |
| 721 | +
|
| 722 | + Returns: |
| 723 | + The container registry credentials object. |
| 724 | + """ |
| 725 | + response = self.request("POST", "/platform/registry-token") |
| 726 | + return ContainerRegistryCredentials(**response.json()) |
| 727 | + |
| 728 | + def get_platform_releases( |
| 729 | + self, tag: str, services: list[str], cli_version: str | None |
| 730 | + ) -> RegistryImageDetails: |
| 731 | + """ |
| 732 | + Resolves the platform releases for the current project. |
| 733 | +
|
| 734 | + Returns: |
| 735 | + The resolved platform releases as a ResolveReleasesResponse object. |
| 736 | + """ |
| 737 | + payload = { |
| 738 | + "tag": tag, |
| 739 | + "services": services, |
| 740 | + "cli_version": cli_version, |
| 741 | + } |
| 742 | + try: |
| 743 | + response = self.request("POST", "/platform/get-releases", json_data=payload) |
| 744 | + |
| 745 | + except RuntimeError as e: |
| 746 | + if "403" in str(e): |
| 747 | + raise RuntimeError("You do not have access to platform releases.") from e |
| 748 | + |
| 749 | + if "404" in str(e): |
| 750 | + if "Image not found" in str(e): |
| 751 | + raise RuntimeError("Image not found") from e |
| 752 | + |
| 753 | + raise RuntimeError( |
| 754 | + f"Failed to get platform releases: {e}. The feature is likely disabled on this server" |
| 755 | + ) from e |
| 756 | + raise |
| 757 | + return RegistryImageDetails(**response.json()) |
| 758 | + |
| 759 | + def get_platform_templates(self, tag: str) -> bytes: |
| 760 | + """ |
| 761 | + Retrieves the available platform templates. |
| 762 | + """ |
| 763 | + params = {"tag": tag} |
| 764 | + response = self.request("GET", "/platform/templates/all", params=params) |
| 765 | + zip_content: bytes = response.content |
| 766 | + return zip_content |
0 commit comments