Skip to content

Commit ed34cbc

Browse files
committed
feat(CLI): add pay info subcommand to show payment info for cluster
1 parent 7d06ed7 commit ed34cbc

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

silverback/_cli.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,35 @@ def create_payment_stream(
743743
)
744744

745745

746+
@pay.command(name="info")
747+
@click.argument("cluster_path", metavar="CLUSTER")
748+
@platform_client()
749+
def get_payment_info(platform: "PlatformClient", cluster_path: str):
750+
"""Display streaming payment information for the given CLUSTER"""
751+
from silverback.cluster.types import ResourceStatus
752+
753+
if "/" not in cluster_path or len(cluster_path.split("/")) > 2:
754+
raise click.BadArgumentUsage(f"Invalid cluster path: '{cluster_path}'")
755+
756+
workspace_name, cluster_name = cluster_path.split("/")
757+
if not (workspace_client := platform.workspaces.get(workspace_name)):
758+
raise click.BadArgumentUsage(f"Unknown workspace: '{workspace_name}'")
759+
760+
elif not (cluster := workspace_client.clusters.get(cluster_name)):
761+
raise click.BadArgumentUsage(
762+
f"Unknown cluster in workspace '{workspace_name}': '{cluster_name}'"
763+
)
764+
765+
elif cluster.status != ResourceStatus.RUNNING:
766+
raise click.UsageError(f"Cannot fund '{cluster.name}': cluster is not running.")
767+
768+
elif stream_info := workspace_client.get_stream_info(cluster):
769+
click.echo(f"Cluster is funded via '{stream_info}'.")
770+
771+
else:
772+
click.echo("Cluster is not funded via ApePay Stream")
773+
774+
746775
@pay.command(name="add-time", cls=ConnectedProviderCommand)
747776
@account_option()
748777
@click.argument("cluster_path", metavar="CLUSTER")

silverback/cluster/types.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ class StreamInfo(BaseModel):
247247
manager: AddressType
248248
stream_id: int
249249

250+
def __str__(self) -> str:
251+
return f"eip155:{self.chain_id}:{self.manager}/{self.stream_id}"
252+
250253

251254
class ClusterInfo(BaseModel):
252255
# NOTE: Raw API object (gets exported)

0 commit comments

Comments
 (0)