Get a token
Obtain a token
One of the key operations of a Vault is to retrieve Pangea API tokens stored in the Vault for use by your application code.
import os
import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.services import Vault
def get_token(token_id):
token = os.getenv("PANGEA_VAULT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)
vault = Vault(token, config=config)
token_data = None
try:
# if no version is specified curent_version is returned
response = vault.get(token_id)
# tokens are stored as secrets
token_data = response.result.current_version.secret
except pe.PangeaAPIException as e:
print(f"Vault Request Error: {e.response.summary}")
for err in e.errors:
print(f"\t{err.detail} \n")
return token_data
Was this article helpful?