Skip to content

Commit

Permalink
fall back on PMG_MAPI_KEY (#1841)
Browse files Browse the repository at this point in the history
* fall back on PMG_MAPI_KEY

* client: add apikey to error msg

* client: allow no apikey through
  • Loading branch information
tschaume authored Oct 17, 2024
1 parent 6846d7d commit 12fa6c4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion mpcontribs-client/mpcontribs/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
from plotly.express._chart_types import line as line_chart
from cachetools import cached, LRUCache
from cachetools.keys import hashkey
from pymatgen.core import SETTINGS

RETRIES = 3
MAX_WORKERS = 3
Expand Down Expand Up @@ -886,7 +887,9 @@ def __init__(
host = os.environ.get("MPCONTRIBS_API_HOST", DEFAULT_HOST)

if not apikey:
apikey = os.environ.get("MPCONTRIBS_API_KEY")
apikey = os.environ.get("MPCONTRIBS_API_KEY", SETTINGS.get("PMG_MAPI_KEY"))
if apikey and len(apikey) != 32:
raise MPContribsClientError(f"Invalid API key: {apikey}")

if apikey and headers:
apikey = None
Expand Down

2 comments on commit 12fa6c4

@hongyi-zhao
Copy link

@hongyi-zhao hongyi-zhao commented on 12fa6c4 Oct 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have another question: Can the MPCONTRIBS_API_KEY be a valid value different from PMG_MAPI_KEY?

@tschaume
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it can. MPCONTRIBS_API_KEY will be checked first and only if the environment variable isn't present it'll fall back on PMG_MAPI_KEY from .pmgrc.yaml. HTH.

Please sign in to comment.