Fix: accounts type filter, sites endpoint, remove partner_accounts
This commit is contained in:
@@ -37,31 +37,35 @@ def snapshot(host, port, user, password):
|
|||||||
base = f"https://{host}:{port}/api/v2.0"
|
base = f"https://{host}:{port}/api/v2.0"
|
||||||
auth = base64.b64encode(f"{user}:{password}".encode()).decode()
|
auth = base64.b64encode(f"{user}:{password}".encode()).decode()
|
||||||
|
|
||||||
# Accounts
|
# Accounts — no type filter (type=individual is invalid; all accounts returned, categorised client-side)
|
||||||
accts_raw = api_get(base, "/accounts?type=individual&limit=100", auth)
|
accts_raw = api_get(base, "/accounts?limit=200", auth)
|
||||||
accts = []
|
accts = []
|
||||||
|
partners = []
|
||||||
for a in accts_raw if isinstance(accts_raw, list) else accts_raw.get("result", []):
|
for a in accts_raw if isinstance(accts_raw, list) else accts_raw.get("result", []):
|
||||||
accts.append({
|
locked = a.get("user", {}).get("locked", False) if isinstance(a.get("user"), dict) else False
|
||||||
|
entry = {
|
||||||
"name": a.get("name"),
|
"name": a.get("name"),
|
||||||
"type": a.get("type"),
|
"type": a.get("type"),
|
||||||
"status": "locked" if a.get("locked") else "active"
|
"status": "locked" if locked else "active"
|
||||||
})
|
}
|
||||||
|
# Partner accounts have routingMode set and no transferType=N pattern; use name heuristic or type field
|
||||||
|
# In ST v5, partner accounts show type=user but have a distinct homeFolderAccessLevel pattern.
|
||||||
|
# Most reliable: include all non-service accounts and let caller filter.
|
||||||
|
if a.get("type") in ("user",):
|
||||||
|
accts.append(entry)
|
||||||
|
# Note: ST does not expose a dedicated partner-account type via this API; list all user accounts.
|
||||||
|
|
||||||
# Partner accounts
|
# Partner sites — correct endpoint is /sites (not /transfers/sites)
|
||||||
partners_raw = api_get(base, "/accounts?type=partner&limit=100", auth)
|
sites_raw = api_get(base, "/sites?limit=100", auth)
|
||||||
partners = []
|
|
||||||
for a in partners_raw if isinstance(partners_raw, list) else partners_raw.get("result", []):
|
|
||||||
partners.append({"name": a.get("name"), "type": "partner"})
|
|
||||||
|
|
||||||
# Partner sites (transfer sites)
|
|
||||||
sites_raw = api_get(base, "/transfers/sites?limit=100", auth)
|
|
||||||
sites = []
|
sites = []
|
||||||
for s in sites_raw if isinstance(sites_raw, list) else sites_raw.get("result", []):
|
for s in sites_raw if isinstance(sites_raw, list) else sites_raw.get("result", []):
|
||||||
sites.append({
|
sites.append({
|
||||||
"name": s.get("name"),
|
"name": s.get("name"),
|
||||||
"type": s.get("type"),
|
"type": s.get("type"),
|
||||||
"partner": s.get("partnerAccount"),
|
"partner": s.get("partner"),
|
||||||
"protocol": s.get("protocol")
|
"protocol": s.get("protocol"),
|
||||||
|
"host": s.get("host"),
|
||||||
|
"port": s.get("port")
|
||||||
})
|
})
|
||||||
|
|
||||||
# Certificates (filter to PGP and SSH)
|
# Certificates (filter to PGP and SSH)
|
||||||
@@ -95,7 +99,6 @@ def snapshot(host, port, user, password):
|
|||||||
return {
|
return {
|
||||||
"host": host,
|
"host": host,
|
||||||
"accounts": accts,
|
"accounts": accts,
|
||||||
"partner_accounts": partners,
|
|
||||||
"partner_sites": sites,
|
"partner_sites": sites,
|
||||||
"certificates": certs,
|
"certificates": certs,
|
||||||
"applications": apps,
|
"applications": apps,
|
||||||
@@ -107,7 +110,8 @@ def validate_spec_prerequisites(snapshot_data, prereqs):
|
|||||||
missing = []
|
missing = []
|
||||||
|
|
||||||
acct_names = {a["name"] for a in snapshot_data.get("accounts", [])}
|
acct_names = {a["name"] for a in snapshot_data.get("accounts", [])}
|
||||||
partner_names = {a["name"] for a in snapshot_data.get("partner_accounts", [])}
|
# partner_accounts merged into accounts in v2; check against acct_names
|
||||||
|
acct_names_all = acct_names
|
||||||
site_names = {s["name"] for s in snapshot_data.get("partner_sites", [])}
|
site_names = {s["name"] for s in snapshot_data.get("partner_sites", [])}
|
||||||
cert_map = {c["name"]: c for c in snapshot_data.get("certificates", [])}
|
cert_map = {c["name"]: c for c in snapshot_data.get("certificates", [])}
|
||||||
|
|
||||||
@@ -116,7 +120,7 @@ def validate_spec_prerequisites(snapshot_data, prereqs):
|
|||||||
missing.append(f"Account '{a['name']}' not found")
|
missing.append(f"Account '{a['name']}' not found")
|
||||||
|
|
||||||
for p in prereqs.get("partner_accounts", []):
|
for p in prereqs.get("partner_accounts", []):
|
||||||
if p["name"] not in partner_names:
|
if p["name"] not in acct_names:
|
||||||
missing.append(f"Partner account '{p['name']}' not found")
|
missing.append(f"Partner account '{p['name']}' not found")
|
||||||
|
|
||||||
for s in prereqs.get("partner_sites", []):
|
for s in prereqs.get("partner_sites", []):
|
||||||
|
|||||||
Reference in New Issue
Block a user