2023-05-03 23:24:18 +00:00
|
|
|
"""SporeStack API request/response models"""
|
2022-02-10 21:47:57 +00:00
|
|
|
|
|
|
|
|
2023-03-15 04:06:30 +00:00
|
|
|
from datetime import datetime
|
|
|
|
from enum import Enum
|
2023-04-13 00:01:33 +00:00
|
|
|
from typing import Dict, List, Optional, Union
|
2022-02-10 21:47:57 +00:00
|
|
|
|
2023-02-08 21:05:34 +00:00
|
|
|
from pydantic import BaseModel, Field
|
2022-02-10 21:47:57 +00:00
|
|
|
|
2023-04-14 21:57:08 +00:00
|
|
|
from .models import Flavor, OperatingSystem, Payment
|
2022-02-10 21:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TokenAdd:
|
|
|
|
url = "/token/{token}/add"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
class Request(BaseModel):
|
|
|
|
currency: str
|
|
|
|
dollars: int
|
2023-05-03 23:24:18 +00:00
|
|
|
affiliate_token: Union[str, None] = None
|
2022-02-10 21:47:57 +00:00
|
|
|
|
|
|
|
class Response(BaseModel):
|
|
|
|
token: str
|
|
|
|
payment: Payment
|
|
|
|
|
|
|
|
|
|
|
|
class TokenBalance:
|
|
|
|
url = "/token/{token}/balance"
|
|
|
|
method = "GET"
|
|
|
|
|
|
|
|
class Response(BaseModel):
|
|
|
|
token: str
|
|
|
|
cents: int
|
|
|
|
usd: str
|
|
|
|
|
|
|
|
|
2023-02-08 21:05:34 +00:00
|
|
|
class ServerQuote:
|
|
|
|
url = "/server/quote"
|
|
|
|
method = "GET"
|
|
|
|
|
|
|
|
"""Takes days and flavor as parameters."""
|
|
|
|
|
|
|
|
class Response(BaseModel):
|
|
|
|
cents: int = Field(
|
|
|
|
default=..., ge=1, title="Cents", description="(US) cents", example=1_000_00
|
|
|
|
)
|
|
|
|
usd: str = Field(
|
|
|
|
default=...,
|
|
|
|
min_length=5,
|
|
|
|
title="USD",
|
|
|
|
description="USD in $1,000.00 format",
|
|
|
|
example="$1,000.00",
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2022-02-10 21:47:57 +00:00
|
|
|
class ServerLaunch:
|
|
|
|
url = "/server/{machine_id}/launch"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
class Request(BaseModel):
|
|
|
|
days: int
|
|
|
|
flavor: str
|
|
|
|
ssh_key: str
|
|
|
|
operating_system: str
|
2022-04-01 22:56:17 +00:00
|
|
|
region: Optional[str] = None
|
2022-06-14 02:40:11 +00:00
|
|
|
"""null is automatic, otherwise a string region slug."""
|
2022-09-07 21:40:02 +00:00
|
|
|
token: str
|
2022-06-14 02:40:11 +00:00
|
|
|
"""Token to draw from when launching the server."""
|
|
|
|
hostname: str = ""
|
|
|
|
"""Hostname to refer to your server by."""
|
2022-09-07 21:40:02 +00:00
|
|
|
autorenew: bool = False
|
|
|
|
"""
|
|
|
|
Automatically renew the server with the token used, keeping it at 1 week
|
|
|
|
expiration.
|
|
|
|
"""
|
2022-02-10 21:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServerTopup:
|
|
|
|
url = "/server/{machine_id}/topup"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
class Request(BaseModel):
|
|
|
|
days: int
|
2023-04-13 00:01:33 +00:00
|
|
|
token: Union[str, None] = None
|
2022-02-10 21:47:57 +00:00
|
|
|
|
|
|
|
|
2023-05-03 23:24:18 +00:00
|
|
|
class ServerDeletedBy(str, Enum):
|
|
|
|
EXPIRATION = "expiration"
|
|
|
|
"""The server was deleted automatically for being expired."""
|
|
|
|
MANUAL = "manual"
|
|
|
|
"""The server was deleted before its expiration via the API."""
|
|
|
|
SPORESTACK = "sporestack"
|
|
|
|
"""The server was deleted by SporeStack, likely due to an AUP violation."""
|
|
|
|
|
|
|
|
|
2022-02-10 21:47:57 +00:00
|
|
|
class ServerInfo:
|
|
|
|
url = "/server/{machine_id}/info"
|
|
|
|
method = "GET"
|
|
|
|
|
|
|
|
class Response(BaseModel):
|
|
|
|
created_at: int
|
|
|
|
expiration: int
|
|
|
|
running: bool
|
|
|
|
machine_id: str
|
2022-09-27 18:52:36 +00:00
|
|
|
token: str
|
2022-06-14 02:40:11 +00:00
|
|
|
ipv4: str
|
|
|
|
ipv6: str
|
2022-02-10 21:47:57 +00:00
|
|
|
region: str
|
2022-06-14 02:40:11 +00:00
|
|
|
flavor: Flavor
|
|
|
|
deleted: bool
|
2023-03-29 01:51:06 +00:00
|
|
|
deleted_at: int
|
2023-05-03 23:24:18 +00:00
|
|
|
deleted_by: Union[ServerDeletedBy, None]
|
|
|
|
forgotten_at: Union[datetime, None]
|
2022-06-14 02:40:11 +00:00
|
|
|
operating_system: str
|
|
|
|
hostname: str
|
2022-09-07 21:40:02 +00:00
|
|
|
autorenew: bool
|
2022-02-10 21:47:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServerStart:
|
|
|
|
url = "/server/{machine_id}/start"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
|
|
|
|
class ServerStop:
|
|
|
|
url = "/server/{machine_id}/stop"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
|
|
|
|
class ServerDelete:
|
2023-05-03 23:24:18 +00:00
|
|
|
url = "/server/{machine_id}"
|
|
|
|
method = "DELETE"
|
2022-09-07 21:40:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class ServerForget:
|
|
|
|
url = "/server/{machine_id}/forget"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
|
2022-02-10 21:47:57 +00:00
|
|
|
class ServerRebuild:
|
|
|
|
url = "/server/{machine_id}/rebuild"
|
|
|
|
method = "POST"
|
2022-06-14 02:40:11 +00:00
|
|
|
|
|
|
|
|
2022-09-27 18:52:36 +00:00
|
|
|
class ServerEnableAutorenew:
|
|
|
|
url = "/server/{machine_id}/autorenew/enable"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
|
|
|
|
class ServerDisableAutorenew:
|
|
|
|
url = "/server/{machine_id}/autorenew/disable"
|
|
|
|
method = "POST"
|
|
|
|
|
|
|
|
|
2022-06-14 02:40:11 +00:00
|
|
|
class ServersLaunchedFromToken:
|
|
|
|
url = "/token/{token}/servers"
|
|
|
|
method = "GET"
|
|
|
|
|
|
|
|
class Response(BaseModel):
|
|
|
|
servers: List[ServerInfo.Response]
|
|
|
|
|
|
|
|
|
|
|
|
class Flavors:
|
|
|
|
url = "/flavors"
|
|
|
|
method = "GET"
|
|
|
|
|
|
|
|
class Response(BaseModel):
|
2022-11-02 00:00:00 +00:00
|
|
|
flavors: Dict[str, Flavor]
|
2022-09-07 23:07:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class OperatingSystems:
|
|
|
|
url = "/operatingsystems"
|
|
|
|
method = "GET"
|
|
|
|
|
|
|
|
class Response(BaseModel):
|
2023-04-14 21:57:08 +00:00
|
|
|
operating_systems: Dict[str, OperatingSystem]
|
2023-03-15 04:06:30 +00:00
|
|
|
|
|
|
|
|
2023-03-29 01:51:06 +00:00
|
|
|
class TokenMessageSender(str, Enum):
|
2023-03-15 04:06:30 +00:00
|
|
|
USER = "User"
|
|
|
|
SPORESTACK = "SporeStack"
|
|
|
|
|
|
|
|
|
|
|
|
class TokenMessage(BaseModel):
|
|
|
|
message: str = Field(
|
|
|
|
...,
|
|
|
|
title="Message",
|
|
|
|
min_length=1,
|
|
|
|
max_length=10_000,
|
|
|
|
)
|
|
|
|
sent_at: datetime = Field(
|
|
|
|
...,
|
|
|
|
title="Sent At",
|
|
|
|
description="When the message was sent.",
|
|
|
|
)
|
|
|
|
sender: TokenMessageSender = Field(
|
|
|
|
..., title="Sender", description="Who sent the message."
|
|
|
|
)
|