Skip to content

Commit

Permalink
Merge pull request #37 from brightway-lca/ecoquery-client
Browse files Browse the repository at this point in the history
Make ecoinvent SSO client id configurable
  • Loading branch information
cmutel authored Nov 25, 2024
2 parents a512158 + 4f027ab commit c7d6d22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ecoinvent_interface/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ def __init__(
self.password = settings.password
if not self.password:
raise ValueError("Missing password; see configurations docs")
self.client_id = settings.client_id
if not self.client_id:
raise ValueError("Missing client_id; see configurations docs")

self.urls = URLS if urls is None else urls
self.custom_headers = custom_headers or {}
Expand All @@ -84,6 +87,7 @@ def __init__(
Instance ID: {id(self)}
Version: {__version__}
User: {self.username}
Client ID: {self.client_id}
Output directory: {self.storage.dir}
Custom headers: {bool(custom_headers)}
Custom URLs: {bool(urls)}
Expand All @@ -94,31 +98,33 @@ def login(self) -> None:
post_data = {
"username": self.username,
"password": self.password,
"client_id": "apollo-ui",
"client_id": self.client_id,
"grant_type": "password",
}
self._get_credentials(post_data)
message = """Got initial credentials.
message = f"""Got initial credentials.
Class: {self.__class__.__name__}
Instance ID: {id(self)}
Version: {__version__}
User: {self.username}
Client ID: {self.client_id}
"""
logger.debug(message)

@logged_in
def refresh_tokens(self) -> None:
post_data = {
"client_id": "apollo-ui",
"client_id": self.client_id,
"grant_type": "refresh_token",
"refresh_token": self.refresh_token,
}
self._get_credentials(post_data)
message = """Renewed credentials.
message = f"""Renewed credentials.
Class: {self.__class__.__name__}
Instance ID: {id(self)}
Version: {__version__}
User: {self.username}
Client ID: {self.client_id}
"""
logger.debug(message)

Expand Down Expand Up @@ -164,12 +170,13 @@ def _get_all_reports(self) -> dict:
"ecoinvent-api-client-library-version": __version__,
}
headers.update(self.custom_headers)
message = """Requesting URL.
message = f"""Requesting URL.
URL: {reports_url}
Class: {self.__class__.__name__}
Instance ID: {id(self)}
Version: {__version__}
User: {self.username}
Client ID: {self.client_id}
"""
logger.debug(message)
return requests.get(reports_url, headers=headers, timeout=20).json()
Expand All @@ -183,12 +190,13 @@ def _get_all_files(self) -> dict:
"ecoinvent-api-client-library-version": __version__,
}
headers.update(self.custom_headers)
message = """Requesting URL.
message = f"""Requesting URL.
URL: {files_url}
Class: {self.__class__.__name__}
Instance ID: {id(self)}
Version: {__version__}
User: {self.username}
Client ID: {self.client_id}
"""
logger.debug(message)
return requests.get(files_url, headers=headers, timeout=20).json()
Expand Down
1 change: 1 addition & 0 deletions ecoinvent_interface/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Settings(BaseSettings):

username: Optional[str] = None
password: Optional[str] = None
client_id: str = "brightway-ei"
output_path: Optional[str] = None


Expand Down

0 comments on commit c7d6d22

Please sign in to comment.