From e7ff043d51c293b48d09c2ed685c12487fdc6bd4 Mon Sep 17 00:00:00 2001 From: Trey Stafford Date: Mon, 11 Nov 2024 14:57:31 -0700 Subject: [PATCH] Harmony api: use `EarthdataAuthMixin` --- icepyx/core/harmony.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/icepyx/core/harmony.py b/icepyx/core/harmony.py index cc812b00..33274a5a 100644 --- a/icepyx/core/harmony.py +++ b/icepyx/core/harmony.py @@ -2,13 +2,22 @@ import harmony +from icepyx.core.auth import EarthdataAuthMixin -def get_capabilities(concept_id: str) -> dict[str, Any]: - capabilities_request = harmony.CapabilitiesRequest(concept_id=concept_id) - # TODO: This will work if the user has a .netrc file available but the other - # auth options might fail. We might need to add harmony client auth to the - # icepyx auth package. - harmony_client = harmony.Client() - response = harmony_client.submit(capabilities_request) - return response +class HarmonyApi(EarthdataAuthMixin): + def __init__(self): + # initialize authentication properties + EarthdataAuthMixin.__init__(self) + self.harmony_client = harmony.Client( + auth=( + self.auth.username, + self.auth.password, + ), + ) + + def get_capabilities(self, concept_id: str) -> dict[str, Any]: + capabilities_request = harmony.CapabilitiesRequest(concept_id=concept_id) + response = self.harmony_client.submit(capabilities_request) + + return response