Skip to main content

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: str) -> str:
token = os.getenv("PANGEA_VAULT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)
vault = Vault(token, config=config)

try:
# If no version is specified, then the current version is returned.
response = vault.get(token_id)
except pe.PangeaAPIException as e:
print(f"Vault Request Error: {e.response.summary}")
for err in e.errors:
print(f"\t{err.detail} \n")
else:
# Tokens are stored as secrets.
return response.result.current_version.secret

Was this article helpful?

Contact us