Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions neonUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
import time
import os
from tenacity import retry, stop_after_attempt, wait_fixed, retry_if_exception_type

if os.environ.get("USER") == "ec2-user" or os.environ.get("LAMBDA_TASK_ROOT"):
from aws_ssm import N_APIkey, N_APIuser
Expand Down Expand Up @@ -320,6 +321,20 @@ def fixTypes(account: dict):
return account


@retry(
stop=stop_after_attempt(3),
wait=wait_fixed(5),
retry=retry_if_exception_type(ValueError),
before_sleep=lambda rs: logging.warning("Neon search returned %s, retrying...", rs.outcome.exception()),
)
def _neon_search(data):
url = N_baseURL + "/accounts/search"
response = requests.post(url, json=data, headers=N_headers)
if response.status_code != 200:
raise ValueError(f"Post {url} returned status code {response.status_code}: {response.text}")
return response


####################################################################
# Get Neon accounts matching given criteria
####################################################################
Expand Down Expand Up @@ -366,11 +381,7 @@ def getNeonAccounts(searchFields, neonAccountDict={}):
"pagination": {"currentPage": page, "pageSize": 200},
}

url = N_baseURL + "/accounts/search"
response = requests.post(url, json=data, headers=N_headers)

if response.status_code != 200:
raise ValueError(f"Post {url} returned status code {response.status_code}: {response.text}")
response = _neon_search(data)

logging.info("Fetching Accounts: %s", response.json().get("pagination"))
# re-shuffle the data into a format that's a little easier to work with
Expand Down
Loading