Skip to content

Commit

Permalink
Change to longer-lived JWT's.
Browse files Browse the repository at this point in the history
  • Loading branch information
Schalk1e committed Nov 18, 2024
1 parent 7b3f09c commit 4cfcec1
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 26 deletions.
34 changes: 34 additions & 0 deletions rdw_ingestion_tools/api/content_repo/requests/assessments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from attrs import define
from httpx import Client
from pandas import DataFrame

from api import concatenate

from ..extensions.httpx import get_paginated


@define
class Assessments:
"""Dedicated to the Assessments endpoint of the Content Repo API"""

client: Client

def get_assessments(self, max_pages: int = 5) -> DataFrame:
"""Get a pandas DataFrame of Content Repo assessments.
No time-based query parameters are supported by the endpoint.
Full set of assessments accessible via pagination.
"""

url = "assessments"

assessments_generator = get_paginated(
client=self.client,
url=url,
max_pages=max_pages,
)

assessments = concatenate(assessments_generator)

return assessments
28 changes: 2 additions & 26 deletions rdw_ingestion_tools/api/turn_bq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,11 @@

from .. import config_from_env

USER = config_from_env("TURN_BQ_API_USER")
PASS = config_from_env("TURN_BQ_API_PASS")
API_KEY = config_from_env("TURN_BQ_API_KEY")
BASE_URL = config_from_env("TURN_BQ_API_BASE_URL")

token_request_headers = {
"accept": "application/json",
"Content-Type": "application/x-www-form-urlencoded",
}

token_request_data = {
"grant_type": "password",
"username": f"{USER}",
"password": f"{PASS}",
"client_id": "",
"client_secret": "",
}

token_response = Client().post(
url=f"{BASE_URL}/token",
headers=token_request_headers,
data=token_request_data,
)

token_response.raise_for_status()

access_token = token_response.json()["access_token"]

session_headers = {
"Authorization": f"Bearer {access_token}",
"Authorization": f"Bearer {API_KEY}",
"Accept": "application/vnd.v1+json",
"Content-Type": "application/json",
}
Expand Down

0 comments on commit 4cfcec1

Please sign in to comment.