From 730bb594459d4e29cd93c25e505baf7bcca39e53 Mon Sep 17 00:00:00 2001 From: crisog Date: Mon, 15 Jan 2024 14:31:39 -0400 Subject: [PATCH] feat: region loading + bucket url --- stateless/cli/commands/buckets.py | 34 +++++++++++++++++++---------- stateless/cli/models/entrypoints.py | 5 +++++ stateless/cli/utils.py | 7 ++++++ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/stateless/cli/commands/buckets.py b/stateless/cli/commands/buckets.py index 0b2f1db..ec028d8 100644 --- a/stateless/cli/commands/buckets.py +++ b/stateless/cli/commands/buckets.py @@ -7,7 +7,12 @@ from ..models.buckets import BucketCreate, BucketUpdate from ..routes import V1Routes -from ..utils import make_request_with_api_key, parse_config_file, user_guard +from ..utils import ( + get_route_by_chain_id, + make_request_with_api_key, + parse_config_file, + user_guard, +) from .offerings import OfferingsManager console = Console() @@ -66,6 +71,7 @@ def buckets_list(): "\n".join( [f"{offering['provider']['name']}" for offering in bucket["offerings"]] ), + f"https://api.stateless.solutions/{get_route_by_chain_id(int(bucket['chain_id']))}/v1/{bucket['id']}", ) for bucket in buckets ] @@ -110,7 +116,10 @@ def buckets_create(config_file: Optional[str] = Option(None, "--config-file", "- json_response = response.json() if response.status_code == 201: - console.print(f"Successfully created bucket {json_response['id']}") + chain_route = get_route_by_chain_id(int(chain_id)) + console.print( + f"Your bucket has been created, and your URL is: https://api.stateless.solutions/{chain_route}/v1/{json_response['id']}" + ) else: console.print(f"Error creating bucket: {json_response['detail']}") @@ -122,22 +131,22 @@ def buckets_update( ): user_guard() if not bucket_id: - bucket = BucketsManager._select_bucket( - "Choose the bucket to update" - ) + bucket = BucketsManager._select_bucket("Choose the bucket to update") bucket_id = bucket["id"] bucket_name = bucket["name"] bucket_chain_id = bucket["chain"]["chain_id"] - bucket_offerings_ids = [ - offering["id"] for offering in bucket["offerings"] - ] + bucket_offerings_ids = [offering["id"] for offering in bucket["offerings"]] if config_file: bucket_update = parse_config_file(config_file, BucketUpdate) else: - name = inquirer.text(message="Enter the updated name of the bucket", default=bucket_name) + name = inquirer.text( + message="Enter the updated name of the bucket", default=bucket_name + ) offering_ids = OfferingsManager._select_offerings( - "Choose the offerings to associate with the bucket", int(bucket_chain_id), bucket_offerings_ids + "Choose the offerings to associate with the bucket", + int(bucket_chain_id), + bucket_offerings_ids, ) bucket_update = BucketUpdate(name=name, offerings=offering_ids) @@ -173,15 +182,16 @@ def buckets_get( bucket["chain"]["name"], "\n".join( [ - f"{offering['provider']['name']}" + f"{offering['provider']['name']} [{', '.join([entrypoint['region']['name'] for entrypoint in offering['entrypoints']])}]" for offering in bucket["offerings"] ] ), + f"https://api.stateless.solutions/{get_route_by_chain_id(int(bucket['chain_id']))}/v1/{bucket['id']}", ) for bucket in [json_response] ] - BucketsManager._print_table(items, ["ID", "Name", "Chain", "Offerings"]) + BucketsManager._print_table(items, ["ID", "Name", "Chain", "Offerings", "URL"]) else: console.print(f"Error getting bucket: {json_response['detail']}") diff --git a/stateless/cli/models/entrypoints.py b/stateless/cli/models/entrypoints.py index cafcf26..5aa4cd8 100644 --- a/stateless/cli/models/entrypoints.py +++ b/stateless/cli/models/entrypoints.py @@ -1,13 +1,18 @@ from datetime import datetime +from typing import Optional from pydantic import UUID4, BaseModel, ConfigDict, Field +from .regions import RegionFullResponse + class EntrypointNoURLResponse(BaseModel): model_config = ConfigDict(from_attributes=True) offering_id: UUID4 region_id: UUID4 + + region: Optional[RegionFullResponse] created_at: datetime updated_at: datetime diff --git a/stateless/cli/utils.py b/stateless/cli/utils.py index d040f66..90f5ba1 100644 --- a/stateless/cli/utils.py +++ b/stateless/cli/utils.py @@ -12,6 +12,11 @@ console = Console() +CHAINS_MAPPING = { + 1: "ethereum", + 137: "polygon", + 10: "optimism", +} def get_api_key_from_env(): api_key = os.environ.get("STATELESS_API_KEY") @@ -23,6 +28,8 @@ def get_api_key_from_env(): return return api_key +def get_route_by_chain_id(chain_id: int): + return CHAINS_MAPPING[chain_id] def get_account_type(): response = make_request_with_api_key("GET", V1Routes.ACCOUNT_PROFILE)