Skip to content

Instantly share code, notes, and snippets.

@llamasoft
Created September 27, 2019 00:43
Show Gist options
  • Save llamasoft/ab5724feddf1580cde1ac16f5065a98e to your computer and use it in GitHub Desktop.
Save llamasoft/ab5724feddf1580cde1ac16f5065a98e to your computer and use it in GitHub Desktop.
HVAC Clobber Demo
import hvac
import pprint
client = hvac.Client("http://localhost:8200")
# Make sure the test user doesn't exist
client.secrets.identity.delete_entity_by_name("clobber-demo")
# Create the user with a set of policies and metadata
client.secrets.identity.create_or_update_entity_by_name(
name = "clobber-demo",
policies = ["policy-one", "policy-two"],
metadata = {
"old": "value"
}
)
# Note that both `policies` and `metadata` are present
resp = client.secrets.identity.read_entity_by_name(name = "clobber-demo")
print("Newly created Entity:")
pprint.pprint(resp["data"])
print("")
# Update the metadata field...
client.secrets.identity.create_or_update_entity_by_name(
name = "clobber-demo",
metadata = {
"new": "data"
}
)
# ... `metadata` has been updated but `policies` has been clobbered
resp = client.secrets.identity.read_entity_by_name(name = "clobber-demo")
print("Updated metadata:")
pprint.pprint(resp["data"])
print("")
# Updating the policies...
client.secrets.identity.create_or_update_entity_by_name(
name = "clobber-demo",
policies = ["policy-three", "policy-four"]
)
# ... and now `metadata` has been clobbered
resp = client.secrets.identity.read_entity_by_name(name = "clobber-demo")
print("Updated policies:")
pprint.pprint(resp["data"])
print("")
# Updating the metadata manually...
client._adapter.post(
url = "/v1/identity/entity/name/clobber-demo",
json = {
"metadata": {"newest": "text"}
}
)
# ... only the metadata has changed (yay!)
resp = client.secrets.identity.read_entity_by_name(name = "clobber-demo")
print("Manually updated metadata:")
pprint.pprint(resp["data"])
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment