init
This commit is contained in:
23
python/mrds_common/mrds/utils/vault.py
Normal file
23
python/mrds_common/mrds/utils/vault.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import oci
|
||||
import ast
|
||||
import base64
|
||||
|
||||
# Specify the OCID of the secret to retrieve
|
||||
|
||||
|
||||
def get_password(ocid):
|
||||
|
||||
# Create vaultsclient using the default config file (\.oci\config) for auth to the API
|
||||
signer = signer = oci.auth.signers.InstancePrincipalsSecurityTokenSigner()
|
||||
|
||||
# Get the secret
|
||||
secretclient = oci.secrets.SecretsClient({}, signer=signer)
|
||||
secretcontents = secretclient.get_secret_bundle(secret_id=ocid)
|
||||
|
||||
# Decode the secret from base64 and print
|
||||
keybase64 = secretcontents.data.secret_bundle_content.content
|
||||
keybase64bytes = keybase64.encode("ascii")
|
||||
keybytes = base64.b64decode(keybase64bytes)
|
||||
key = keybytes.decode("ascii")
|
||||
keydict = ast.literal_eval(key)
|
||||
return keydict["password"]
|
||||
Reference in New Issue
Block a user