Skip to content

refactor(auth): collapse 5 Dataverse Web API helpers into a shared _dv_request #132

@daeunJe0ng

Description

@daeunJe0ng

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:

  1. _validate_https_url(env_url)
  2. headers = {"Authorization": f"Bearer {token}", ...}
  3. URL prefix {env_url}/api/data/v9.2/...
  4. 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

  • All existing tests pass without modification (no test should depend on the internal preamble shape).
  • ruff check solutions/ess-maker-skills/scripts/ clean.
  • Five public function signatures unchanged.
  • 401 → AuthExpiredError and _validate_https_url are called exactly once per request.

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions