Skip to content

Commit

Permalink
Merge pull request #320 from microbiomedata/319-remove-obsolete-re-id…
Browse files Browse the repository at this point in the history
…ing-code

Remove obsolete re-iding code
  • Loading branch information
mbthornton-lbl authored Jan 9, 2025
2 parents 533932c + bfc17b2 commit 114255c
Show file tree
Hide file tree
Showing 163 changed files with 61 additions and 554,527 deletions.
8 changes: 4 additions & 4 deletions badges/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions badges/tests.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion nmdc_automation/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .nmdcapi import NmdcRuntimeApi, NmdcRuntimeUserApi
from .nmdcapi import NmdcRuntimeApi
119 changes: 0 additions & 119 deletions nmdc_automation/api/nmdcapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,125 +396,6 @@ def run_query(self, query):
return resp.json()


# TODO - This is deprecated and should be removed along with the re_iding code that uses it
class NmdcRuntimeUserApi:
"""
Basic Runtime API Client with user/password authentication.
"""
def __init__(self, site_configuration):
self.config = UserConfig(site_configuration)

self.username = self.config.username
self.password = self.config.password
self.base_url = self.config.base_url
self.headers = {}
self.token_response = None
self.refresh_token_after = None

def ensure_token(self):
if (self.refresh_token_after is None or datetime.now(timezone.utc) >
self.refresh_token_after):
self.get_token()
def get_token(self):
token_request_body = {
"grant_type": "password",
"username": self.username,
"password": self.password,
"scope": '',
"client_id": "",
"client_secret": "",
}
headers = {
'accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
}
rv = requests.post(
self.base_url + "token", data=token_request_body
)
self.token_response = rv.json()
if "access_token" not in self.token_response:
raise Exception(f"Getting token failed: {self.token_response}")

self.headers[
"Authorization"] = f'Bearer {self.token_response["access_token"]}'
self.refresh_token_after = expiry_dt_from_now(
**self.token_response["expires"]
) - timedelta(seconds=5)

def request(self, method, url_path, params_or_json_data=None):
self.ensure_token()
kwargs = {"url": self.base_url + url_path, "headers": self.headers}
if isinstance(params_or_json_data, BaseModel):
params_or_json_data = params_or_json_data.dict(exclude_unset=True)
if method.upper() == "GET":
kwargs["params"] = params_or_json_data
else:
kwargs["json"] = params_or_json_data
rv = requests.request(method, **kwargs)
rv.raise_for_status()
return rv

def run_query(self, query: dict):
"""
Function to run a query using the Microbiome Data API.
Parameters:
query (dict): The query to be run in JSON format.
Returns:
dict: The response from the API.
"""

self.ensure_token()
url = f"{self.base_url}queries:run"

response = requests.post(url, json=query, headers=self.headers)
return response.json()

def validate_record(self, record: dict):
"""
Function to validate a record using the Microbiome Data API.
Parameters:
record (dict): The record to be validated.
Returns:
dict: The response from the API.
"""

self.ensure_token()
url = f"{self.base_url}metadata/json:validate"

response = requests.post(url, json=record, headers=self.headers)
# check for validation failure
if response.status_code == 422:
logging.error(f"Validation failed for record: {record}")
logging.error(response.json())
response.raise_for_status()
return response.json()

def submit_record(self, record: dict):
"""
Function to submit a record using the Microbiome Data API.
Parameters:
record (dict): The record to be submitted.
Returns:
dict: The response from the API.
"""

self.ensure_token()
url = f"{self.base_url}metadata/json:submit"

response = requests.post(url, json=record, headers=self.headers)
# check if we already have it:
if response.status_code == 409:
logging.debug(f"Record already exists: {response.json()}")
return
response.raise_for_status()
return response.json()

def jprint(obj):
print(json.dumps(obj, indent=2))

Expand Down
12 changes: 6 additions & 6 deletions nmdc_automation/jgi_file_staging/models.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
from pydantic import BaseModel
from datetime import datetime
from typing import Optional
from typing import Optional, List


class Sample(BaseModel):
project: str
apGoldId: str
studyId: str
itsApId: str
itsApId: int
projects: str
biosample_id: str
seq_id: str
file_name: str
file_status: str
file_size: int
jdp_file_id: str
md5sum: Optional[str]
md5sum: Optional[str] = None
analysis_project_id: str
create_date: datetime = datetime.now()
update_date: Optional[datetime]
request_id: Optional[str]
update_date: Optional[datetime] = None
request_id: Optional[str] = None
Empty file.
112 changes: 0 additions & 112 deletions nmdc_automation/nmdc_common/client.py

This file was deleted.

Empty file.
Loading

0 comments on commit 114255c

Please sign in to comment.