Switched to HVAC Agent instead of connecting to the vault directly
This commit is contained in:
parent
b2af6fe289
commit
f8c9820e2c
@ -1,27 +1,13 @@
|
|||||||
import base64
|
|
||||||
import hvac
|
import hvac
|
||||||
|
import base64
|
||||||
|
import os
|
||||||
|
|
||||||
|
HVAC_AGENT_URL = os.getenv("HVAC_AGENT_URL","http://vault-agent:8201")
|
||||||
client = hvac.Client(
|
client = hvac.Client(url=HVAC_AGENT_URL)
|
||||||
url='http://127.0.0.1:8200',
|
|
||||||
token='root'
|
|
||||||
)
|
|
||||||
|
|
||||||
def encrypt_token(token: str) -> str:
|
def encrypt_token(token: str) -> str:
|
||||||
response = client.secrets.transit.encrypt_data(
|
response = client.secrets.transit.encrypt_data(
|
||||||
name='push-tokens',
|
name='push-tokens',
|
||||||
plaintext=base64.b64encode(token.encode()).decode()
|
plaintext=base64.b64encode(token.encode()).decode()
|
||||||
)
|
)
|
||||||
return response['data']['ciphertext']
|
return response['data']['ciphertext']
|
||||||
|
|
||||||
|
|
||||||
# Decrypt a device token (for worker use)
|
|
||||||
def decrypt_token(ciphertext: str) -> str:
|
|
||||||
response = client.secrets.transit.decrypt_data(
|
|
||||||
name='push-tokens',
|
|
||||||
ciphertext=ciphertext
|
|
||||||
)
|
|
||||||
plaintext_b64 = response['data']['plaintext']
|
|
||||||
return base64.b64decode(plaintext_b64).decode()
|
|
||||||
|
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user