Background
Follow-up to PR #128 review feedback from @qazi-microsoft (last comment on the PR).
solutions/ess-maker-skills/scripts/auth.py now has five sibling functions that each issue a single authenticated Dataverse Web API request:
| Function |
Line |
Method |
query_all |
188 |
GET (paged) |
dataverse_get |
220 |
GET (single) |
update_record |
275 |
PATCH |
create_record |
297 |
POST |
delete_record |
315 |
DELETE |
Each duplicates the same ~4-line preamble:
_validate_https_url(env_url)
headers = {"Authorization": f"Bearer {token}", ...}
- URL prefix
{env_url}/api/data/v9.2/...
401 → AuthExpiredError mapping
PR #128 did not make this duplication worse — dataverse_get follows the same convention as the existing four — but the duplication is now five-fold instead of four-fold.
Proposal
Introduce a private _dv_request(env_url, token, method, path, *, params=None, json=None, extra_headers=None) helper that owns the preamble + the 401 mapping. Rewrite the five public functions as thin wrappers (one for paging, four for single-call verbs).
Out of scope
- Public signatures of the five exported functions must not change (they are consumed across
flightcheck/, bootstrap/, etc.).
- Retry behaviour for
query_all (urllib3 retry adapter on 5xx) must be preserved.
Acceptance criteria
References
Background
Follow-up to PR #128 review feedback from @qazi-microsoft (last comment on the PR).
solutions/ess-maker-skills/scripts/auth.pynow has five sibling functions that each issue a single authenticated Dataverse Web API request:query_alldataverse_getupdate_recordcreate_recorddelete_recordEach duplicates the same ~4-line preamble:
_validate_https_url(env_url)headers = {"Authorization": f"Bearer {token}", ...}{env_url}/api/data/v9.2/...401 → AuthExpiredErrormappingPR #128 did not make this duplication worse —
dataverse_getfollows the same convention as the existing four — but the duplication is now five-fold instead of four-fold.Proposal
Introduce a private
_dv_request(env_url, token, method, path, *, params=None, json=None, extra_headers=None)helper that owns the preamble + the 401 mapping. Rewrite the five public functions as thin wrappers (one for paging, four for single-call verbs).Out of scope
flightcheck/,bootstrap/, etc.).query_all(urllib3 retry adapter on 5xx) must be preserved.Acceptance criteria
ruff check solutions/ess-maker-skills/scripts/clean.AuthExpiredErrorand_validate_https_urlare called exactly once per request.References