0

I would like to get the Secret value from given SecretID using Python API's. I have folowing code. On the last line I am trying to get the SECRET_VERSION using get_secret_versions function. The function returns SecretItemPaged type of Object. Can someone please help to to retrieve secret_version from this objet.

#!/usr/bin/python
from azure.keyvault import KeyVaultClient
    from azure.common.credentials import ServicePrincipalCredentials
    import pprint
    #from msrestazure.azure_active_directory import 
    ServicePrincipalCredentials



credentials = ServicePrincipalCredentials(
      client_id = 'XXX',
      secret = 'XXX',
      tenant = 'XXX'
)

client = KeyVaultClient(credentials)

    VAULT_URL='https://xxxxxxx.vault.azure.net'
    SECRET_ID='https://xxxxxxxx.vault.azure.net/secrets/2345mat'
    SECRET_VERSION= client.get_secret_versions(VAULT_URL , SECRET_ID)
FZs
  • 16,581
  • 13
  • 41
  • 50
Agnihotra
  • 1
  • 1

1 Answers1

0

SecretItemPaged is an iterator of objects, following the Python protocol for this: https://docs.python.org/3/glossary.html#term-iterable https://docs.python.org/3/glossary.html#term-iterator

That being said, you can then use a list to consume it, or a next call until you get a StopIteration object, etc.

Simplest way would be to consume it as a list:

list(client.get_secret_versions(VAULT_URL , SECRET_ID))
Laurent Mazuel
  • 3,422
  • 13
  • 27