Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 36 additions & 54 deletions docs/sdk/api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -505,37 +505,6 @@ def export_timeseries(
```


</Accordion>

### get\_container\_registry\_credentials

```python
get_container_registry_credentials() -> (
ContainerRegistryCredentials
)
```

Retrieves container registry credentials for Docker image access.

**Returns:**

* `ContainerRegistryCredentials`
–The container registry credentials object.

<Accordion title="Source code in dreadnode/api/client.py" icon="code">
```python
def get_container_registry_credentials(self) -> ContainerRegistryCredentials:
"""
Retrieves container registry credentials for Docker image access.

Returns:
The container registry credentials object.
"""
response = self.request("POST", "/platform/registry-token")
return ContainerRegistryCredentials(**response.json())
```


</Accordion>

### get\_device\_codes
Expand Down Expand Up @@ -577,13 +546,44 @@ def get_github_access_token(self, repos: list[str]) -> GithubTokenResponse:
```


</Accordion>

### get\_platform\_registry\_credentials

```python
get_platform_registry_credentials() -> (
ContainerRegistryCredentials
)
```

Retrieves container registry credentials for Docker image access.

**Returns:**

* `ContainerRegistryCredentials`
–The container registry credentials object.

<Accordion title="Source code in dreadnode/api/client.py" icon="code">
```python
def get_platform_registry_credentials(self) -> ContainerRegistryCredentials:
"""
Retrieves container registry credentials for Docker image access.

Returns:
The container registry credentials object.
"""
response = self.request("POST", "/platform/registry-token")
return ContainerRegistryCredentials(**response.json())
```


</Accordion>

### get\_platform\_releases

```python
get_platform_releases(
tag: str, services: list[str], cli_version: str | None
tag: str, services: list[str]
) -> RegistryImageDetails
```

Expand All @@ -596,35 +596,17 @@ Resolves the platform releases for the current project.

<Accordion title="Source code in dreadnode/api/client.py" icon="code">
```python
def get_platform_releases(
self, tag: str, services: list[str], cli_version: str | None
) -> RegistryImageDetails:
def get_platform_releases(self, tag: str, services: list[str]) -> RegistryImageDetails:
"""
Resolves the platform releases for the current project.

Returns:
The resolved platform releases as a ResolveReleasesResponse object.
"""
payload = {
"tag": tag,
"services": services,
"cli_version": cli_version,
}
try:
response = self.request("POST", "/platform/get-releases", json_data=payload)

except RuntimeError as e:
if "403" in str(e):
raise RuntimeError("You do not have access to platform releases.") from e

if "404" in str(e):
if "Image not found" in str(e):
raise RuntimeError("Image not found") from e
from dreadnode.version import VERSION

raise RuntimeError(
f"Failed to get platform releases: {e}. The feature is likely disabled on this server"
) from e
raise
payload = {"tag": tag, "services": services, "cli_version": VERSION}
response = self.request("POST", "/platform/get-releases", json_data=payload)
return RegistryImageDetails(**response.json())
```

Expand Down
6 changes: 4 additions & 2 deletions docs/sdk/main.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,13 @@ def configure(
# Log config information for clarity
if self.server or self.token or self.local_dir:
destination = self.server or DEFAULT_SERVER_URL or "local storage"
rich.print(f"Dreadnode logging to [orange_red1]{destination}[/] ({config_source})")
logging_console.print(
f"Dreadnode logging to [orange_red1]{destination}[/] ({config_source})"
)

# Warn the user if the profile didn't resolve
elif active_profile and not (self.server or self.token):
rich.print(
logging_console.print(
f":exclamation: Dreadnode profile [orange_red1]{active_profile}[/] appears invalid."
)

Expand Down
28 changes: 5 additions & 23 deletions dreadnode/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def get_user_data_credentials(self) -> UserDataCredentials:

# Container registry access

def get_container_registry_credentials(self) -> ContainerRegistryCredentials:
def get_platform_registry_credentials(self) -> ContainerRegistryCredentials:
"""
Retrieves container registry credentials for Docker image access.

Expand All @@ -736,35 +736,17 @@ def get_container_registry_credentials(self) -> ContainerRegistryCredentials:
response = self.request("POST", "/platform/registry-token")
return ContainerRegistryCredentials(**response.json())

def get_platform_releases(
self, tag: str, services: list[str], cli_version: str | None
) -> RegistryImageDetails:
def get_platform_releases(self, tag: str, services: list[str]) -> RegistryImageDetails:
"""
Resolves the platform releases for the current project.

Returns:
The resolved platform releases as a ResolveReleasesResponse object.
"""
payload = {
"tag": tag,
"services": services,
"cli_version": cli_version,
}
try:
response = self.request("POST", "/platform/get-releases", json_data=payload)

except RuntimeError as e:
if "403" in str(e):
raise RuntimeError("You do not have access to platform releases.") from e

if "404" in str(e):
if "Image not found" in str(e):
raise RuntimeError("Image not found") from e
from dreadnode.version import VERSION

raise RuntimeError(
f"Failed to get platform releases: {e}. The feature is likely disabled on this server"
) from e
raise
Comment on lines -748 to -767
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 only removed this as I think it's a poor pattern to reflect in the API client code. Might be aggressive to remove clarity from the errors for users - open to moving this somewhere else in the CLI

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I was considering how best to provide thoughtful errors in a "public" SDk that attempts to access "private" features?

payload = {"tag": tag, "services": services, "cli_version": VERSION}
response = self.request("POST", "/platform/get-releases", json_data=payload)
return RegistryImageDetails(**response.json())

def get_platform_templates(self, tag: str) -> bytes:
Expand Down
Loading
Loading