Initial work to create and delete droplets

This commit is contained in:
TC Johnson 2025-03-01 12:54:15 -06:00
parent f79198c545
commit 86076c8700
13 changed files with 481 additions and 0 deletions

View file

@ -0,0 +1,20 @@
import aiohttp
import sys
async def test_api_credentials(token: str) -> None:
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json",
}
url = "https://api.digitalocean.com/v2/droplets"
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as resp:
if resp.status == 200:
data = await resp.json()
droplets = data.get("droplets", [])
print("API credentials are valid.")
print(f"Retrieved {len(droplets)} droplet(s).")
else:
error_text = await resp.text()
print("Failed to authenticate API credentials:", error_text, file=sys.stderr)
sys.exit(error_text)