Skip to main content

Modify key state

Alter the state of a key

A key can be in an enabled or disabled state.

Disabling a key

Disabling a key prevents all versions of a key from being used. When a key is in the disabled state, only the following actions can be performed:

  • Update/Retrieve metadata
  • Deleting the key

import os

import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.services import Vault
from pangea.services.vault.models.common import ItemState


def disable_key(key_id):
token = os.getenv("PANGEA_VAULT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)
vault = Vault(token, config=config)

try:
vault.update(key_id, item_state=ItemState.DISABLED)

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

Enabling a key

Enabling a key restores all previous functionality to a key, and its versions.


import os

import pangea.exceptions as pe
from pangea.config import PangeaConfig
from pangea.services import Vault
from pangea.services.vault.models.common import ItemState


def enable_key(key_id):
token = os.getenv("PANGEA_VAULT_TOKEN")
domain = os.getenv("PANGEA_DOMAIN")
config = PangeaConfig(domain=domain)
vault = Vault(token, config=config)

try:
vault.update(key_id, item_state=ItemState.ENABLED)

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

Was this article helpful?

Contact us