Skip to content

Commit

Permalink
feat: region loading + bucket url
Browse files Browse the repository at this point in the history
  • Loading branch information
crisog committed Jan 15, 2024
1 parent bcc9edc commit 730bb59
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 12 deletions.
34 changes: 22 additions & 12 deletions stateless/cli/commands/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
]
Expand Down Expand Up @@ -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']}")

Expand All @@ -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)

Expand Down Expand Up @@ -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']}")

Expand Down
5 changes: 5 additions & 0 deletions stateless/cli/models/entrypoints.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions stateless/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand Down

0 comments on commit 730bb59

Please sign in to comment.