AzureKeyVault

Use the Azure Key Vault integration to safeguard and manage cryptographic keys and secrets used by cloud applications and services.

Authentication & Identity Management · Azure Key Vault

Details

IDAzureKeyVault
ProviderMicrosoft
CategoryAuthentication & Identity Management
From Version5.5.0
Docker Imagedemisto/crypto:1.0.0.10120494
Supported ModulesAgentix XSIAM Cloud Posture Security

README

Use the Azure Key Vault integration to safeguard and manage cryptographic keys and secrets used by cloud applications and services.
This integration was integrated and tested with version 2022-07-01 of AzureKeyVault.

Configure Azure Key Vault on Cortex XSOAR

  1. Navigate to Settings > Integrations > Servers & Services.
  2. Search for Azure Key Vault.
  3. Click Add instance to create and configure a new integration instance.

    Parameter Required
    Azure Cloud False
    Client ID False
    Client Secret False
    Tenant ID True
    Certificate Thumbprint False
    Private Key False
    Use Azure Managed Identities False
    Azure Managed Identities Client ID False
    Default Subscription ID True
    Default Resource Group Name True
    Fetches credentials False
    Credentials Fetch Mode False
    Key Vault names - comma-separated list of Key Vaults to fetch secrets from. False
    Secret names - comma-separated list of secrets to fetch. False
    Trust any certificate (not secure) False
    Use system proxy settings False
  4. Azure cloud options

    Azure Cloud Description
    Worldwide The publicly accessible Azure Cloud
    US GCC Azure cloud for the USA Government Cloud Community (GCC)
    US GCC-High Azure cloud for the USA Government Cloud Community High (GCC-High)
    DoD Azure cloud for the USA Department of Defense (DoD)
    Germany Azure cloud for the German Government
    China Azure cloud for the Chinese Government
  5. Click Test to validate the URLs, token, and connection.

Commands

You can execute these commands from the Cortex XSOAR CLI, as part of an automation, or in a playbook.
After you successfully execute a command, a DBot message appears in the War Room with the command details.

azure-key-vault-create-update


Create or update a key vault in the specified subscription. If the Key Vault exists, the updated properties will overwrite the existing ones. Please use azure-key-vault-access-policy-update command if you wish to update the access policy of an existing Key Vault.

Base Command

azure-key-vault-create-update

Input

Argument Name Description Required
vault_name Key Vault name. Required
location Key Vault supported Azure location. The location cannot be changed after the Key Vault is created. Default value is ‘westus’. Possible values are: northcentralus, eastus, northeurope, westeurope, eastasia, southeastasia, eastus2, centralus, southcentralus, westus, japaneast, japanwest, australiaeast, australiasoutheast, brazilsouth, centralindia, southindia, westindia, canadacentral, canadaeast, uksouth, ukwest, westcentralus, westus2, koreacentral, francecentral, australiacentral, uaenorth, southafricanorth, switzerlandnorth, germanywestcentral, norwayeast, westus3, jioindiawest. Optional
sku_name Specify whether the key vault is a standard vault or a premium vault. Default value is ‘standard’. Possible values are: standard, premium. Optional
object_id The object ID of a user, service principal or security group in the Entra ID tenant for the vault. The object ID must be unique for the list of access policies: Any change in the access policy regards that object ID, will override the exists one. To retrieve it navigate in the Azure Portal to App registrations > your registered application > click on manage application in local directory > copy Object ID property. Required
keys Permissions to keys. If the Key Vault exists, you must supply the previous keys’ permissions in order to keep them unchanged. Access policy property. Default value is [get,list,create,update,import,delete,backup,restore,recover]. . Possible values are: get, list, create, update, import, delete, backup, restore, recover, decrypt, encrypt, unwrapKey, wrapKey, verify, sign, purge. Optional
secrets Permissions to secrets. If the Key Vault exists, you must supply the previous secrets’ permissions in order to keep them unchanged. Access policy property. Default value is [get,list,set,delete,backup,restore,recover]. Possible values are: get, list, set, delete, recover, backup, restore, purge. Optional
certificates Permissions to certificates. If the Key Vault exists, you must supply the previous certificate’s permissions in order to keep them unchanged. Access policy property. Default value is [get,list,update,create,import,delete,recover,backup,restore,managecontacts,manageissuers,getissuers,listissuers,setissuers,deleteissuers]. Possible values are: get, list, update, create, import, delete, recover, backup, restore, managecontacts, manageissuers, getissuers, listissuers, setissuers, deleteissuers, purge. Optional
storage Permissions to storage accounts. If the Key Vault exists, you must supply the previous storage’s permissions in order to keep them unchanged. Access policy property. Default value is [get,list,set,delete,backup,restore,recover]. Possible values are: get, list, delete, set, update, regeneratekey, getsas, listsas, deletesas, setsas, recover, backup, restore, purge. Optional
enabled_for_deployment Specifies whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault. If the Key Vault exists, you must supply the previous value in order to keep it the same. Default value is True. Possible values are: true, false. Optional
enabled_for_disk_encryption Specifies whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.If the Key Vault exists, you must supply the previous value in order to keep it the same. Default value is True. Possible values are: true, false. Optional
enabled_for_template_deployment Specifies whether Azure Resource Manager is permitted to retrieve secrets from the key vault. If the Key Vault exists, you must supply the previous value in order to keep it the same. Default value is True. Possible values are: true, false. Optional
default_action The default action when no rule from ip_rules and from vnet_subnet_id match. For example, If no ip_rules and vnet_subnet_id arguments are supplied, the access to the key vault from any IP address or virtual network will be according to the default_action value. If you wish to allow access only from specific virtual network or IP address, use the ip_rules or the vnet_subnet_id arguments. This is only used after the bypass property has been evaluated. Network acl property. Possible values are: Allow, Deny. Optional
bypass Tells what traffic can bypass network rules. This can be ‘AzureServices’ or ‘None’. For example, use ‘AzureServices’ if you wish to give azure services access to key vault, although the default action is ‘Deny’ or the access for a specific IP address. Network acl property. Default value is ‘AzureServices’. Possible values are: AzureServices, None. Optional
vnet_subnet_id Allow accessibility of a vault from a specific virtual network. This argument must be the full resource ID of a virtual network subnet. For example, for the subnet ID “/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/virtualNetworks/test-vnet/subnets/subnet1”, you allow access to the Key Vault from subnet1. Network acl property. Optional
ignore_missing_vnet_service_endpoint Specifies whether the Network Resource Provider will ignore the check if parent subnet has serviceEndpoints configured. This allows the configuration for the Key Vault to complete without error before the configuration to the virtual network’s subnet is complete. Once the subnet configuration is complete, the Cosmos account will then be accessible through the configured subnet. Network Acl property. Possible values are: . Default is True. Optional
ip_rules The list of IP address rules. Each rule defines the accessibility of a vault from a specific IP address or IP range. It can be a simple IP address “124.56.78.91” or “124.56.78.0/24” - all addresses that start with 124.56.78. For example, for the IP addresses list: “124.56.78.91,124.56.78.92”, you can access the Key Vault from “124.56.78.91” or “124.56.78.92” IP addresses. Network acl property.  
subscription_id The subscription ID. Note: This argument will override the instance parameter ‘Subscription ID’. Optional
resource_group_name The resource group name. Note: This argument will override the instance parameter ‘Resource Group Name’. Optional

Context Output

Path Type Description
AzureKeyVault.KeyVault.id String Resource ID.
AzureKeyVault.KeyVault.name String Key Vault name.
AzureKeyVault.KeyVault.type String Resource type in Azure.
AzureKeyVault.KeyVault.location String Key Vault location.
AzureKeyVault.KeyVault.properties.sku.family String SKU family name.
AzureKeyVault.KeyVault.properties.sku.name String SKU name to specify whether the key vault is a standard vault or a premium vault.
AzureKeyVault.KeyVault.properties.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.KeyVault.properties.accessPolicies.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.KeyVault.properties.accessPolicies.objectId String The object ID of a user, service principal or security group in the Entra ID tenant for the vault. The object ID must be unique for the list of access policies.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.keys Unknown Permissions to keys.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.secrets Unknown Permissions to secrets.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.certificates Unknown Permissions to certificates.
AzureKeyVault.KeyVault.properties.enabledForDeployment Boolean Property to specify whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault.
AzureKeyVault.KeyVault.properties.enabledForDiskEncryption Boolean Property to specify whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.
AzureKeyVault.KeyVault.properties.enabledForTemplateDeployment Boolean Property to specify whether Azure Resource Manager is permitted to retrieve secrets from the key vault.
AzureKeyVault.KeyVault.properties.vaultUri String The URI of the vault for performing operations on keys and secrets.
AzureKeyVault.KeyVault.properties.provisioningState String The current provisioning state.

Command Example

!azure-key-vault-create-update object_id=YOUR_OBJECT_ID vault_name=xsoar-test-285 keys=create,decrypt

Context Example

{
    "AzureKeyVault": {
        "KeyVault": {
            "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-285",
            "location": "westus",
            "name": "xsoar-test-285",
            "properties": {
                "accessPolicies": [
                    {
                        "objectId": "YOUR_OBJECT_ID",
                        "permissions": {
                            "certificates": [
                                "get",
                                "list",
                                "update",
                                "create",
                                "import",
                                "delete",
                                "recover",
                                "backup",
                                "restore",
                                "managecontacts",
                                "manageissuers",
                                "getissuers",
                                "listissuers",
                                "setissuers",
                                "deleteissuers"
                            ],
                            "keys": [
                                "create",
                                "decrypt"
                            ],
                            "secrets": [
                                "get",
                                "list",
                                "set",
                                "delete",
                                "recover",
                                "backup",
                                "restore"
                            ],
                            "storage": [
                                "get",
                                "list",
                                "delete",
                                "set",
                                "update",
                                "regeneratekey",
                                "getsas",
                                "listsas"
                            ]
                        },
                        "tenantId": "YOUR_TENANT_ID"
                    }
                ],
                "enableSoftDelete": true,
                "enabledForDeployment": true,
                "enabledForDiskEncryption": true,
                "enabledForTemplateDeployment": true,
                "provisioningState": "Succeeded",
                "sku": {
                    "family": "A",
                    "name": "standard"
                },
                "tenantId": "YOUR_TENANT_ID",
                "vaultUri": "https://xsoar-test-285.vault.azure.net/"
            },
            "tags": {},
            "type": "Microsoft.KeyVault/vaults"
        }
    }
}

Human Readable Output

xsoar-test-285 Information

Id Name Type Location
/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-285 xsoar-test-285 Microsoft.KeyVault/vaults westus

azure-key-vault-delete


Delete the specified key vault.

Base Command

azure-key-vault-delete

Input

Argument Name Description Required
vault_name Key Vault name to delete. Required
subscription_id The subscription ID. Note: This argument will override the instance parameter ‘Subscription ID’. Optional
resource_group_name The resource group name. Note: This argument will override the instance parameter ‘Resource Group Name’. Optional

Context Output

There is no context output for this command.

Command Example

!azure-key-vault-delete vault_name=xsoar-test-262

Human Readable Output

Deleted Key Vault xsoar-test-262 successfully.

azure-key-vault-get


Get the specified key vault.

Base Command

azure-key-vault-get

Input

Argument Name Description Required
vault_name Key Vault name. Required
subscription_id The subscription ID. Note: This argument will override the instance parameter ‘Subscription ID’. Optional
resource_group_name The resource group name. Note: This argument will override the instance parameter ‘Resource Group Name’. Optional

Context Output

Path Type Description
AzureKeyVault.KeyVault.id String Resource ID.
AzureKeyVault.KeyVault.name String Key Vault name.
AzureKeyVault.KeyVault.type String Resource type in Azure.
AzureKeyVault.KeyVault.location String Key Vault location.
AzureKeyVault.KeyVault.properties.sku.family String SKU family name.
AzureKeyVault.KeyVault.properties.sku.name String SKU name to specify whether the key vault is a standard vault or a premium vault.
AzureKeyVault.KeyVault.properties.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.KeyVault.properties.accessPolicies.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.KeyVault.properties.accessPolicies.objectId String The object ID of a user, service principal or security group in the Entra ID tenant for the vault. The object ID must be unique for the list of access policies.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.keys Unknown Permissions to keys.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.secrets Unknown Permissions to secrets.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.certificates Unknown Permissions to certificates.
AzureKeyVault.KeyVault.properties.enabledForDeployment Boolean Property to specify whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault.
AzureKeyVault.KeyVault.properties.enabledForDiskEncryption Boolean Property to specify whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.
AzureKeyVault.KeyVault.properties.enabledForTemplateDeployment Boolean Property to specify whether Azure Resource Manager is permitted to retrieve secrets from the key vault.
AzureKeyVault.KeyVault.properties.enableSoftDelete Boolean Property to specify whether the ‘soft delete’ functionality is enabled for this key vault. If it’s not set to any value(true or false) when creating new key vault, it will be set to true by default. Once set to true, it cannot be reverted to false.
AzureKeyVault.KeyVault.properties.vaultUri String The URI of the vault for performing operations on keys and secrets. This property is readonly.

Command Example

!azure-key-vault-get vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "KeyVault": {
            "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-vault",
            "location": "eastus",
            "name": "xsoar-test-vault",
            "properties": {
                "accessPolicies": [
                    {
                        "objectId": "YOUR_OBJECT_ID",
                        "permissions": {
                            "certificates": [
                                "Get",
                                "List",
                                "Update",
                                "Create",
                                "Import",
                                "Delete",
                                "Recover",
                                "Backup",
                                "Restore",
                                "ManageContacts",
                                "ManageIssuers",
                                "GetIssuers",
                                "ListIssuers",
                                "SetIssuers",
                                "DeleteIssuers",
                                "Purge"
                            ],
                            "keys": [
                                "Get",
                                "List",
                                "Update",
                                "Create",
                                "Import",
                                "Delete",
                                "Recover",
                                "Backup",
                                "Restore",
                                "Decrypt",
                                "Encrypt",
                                "UnwrapKey",
                                "WrapKey",
                                "Verify",
                                "Sign",
                                "Purge"
                            ],
                            "secrets": [
                                "Get",
                                "List",
                                "Set",
                                "Delete",
                                "Recover",
                                "Backup",
                                "Restore",
                                "Purge"
                            ]
                        },
                        "tenantId": "YOUR_TENANT_ID"
                    }
                ],
                "enableRbacAuthorization": false,
                "enableSoftDelete": true,
                "enabledForDeployment": false,
                "enabledForDiskEncryption": false,
                "enabledForTemplateDeployment": false,
                "provisioningState": "Succeeded",
                "sku": {
                    "family": "A",
                    "name": "Standard"
                },
                "softDeleteRetentionInDays": 90,
                "tenantId": "YOUR_TENANT_ID",
                "vaultUri": "https://xsoar-test-vault.vault.azure.net/"
            },
            "tags": {},
            "type": "Microsoft.KeyVault/vaults"
        }
    }
}

Human Readable Output

xsoar-test-vault Information

Id Name Type Location
/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-vault xsoar-test-vault Microsoft.KeyVault/vaults eastus

azure-key-vault-list


The List operation gets information about the vaults associated with the subscription. For a limit greater than 25, more than one API call will be required and the command might take longer time.

Base Command

azure-key-vault-list

Input

Argument Name Description Required
limit Limit on the number of keys vaults to return. Default value is 50. Optional
offset First index to retrieve from. Default value is 0. Optional
subscription_id The subscription ID. Note: This argument will override the instance parameter ‘Subscription ID’. Optional

Context Output

Path Type Description
AzureKeyVault.KeyVault.id String Resource ID.
AzureKeyVault.KeyVault.name String Key Vault name.
AzureKeyVault.KeyVault.type String Resource type in Azure.
AzureKeyVault.KeyVault.location String Key Vault location.
AzureKeyVault.KeyVault.properties.sku.family String SKU family name.
AzureKeyVault.KeyVault.properties.sku.name String SKU name to specify whether the key vault is a standard vault or a premium vault.
AzureKeyVault.KeyVault.properties.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.KeyVault.properties.accessPolicies.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.KeyVault.properties.accessPolicies.objectId String The object ID of a user, service principal or security group in the Entra ID tenant for the vault. The object ID must be unique for the list of access policies.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.keys Unknown Permissions to keys.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.secrets Unknown Permissions to secrets.
AzureKeyVault.KeyVault.properties.accessPolicies.permissions.certificates Unknown Permissions to certificates.
AzureKeyVault.KeyVault.properties.enabledForDeployment Boolean Property to specify whether Azure Virtual Machines are permitted to retrieve certificates stored as secrets from the key vault.
AzureKeyVault.KeyVault.properties.enabledForDiskEncryption Boolean Property to specify whether Azure Disk Encryption is permitted to retrieve secrets from the vault and unwrap keys.
AzureKeyVault.KeyVault.properties.enabledForTemplateDeployment Boolean Property to specify whether Azure Resource Manager is permitted to retrieve secrets from the key vault.
AzureKeyVault.KeyVault.properties.enableSoftDelete Boolean Property to specify whether the ‘soft delete’ functionality is enabled for this key vault. If it’s not set to any value(true or false) when creating new key vault, it will be set to true by default. Once set to true, it cannot be reverted to false.
AzureKeyVault.KeyVault.properties.vaultUri String The URI of the vault for performing operations on keys and secrets.

Command Example

!azure-key-vault-list limit=1

Context Example

{
    "AzureKeyVault": {
        "KeyVault": {
            "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-265",
            "location": "eastasia",
            "name": "xsoar-test-265",
            "properties": {
                "accessPolicies": [
                    {
                        "objectId": "YOUR_OBJECT_ID",
                        "permissions": {
                            "certificates": [
                                "get",
                                "list",
                                "update",
                                "create",
                                "import",
                                "delete",
                                "recover",
                                "backup",
                                "restore",
                                "managecontacts",
                                "manageissuers",
                                "getissuers",
                                "listissuers",
                                "setissuers",
                                "deleteissuers"
                            ],
                            "keys": [
                                "get",
                                "list",
                                "update",
                                "create",
                                "import",
                                "delete",
                                "recover",
                                "backup",
                                "restore",
                                "decrypt"
                            ],
                            "secrets": [
                                "get",
                                "list",
                                "set",
                                "delete",
                                "recover",
                                "backup",
                                "restore"
                            ],
                            "storage": [
                                "get",
                                "list",
                                "delete",
                                "set",
                                "update",
                                "regeneratekey",
                                "getsas",
                                "listsas"
                            ]
                        },
                        "tenantId": "YOUR_TENANT_ID"
                    }
                ],
                "enableSoftDelete": true,
                "enabledForDeployment": true,
                "enabledForDiskEncryption": true,
                "enabledForTemplateDeployment": true,
                "provisioningState": "Succeeded",
                "sku": {
                    "family": "A",
                    "name": "standard"
                },
                "tenantId": "YOUR_TENANT_ID",
                "vaultUri": "https://xsoar-test-265.vault.azure.net/"
            },
            "tags": {},
            "type": "Microsoft.KeyVault/vaults"
        }
    }
}

Human Readable Output

Key Vaults List

Id Name Type Location
/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-265 xsoar-test-265 Microsoft.KeyVault/vaults eastasia

azure-key-vault-access-policy-update


Update access policies in a key vault in the specified subscription. The update regards only the access policy for the specified object ID.

Base Command

azure-key-vault-access-policy-update

Input

Argument Name Description Required
vault_name The name of the Key Vault to update it’s access policy. Required
operation_kind The name of the operation to do on the vault’s access policy. Supports three operations: add,remove,replace. For example, to add get, list permissions to the current secret permissions, use operation_kind=add and secrets=get,list. Possible values are: add, remove, replace. Required
object_id The object ID of a user, service principal or security group in the Entra ID tenant for the vault. The update regards only the access policy for the specified object ID. Required
keys Permissions to keys. Possible values are: encrypt, decrypt, wrapKey, unwrapKey, sign, verify, get, list, create, update, import, delete, backup, restore, recover, purge. Optional
secrets Permissions to secrets. Possible values are: get, list, set, delete, backup, restore, recover, purge. Optional
certificates Permissions to certificates. Possible values are: get, list, delete, create, import, update, managecontacts, getissuers, listissuers, setissuers, deleteissuers, manageissuers, recover, purge. Optional
storage Permissions to storage accounts. Possible values are: get, list, delete, set, update, regeneratekey, getsas, listsas, deletesas, setsas, recover, backup, restore, purge. Optional
subscription_id The subscription ID. Note: This argument will override the instance parameter ‘Subscription ID’. Optional
resource_group_name The resource group name. Note: This argument will override the instance parameter ‘Resource Group Name’. Optional

Context Output

Path Type Description
AzureKeyVault.VaultAccessPolicy.id String Resource ID.
AzureKeyVault.VaultAccessPolicy.type String Resource type in Azure.
AzureKeyVault.VaultAccessPolicy.properties.accessPolicies.tenantId String The Entra ID tenant ID that should be used for authenticating requests to the key vault.
AzureKeyVault.VaultAccessPolicy.properties.accessPolicies.objectId String The object ID of a user, service principal or security group in the Entra ID tenant for the vault. The object ID must be unique for the list of access policies.
AzureKeyVault.VaultAccessPolicy.properties.accessPolicies.permissions.keys Unknown Permissions to keys.
AzureKeyVault.VaultAccessPolicy.properties.accessPolicies.permissions.secrets Unknown Permissions to secrets.
AzureKeyVault.VaultAccessPolicy.properties.accessPolicies.permissions.certificates Unknown Permissions to certificates.

Command Example

!azure-key-vault-access-policy-update object_id=YOUR_OBJECT_ID operation_kind=add vault_name=xsoar-test-285 keys=import,list

Context Example

{
    "AzureKeyVault": {
        "VaultAccessPolicy": {
            "id": "/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-285/accessPolicies/",
            "properties": {
                "accessPolicies": [
                    {
                        "objectId": "YOUR_OBJECT_ID",
                        "permissions": {
                            "certificates": [
                                "get",
                                "list",
                                "update",
                                "create",
                                "import",
                                "delete",
                                "recover",
                                "backup",
                                "restore",
                                "managecontacts",
                                "manageissuers",
                                "getissuers",
                                "listissuers",
                                "setissuers",
                                "deleteissuers"
                            ],
                            "keys": [
                                "create",
                                "decrypt",
                                "import",
                                "list"
                            ],
                            "secrets": [
                                "get",
                                "list",
                                "set",
                                "delete",
                                "recover",
                                "backup",
                                "restore"
                            ],
                            "storage": [
                                "get",
                                "list",
                                "delete",
                                "set",
                                "update",
                                "regeneratekey",
                                "getsas",
                                "listsas"
                            ]
                        },
                        "tenantId": "YOUR_TENANT_ID"
                    }
                ]
            },
            "type": "Microsoft.KeyVault/vaults/accessPolicies"
        }
    }
}

Human Readable Output

xsoar-test-285 Updated Access Policy

Id Type
/subscriptions/SUBSCRIPTION_ID/resourceGroups/test-group/providers/Microsoft.KeyVault/vaults/xsoar-test-285/accessPolicies/ Microsoft.KeyVault/vaults/accessPolicies

azure-key-vault-key-get


Get the public part of a stored key. This operation requires the keys/get permission.

Base Command

azure-key-vault-key-get

Input

Argument Name Description Required
vault_name The name of the Key Vault where the key resides in. Required
key_name Key name. Required
key_version Adding the version parameter retrieves a specific version of a key. This URI fragment is optional. If not specified, the latest version of the key is returned. Optional

Context Output

Path Type Description
AzureKeyVault.Key.key.kid String Key identifier.
AzureKeyVault.Key.key.kty String JsonWebKey Key Type.
AzureKeyVault.Key.key.key_ops Unknown Supported key operations.
AzureKeyVault.Key.key.n String RSA modulus.
AzureKeyVault.Key.key.e String RSA public exponent.
AzureKeyVault.Key.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Key.attributes.created Date Creation time in UTC.
AzureKeyVault.Key.attributes.updated Date Last updated time in UTC.
AzureKeyVault.Key.attributes.recoveryLevel Unknown Reflects the deletion recovery level currently in effect for keys in the current vault. If it contains ‘Purgeable’ the key can be permanently deleted by a privileged user; otherwise, only the system can purge the key, at the end of the retention interval.

Command Example

!azure-key-vault-key-get key_name=test-key-1 vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "Key": {
            "attributes": {
                "created": "2021-08-11T12:03:16",
                "enabled": true,
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-08-11T12:03:16"
            },
            "key": {
                "e": "AQAB",
                "key_ops": [
                    "sign",
                    "verify",
                    "wrapKey",
                    "unwrapKey",
                    "encrypt",
                    "decrypt"
                ],
                "kid": "https://xsoar-test-vault.vault.azure.net/keys/test-key-1/KEY_VERSION",
                "kty": "RSA",
                "n": "XXX-XXXX-XXX"
            },
            "key_vault_name": "xsoar-test-vault",
            "tags": {}
        }
    }
}

Human Readable Output

test-key-1 Information

Key Id Enabled Json Web Key Type Key Operations Create Time Update Time
https://xsoar-test-vault.vault.azure.net/keys/test-key-1/KEY_VERSION true RSA sign,
verify,
wrapKey,
unwrapKey,
encrypt,
decrypt
2021-08-11T12:03:16 2021-08-11T12:03:16

azure-key-vault-key-list


List keys in the specified vault. For a limit greater than 25, more than one API call will be required and the command might take longer time. This operation requires the keys/list permission.

Base Command

azure-key-vault-key-list

Input

Argument Name Description Required
vault_name The name of the Key Vault where the keys reside in. Required
limit Limit on the number of keys to return. Default value is 50. Default is 50. Optional
offset First index to retrieve from. Default value is 0. Default is 0. Optional

Context Output

Path Type Description
AzureKeyVault.Key.kid String Key identifier.
AzureKeyVault.Key.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Key.attributes.created Date Creation time in UTC.
AzureKeyVault.Key.attributes.updated Date Last updated time in UTC.
AzureKeyVault.Key.attributes.recoveryLevel String Reflects the deletion recovery level currently in effect for keys in the current vault. If it contains ‘Purgeable’ the key can be permanently deleted by a privileged user; otherwise, only the system can purge the key, at the end of the retention interval.
AzureKeyVault.Key.attributes.recoverableDays Number Soft Delete data retention days. Value should be >=7 and <=90 when softDelete enabled, otherwise 0.

Command Example

!azure-key-vault-key-list vault_name=xsoar-test-vault limit=1

Context Example

{
    "AzureKeyVault": {
        "Key": {
            "attributes": {
                "created": "2021-08-11T12:05:48",
                "enabled": false,
                "exp": "2022-08-11T12:05:48",
                "nbf": "2021-08-11T11:55:48",
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-09-05T14:02:13"
            },
            "key_vault_name": "xsoar-test-vault",
            "kid": "https://xsoar-test-vault.vault.azure.net/keys/test-cer-1",
            "managed": true,
            "tags": {}
        }
    }
}

Human Readable Output

xsoar-test-vault Keys List

Key Id Enabled Create Time Update Time Expiry Time
https://xsoar-test-vault.vault.azure.net/keys/test-cer-1 false 2021-08-11T12:05:48 2021-09-05T14:02:13 2022-08-11T12:05:48

azure-key-vault-key-delete


Delete a key of any type from storage in Azure Key vault. This operation requires the keys/delete permission.

Base Command

azure-key-vault-key-delete

Input

Argument Name Description Required
vault_name The name of the Key Vault where the key resides in. Required
key_name Key name to delete. Required

Context Output

Path Type Description
AzureKeyVault.Key.recoveryId String The url of the recovery object, used to identify and recover the deleted key.
AzureKeyVault.Key.deletedDate Date The time when the key was deleted, in UTC.
AzureKeyVault.Key.key.kid String Key identifier.
AzureKeyVault.Key.key.kty String JsonWebKey Key Type.
AzureKeyVault.Key.key.key_ops Unknown Supported key operations.
AzureKeyVault.Key.key.n String RSA modulus.
AzureKeyVault.Key.key.e String RSA public exponent.
AzureKeyVault.Key.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Key.attributes.created Number Creation time in UTC.
AzureKeyVault.Key.attributes.updated Number Last updated time in UTC.
AzureKeyVault.Key.attributes.recoveryLevel String Reflects the deletion recovery level currently in effect for keys in the current vault. If it contains ‘Purgeable’ the key can be permanently deleted by a privileged user; otherwise, only the system can purge the key, at the end of the retention interval.

Command Example

!azure-key-vault-key-delete key_name=test-key-10 vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "Key": {
            "attributes": {
                "created": "2021-08-18T07:07:18",
                "enabled": true,
                "exp": "2023-08-18T07:07:03",
                "nbf": "2021-08-18T07:07:03",
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-08-18T07:07:18"
            },
            "deletedDate": "2021-11-01T12:52:40",
            "key": {
                "e": "AQAB",
                "key_ops": [
                    "sign",
                    "verify",
                    "wrapKey",
                    "unwrapKey",
                    "encrypt",
                    "decrypt"
                ],
                "kid": "https://xsoar-test-vault.vault.azure.net/keys/test-key-10/KEY_VERSION",
                "kty": "RSA",
                "n": "XXX-XXXX-XXX"
            },
            "key_vault_name": "xsoar-test-vault",
            "recoveryId": "https://xsoar-test-vault.vault.azure.net/deletedkeys/test-key-10",
            "scheduledPurgeDate": "2022-01-30T12:52:40",
            "tags": {}
        }
    }
}

Human Readable Output

Delete test-key-10

Key Id Recovery Id Deleted Date Scheduled Purge Date
https://xsoar-test-vault.vault.azure.net/keys/test-key-10/KEY_VERSION https://xsoar-test-vault.vault.azure.net/deletedkeys/test-key-10 2021-11-01T12:52:40 2022-01-30T12:52:40

azure-key-vault-secret-get


Get a specified secret from a given key vault. The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission.

Base Command

azure-key-vault-secret-get

Input

Argument Name Description Required
vault_name The name of the Key Vault where the secret resides in. Required
secret_name Secret name. Required
secret_version Secret version.If not specified, the latest version of the secret is returned. Optional

Context Output

Path Type Description
AzureKeyVault.Secret.value String Secret value.
AzureKeyVault.Secret.id String Secret ID.
AzureKeyVault.Secret.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Secret.attributes.created Date Creation time in UTC.
AzureKeyVault.Secret.attributes.updated Date Last updated time in UTC.
AzureKeyVault.Secret.attributes.recoveryLevel String Reflects the deletion recovery level currently in effect for secrets in the current vault. If it contains ‘Purgeable’, the secret can be permanently deleted by a privileged user; otherwise, only the system can purge the secret, at the end of the retention interval.

Command Example

!azure-key-vault-secret-get secret_name=test-sec-1 vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "Secret": {
            "attributes": {
                "created": "2021-08-11T12:04:12",
                "enabled": true,
                "exp": "2023-08-11T12:04:06",
                "nbf": "2021-08-11T12:04:06",
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-08-17T16:22:57"
            },
            "contentType": "text",
            "id": "https://xsoar-test-vault.vault.azure.net/secrets/test-sec-1/SECRET_VERSION",
            "key_vault_name": "xsoar-test-vault",
            "tags": {},
            "value": "test"
        }
    }
}

Human Readable Output

test-sec-1 Information

Secret Id Enabled Create Time Update Time Expiry Time
https://xsoar-test-vault.vault.azure.net/secrets/test-sec-1/SECRET_VERSION true 2021-08-11T12:04:12 2021-08-17T16:22:57 2023-08-11T12:04:06

azure-key-vault-secret-list


List secrets in a specified key vault. For a limit greater than 25, more than one API call will be required and the command might take longer time. This operation requires the secrets/list permission.

Base Command

azure-key-vault-secret-list

Input

Argument Name Description Required
vault_name The name of the Key Vault where the secrets reside in. Required
limit Limit on the number of secrets to return. Default value is 50. Optional
offset First index to retrieve from. Default value is 0. Optional

Context Output

Path Type Description
AzureKeyVault.Secret.id String Secret ID.
AzureKeyVault.Secret.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Secret.attributes.nbf Date Not before date in UTC.
AzureKeyVault.Secret.attributes.exp Date Expiry date in UTC.
AzureKeyVault.Secret.attributes.created Date Creation time in UTC.
AzureKeyVault.Secret.attributes.updated Date Last updated time in UTC.
AzureKeyVault.Secret.attributes.recoveryLevel String Reflects the deletion recovery level currently in effect for secrets in the current vault. If it contains ‘Purgeable’, the secret can be permanently deleted by a privileged user; otherwise, only the system can purge the secret, at the end of the retention interval.
AzureKeyVault.Secret.attributes.recoverableDays Number Soft Delete data retention days. Value should be >=7 and <=90 when softDelete enabled, otherwise 0.

Command Example

!azure-key-vault-secret-list vault_name=xsoar-test-vault limit=1

Context Example

{
    "AzureKeyVault": {
        "Secret": {
            "attributes": {
                "created": "2021-08-11T12:05:48",
                "enabled": false,
                "exp": "2022-08-11T12:05:48",
                "nbf": "2021-08-11T11:55:48",
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-09-05T14:02:13"
            },
            "contentType": "application/x-pkcs12",
            "id": "https://xsoar-test-vault.vault.azure.net/secrets/test-cer-1",
            "key_vault_name": "xsoar-test-vault",
            "managed": true,
            "tags": {}
        }
    }
}

Human Readable Output

xsoar-test-vault Secrets List

Secret Id Enabled Create Time Update Time Expiry Time
https://xsoar-test-vault.vault.azure.net/secrets/test-cer-1 false 2021-08-11T12:05:48 2021-09-05T14:02:13 2022-08-11T12:05:48

azure-key-vault-secret-delete


Delete a secret from a specified key vault. This operation requires the secrets/delete permission.

Base Command

azure-key-vault-secret-delete

Input

Argument Name Description Required
vault_name The name of the Key Vault where the secret resides in. Required
secret_name Secret name to delete. Required

Context Output

Path Type Description
AzureKeyVault.Secret.recoveryId String The URL of the recovery object, used to identify and recover the deleted secret.
AzureKeyVault.Secret.deletedDate Date The time when the secret was deleted, in UTC.
AzureKeyVault.Secret.scheduledPurgeDate Date The time when the secret is scheduled to be purged, in UTC.
AzureKeyVault.Secret.id String Deleted secret ID.
AzureKeyVault.Secret.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Secret.attributes.created Date Creation time in UTC.
AzureKeyVault.Secret.attributes.updated Date Last updated time in UTC.
AzureKeyVault.Secret.attributes.recoveryLevel String Reflects the deletion recovery level currently in effect for secrets in the current vault.

Command Example

!azure-key-vault-secret-delete secret_name=test-sec-10 vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "Secret": {
            "attributes": {
                "created": "2021-08-18T07:08:10",
                "enabled": true,
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-08-18T07:08:10"
            },
            "contentType": "aa",
            "deletedDate": "2021-11-01T12:52:54",
            "id": "https://xsoar-test-vault.vault.azure.net/secrets/test-sec-10/SECRET_VERSION",
            "key_vault_name": "xsoar-test-vault",
            "recoveryId": "https://xsoar-test-vault.vault.azure.net/deletedsecrets/test-sec-10",
            "scheduledPurgeDate": "2022-01-30T12:52:54",
            "tags": {}
        }
    }
}

Human Readable Output

Delete test-sec-10

Secret Id Recovery Id Deleted Date Scheduled Purge Date
https://xsoar-test-vault.vault.azure.net/secrets/test-sec-10/SECRET_VERSION https://xsoar-test-vault.vault.azure.net/deletedsecrets/test-sec-10 2021-11-01T12:52:54 2022-01-30T12:52:54

azure-key-vault-certificate-get


Gets information about a specific certificate. This operation requires the certificates/get permission.

Base Command

azure-key-vault-certificate-get

Input

Argument Name Description Required
vault_name The name of the Key Vault where the certificate resides in. Required
certificate_name Certificate name. Required
certificate_version The version of the certificate. If not specified, the latest version of the certificate is returned. Optional

Context Output

Path Type Description
AzureKeyVault.Certificate.id String Certificate ID.
AzureKeyVault.Certificate.kid String Key ID.
AzureKeyVault.Certificate.sid String Secret ID.
AzureKeyVault.Certificate.x5t String Thumbprint of the certificate.
AzureKeyVault.Certificate.cer String CER contents of x509 certificate.
AzureKeyVault.Certificate.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Certificate.attributes.exp Date Expiry date in UTC.
AzureKeyVault.Certificate.attributes.created Date Creation time in UTC.
AzureKeyVault.Certificate.attributes.updated Date Last updated time in UTC.
AzureKeyVault.Certificate.attributes.recoveryLevel String Reflects the deletion recovery level currently in effect for certificates in the current vault. If it contains ‘Purgeable’, the certificate can be permanently deleted by a privileged user; otherwise, only the system can purge the certificate, at the end of the retention interval.
AzureKeyVault.Certificate.policy Unknown The management policy.

Command Example

!azure-key-vault-certificate-get certificate_name=test-cer-1 vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "Certificate": {
            "attributes": {
                "created": "2021-08-11T12:05:48",
                "enabled": false,
                "exp": "2022-08-11T12:05:48",
                "nbf": "2021-08-11T11:55:48",
                "recoverableDays": 90,
                "recoveryLevel": "Recoverable+Purgeable",
                "updated": "2021-09-05T14:02:13"
            },
            "cer": "XXXXX-XXXXXX",
            "id": "https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1/CERTIFICATE_VERSION",
            "key_vault_name": "xsoar-test-vault",
            "kid": "https://xsoar-test-vault.vault.azure.net/keys/test-cer-1/CERTIFICATE_VERSION",
            "pending": {
                "id": "https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1/pending"
            },
            "policy": {
                "attributes": {
                    "created": "2021-08-11T12:05:31",
                    "enabled": true,
                    "updated": "2021-08-11T12:05:31"
                },
                "id": "https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1/policy",
                "issuer": {
                    "name": "Self"
                },
                "key_props": {
                    "exportable": true,
                    "key_size": 2048,
                    "kty": "RSA",
                    "reuse_key": false
                },
                "lifetime_actions": [
                    {
                        "action": {
                            "action_type": "AutoRenew"
                        },
                        "trigger": {
                            "lifetime_percentage": 80
                        }
                    }
                ],
                "secret_props": {
                    "contentType": "application/x-pkcs12"
                },
                "x509_props": {
                    "basic_constraints": {
                        "ca": false
                    },
                    "ekus": [
                        "1.3.6.1.5.5.7.3.1",
                        "1.3.6.1.5.5.7.3.2"
                    ],
                    "key_usage": [
                        "digitalSignature",
                        "keyEncipherment"
                    ],
                    "sans": {
                        "dns_names": []
                    },
                    "subject": "CN=test",
                    "validity_months": 12
                }
            },
            "sid": "https://xsoar-test-vault.vault.azure.net/secrets/test-cer-1/CERTIFICATE_VERSION",
            "tags": {},
            "x5t": "XXXX-XXXXX"
        }
    }
}

Human Readable Output

test-cer-1 Information

Certificate Id Enabled Create Time Update Time Expiry Time
https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1/CERTIFICATE_VERSION false 2021-08-11T12:05:48 2021-09-05T14:02:13 2022-08-11T12:05:48

azure-key-vault-certificate-list


List certificates in a specified key vault. For a limit greater than 25, more than one API call will be required and the command might take longer time. This operation requires the certificates/list permission.

Base Command

azure-key-vault-certificate-list

Input

Argument Name Description Required
vault_name The name of the Key Vault where the certificate reside in. Required
limit Limit on the number of certificates to return. Default value is 50. Optional
offset First index to retrieve from. Default value is 0. Optional

Context Output

Path Type Description
AzureKeyVault.Certificate.id String Certificate ID.
AzureKeyVault.Certificate.x5t String Thumbprint of the certificate.
AzureKeyVault.Certificate.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.Certificate.attributes.created Date Creation time in UTC.
AzureKeyVault.Certificate.attributes.updated Date Last updated time in UTC.

Command Example

!azure-key-vault-certificate-list vault_name=xsoar-test-vault limit=1

Context Example

{
    "AzureKeyVault": {
        "Certificate": {
            "attributes": {
                "created": "2021-08-11T12:05:48",
                "enabled": false,
                "exp": "2022-08-11T12:05:48",
                "nbf": "2021-08-11T11:55:48",
                "updated": "2021-09-05T14:02:13"
            },
            "id": "https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1",
            "key_vault_name": "xsoar-test-vault",
            "subject": "",
            "tags": {},
            "x5t": "XXXX-XXXXX"
        }
    }
}

Human Readable Output

xsoar-test-vault Certificates List

Certificate Id Enabled Create Time Update Time Expiry Time
https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1 false 2021-08-11T12:05:48 2021-09-05T14:02:13 2022-08-11T12:05:48

azure-key-vault-certificate-policy-get


Get the policy of the specified certificate.This operation requires the certificates/get permission.

Base Command

azure-key-vault-certificate-policy-get

Input

Argument Name Description Required
vault_name The name of the Key Vault where the secret resides in. Required
certificate_name The name of the certificate to retrieve the policy from. Required

Context Output

Path Type Description
AzureKeyVault.CertificatePolicy.id String Policy ID.
AzureKeyVault.CertificatePolicy.key_props Unknown Properties of the key backing a certificate.
AzureKeyVault.CertificatePolicy.x509_props Unknown Properties of the X509 component of a certificate.
AzureKeyVault.CertificatePolicy.lifetime_actions Unknown Actions that will be performed by Key Vault over the lifetime of a certificate.
AzureKeyVault.CertificatePolicy.issuer Unknown Parameters for the issuer of the X509 component of a certificate.
AzureKeyVault.CertificatePolicy.attributes.enabled Boolean Determines whether the object is enabled.
AzureKeyVault.CertificatePolicy.attributes.created Date Creation time in UTC.
AzureKeyVault.CertificatePolicy.attributes.updated Date Last updated time in UTC.

Command Example

!azure-key-vault-certificate-policy-get certificate_name=test-cer-1 vault_name=xsoar-test-vault

Context Example

{
    "AzureKeyVault": {
        "CertificatePolicy": {
            "CertificateName": "test-cer-1",
            "attributes": {
                "created": "2021-08-11T12:05:31",
                "enabled": true,
                "updated": "2021-08-11T12:05:31"
            },
            "id": "https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1/policy",
            "issuer": {
                "name": "Self"
            },
            "key_props": {
                "exportable": true,
                "key_size": 2048,
                "kty": "RSA",
                "reuse_key": false
            },
            "lifetime_actions": [
                {
                    "action": {
                        "action_type": "AutoRenew"
                    },
                    "trigger": {
                        "lifetime_percentage": 80
                    }
                }
            ],
            "secret_props": {
                "contentType": "application/x-pkcs12"
            },
            "x509_props": {
                "basic_constraints": {
                    "ca": false
                },
                "ekus": [
                    "1.3.6.1.5.5.7.3.1",
                    "1.3.6.1.5.5.7.3.2"
                ],
                "key_usage": [
                    "digitalSignature",
                    "keyEncipherment"
                ],
                "sans": {
                    "dns_names": []
                },
                "subject": "CN=test",
                "validity_months": 12
            }
        }
    }
}

Human Readable Output

test-cer-1 Policy Information

Id Key Props Secret Props X509 Props Issuer Attributes
https://xsoar-test-vault.vault.azure.net/certificates/test-cer-1/policy exportable: true
kty: RSA
key_size: 2048
reuse_key: false
contentType: application/x-pkcs12 subject: CN=test
sans: {“dns_names”: []}
ekus: 1.3.6.1.5.5.7.3.1,
1.3.6.1.5.5.7.3.2
key_usage: digitalSignature,
keyEncipherment
validity_months: 12
basic_constraints: {“ca”: false}
name: Self enabled: true
created: 2021-08-11T12:05:31
updated: 2021-08-11T12:05:31

azure-key-vault-subscriptions-list


List all subscriptions for a tenant.

Base Command

azure-key-vault-subscriptions-list

Input

There are no input arguments for this command.

Context Output

Path Type Description
AzureKeyVault.Subscription.id String Subscription ID.
AzureKeyVault.Subscription.displayName String Subscription display name.
AzureKeyVault.Subscription.state String Subscription state.
AzureKeyVault.Subscription.subscriptionPolicies Unknown Subscription policies.
AzureKeyVault.Subscription.authorizationSource String Authorization source.
AzureKeyVault.Subscription.managedByTenants Unknown Managed by tenants.
AzureKeyVault.Subscription.tenantId String Tenant ID.

azure-key-vault-resource-group-list


List all resource groups for a subscription.

Base Command

azure-key-vault-resource-group-list

Input

Argument Name Description Required
subscription_id The subscription ID. Note: This argument will override the instance parameter ‘Subscription ID’. Optional
limit Limit on the number of resource groups to return. Default is 50. Default is 50. Optional
tag A single tag in the form of ‘{“Tag Name”:”Tag Value”}’ to filter the list by. Optional

Context Output

Path Type Description
AzureKeyVault.ResourceGroup.id String Resource group ID.
AzureKeyVault.ResourceGroup.name String Resource group name.
AzureKeyVault.ResourceGroup.location String Resource group location.
AzureKeyVault.ResourceGroup.tags Unknown Resource group tags.
AzureKeyVault.ResourceGroup.properties.provisioningState unknown Resource group provisioning state.

azure-key-vault-auth-reset


Run this command if for some reason you need to rerun the authentication process.

Base Command

azure-key-vault-auth-reset

Input

There are no input arguments for this command.

Context Output

There is no context output for this command.

Configuration parameters

  • azure_cloud — Azure Cloud
  • client_id — Client ID
  • credentials
  • tenant_id — Tenant ID (required)
  • certificate_thumbprint — Certificate Thumbprint
  • credentials_certificate_thumbprint
  • private_key — Private Key
  • use_managed_identities — Use Azure Managed Identities
  • managed_identities_client_id
  • subscription_id — Default Subscription ID (required)
  • resource_group_name — Default Resource Group Name (required)
  • isFetchCredentials — Fetches credentials
  • credentials_fetch_mode — Credentials Fetch Mode
  • key_vaults — Key Vault names - a comma separated list of Key Vaults to fetch secrets from.
  • secrets — Secret names - a comma separated list of secrets to fetch.
  • insecure — Trust any certificate (not secure)
  • proxy — Use system proxy settings

Commands (17)

  • azure-key-vault-access-policy-update

    Update access policies in a key vault in the specified subscription. The update regards only the access policy for the specified object ID.

  • azure-key-vault-auth-reset

    Run this command if for some reason you need to rerun the authentication process.

  • azure-key-vault-certificate-get

    Gets information about a specific certificate. This operation requires the certificates/get permission.

  • azure-key-vault-certificate-list

    List certificates in a specified key vault. For a limit greater than 25, more than one API call will be required and the command might take longer time. This operation requires the certificates/list permission.

  • azure-key-vault-certificate-policy-get

    Get the policy of the specified certificate.This operation requires the certificates/get permission.

  • azure-key-vault-create-update

    Create or update a key vault in the specified subscription. If the Key Vault exists, the updated properties will overwrite the existing ones. Please use azure-key-vault-access-policy-update command if you wish to update the access policy of an existing Key Vault.

  • azure-key-vault-delete

    Delete the specified key vault.

  • azure-key-vault-get

    Get the specified key vault.

  • azure-key-vault-key-delete

    Delete a key of any type from storage in Azure Key vault. This operation requires the keys/delete permission.

  • azure-key-vault-key-get

    Get the public part of a stored key. This operation requires the keys/get permission.

  • azure-key-vault-key-list

    List keys in the specified vault. For a limit greater than 25, more than one API call will be required and the command might take longer time. This operation requires the keys/list permission.

  • azure-key-vault-list

    The List operation gets information about the vaults associated with the subscription. For a limit greater than 25, more than one API call will be required and the command might take longer time.

  • azure-key-vault-resource-group-list

    List all resource groups for a subscription.

  • azure-key-vault-secret-delete

    Delete a secret from a specified key vault. This operation requires the secrets/delete permission.

  • azure-key-vault-secret-get

    Get a specified secret from a given key vault. The GET operation is applicable to any secret stored in Azure Key Vault. This operation requires the secrets/get permission.

  • azure-key-vault-secret-list

    List secrets in a specified key vault. For a limit greater than 25, more than one API call will be required and the command might take longer time. This operation requires the secrets/list permission.

  • azure-key-vault-subscriptions-list

    List all subscriptions for a tenant.

import copy
from datetime import datetime
from typing import Any

import urllib3
from CommonServerPython import *
from MicrosoftApiModule import *  # noqa: E402

APP_NAME = "azure-key-vault"
DATE_FORMAT = "%Y-%m-%dT%H:%M:%SZ"
AUTHORIZATION_CODE = "authorization_code"
VAULT_NAME_CONTEXT_FIELD = "key_vault_name"

DEFAULT_LIMIT = 50
DEFAULT_OFFSET = 0

STORE_IN_CORTEX_MODE = "Store in Cortex"
ON_DEMAND_MODE = "External Credentials Vault (on-demand)"


class KeyVaultClient:
    """
    Key Vault API Client
    """

    def __init__(
        self,
        tenant_id: str,
        client_id: str,
        client_secret: str,
        subscription_id: str,
        resource_group_name: str,
        verify: bool,
        proxy: bool,
        certificate_thumbprint: Optional[str],
        private_key: Optional[str],
        managed_identities_client_id: Optional[str] = None,
        azure_cloud: Optional[AzureCloud] = None,
    ):
        self.azure_cloud = azure_cloud or AZURE_WORLDWIDE_CLOUD
        self.ms_client = MicrosoftClient(
            self_deployed=True,
            auth_id=client_id,
            enc_key=client_secret,
            token_retrieval_url=urljoin(self.azure_cloud.endpoints.active_directory, f"/{tenant_id}/oauth2/token"),
            app_name=APP_NAME,
            base_url=urljoin(
                self.azure_cloud.endpoints.resource_manager,
                f"/subscriptions/{subscription_id}/resourceGroups/{resource_group_name}/providers/Microsoft.KeyVault",
            ),
            verify=verify,
            proxy=proxy,
            multi_resource=True,
            resources=[self.get_management_resource(), self.get_vault_resource()],
            resource="",
            scope="",
            tenant_id=tenant_id,
            ok_codes=(200, 201, 202, 204, 400, 401, 403, 404),
            certificate_thumbprint=certificate_thumbprint,
            private_key=private_key,
            managed_identities_client_id=managed_identities_client_id,
            command_prefix="azure-key-vault",
            azure_cloud=self.azure_cloud,
        )

    def get_vault_resource(self) -> str:
        return self.azure_cloud.endpoints.keyvault

    def get_management_resource(self) -> str:
        return self.azure_cloud.endpoints.resource_manager

    def http_request(
        self,
        method: str,
        url_suffix: str = None,
        full_url: str = None,
        params: dict = None,
        data: dict = None,
        resource: Optional[str] = None,
        ok_codes: list = None,
    ):
        """
        Wrapper to MicrosoftClient http_request method.

        """
        resource = resource or self.get_management_resource()
        if not params:
            params = {}
        if "api-version" not in params and full_url and "api-version" not in full_url:
            params["api-version"] = "2022-07-01" if resource == self.get_management_resource() else "7.2"
        res = self.ms_client.http_request(
            method=method,
            url_suffix=url_suffix,
            full_url=full_url,
            json_data=data,
            params=params,
            resp_type="response",
            return_empty_response=True,
            resource=resource,
            timeout=20,
            ok_codes=ok_codes,
        )

        if res.text:
            res_json = res.json()
        else:  # in case an empty response returned in delete key vault command
            res_json = {"status_code": res.status_code}

        return res_json

    """integration commands requests"""

    def create_or_update_key_vault_request(
        self,
        subscription_id: str,
        resource_group_name: str,
        vault_name: str,
        object_id: str,
        location: str,
        sku_name: str,
        keys_permissions: list[str],
        secrets_permissions: list[str],
        certificates_permissions: list[str],
        storage_accounts: list[str],
        enabled_for_deployment: bool,
        enabled_for_disk_encryption: bool,
        enabled_for_template_deployment: bool,
        default_action: str,
        bypass: str,
        vnet_subnet_id: str,
        ignore_missing_vnet_service_endpoint: bool,
        ip_rules: list[str],
    ) -> dict[str, Any]:
        """
        Create or update a key vault in the specified subscription..

        Args:
            subscription_id (str): Subscription ID.
            resource_group_name (str): Resource group name.
            vault_name (str): Key Vault name.
            object_id (str): The object ID of a user, service principal or security group
                             in the Azure Active Directory.
            location (str): Key Vault supported Azure location.
            sku_name (str): Sku name.
            keys_permissions (List[str]): Permissions to keys.
            secrets_permissions (List[str]): Permissions to secrets.
            certificates_permissions (List[str]): Permissions to certificates.
            storage_accounts (List[str]): Permissions to storage accounts.
            enabled_for_deployment (bool): permission for Azure VM to retrieve certificates stored as secrets.
            enabled_for_disk_encryption (bool): permission for Azure Disk Encryption to retrieve secrets.
            enabled_for_template_deployment (bool): permission for Azure Resource Manager to retrieve secrets.
            default_action (str): The default action.
            bypass (str): bypass network rules.Network acl property.Default is 'AzureServices'.
            vnet_subnet_id (str): Full resource id of a vnet subnet.
            ignore_missing_vnet_service_endpoint (bool): NRP will ignore the check.
            ip_rules (List[str],optional) : The list of IP address rules.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        # permissions property

        permissions = self.config_vault_permission(
            keys_permissions, secrets_permissions, certificates_permissions, storage_accounts
        )

        # network property
        network_acl = self.config_vault_network_acls(
            default_action, bypass, vnet_subnet_id, ignore_missing_vnet_service_endpoint, ip_rules
        )
        # private end point connection property

        properties = self.config_vault_properties(
            object_id,
            self.ms_client.tenant_id,
            enabled_for_deployment,
            enabled_for_disk_encryption,
            enabled_for_template_deployment,
            sku_name,
            permissions,
            network_acl,
        )

        data = {"location": location, "properties": properties}

        full_url = urljoin(
            self.azure_cloud.endpoints.resource_manager,
            f"subscriptions/{subscription_id}/resourceGroups/"
            f"{resource_group_name}/providers/Microsoft.KeyVault/vaults/{vault_name}",
        )

        return self.http_request("PUT", full_url=full_url, data=data, ok_codes=[200, 201])

    def delete_key_vault_request(self, subscription_id: str, resource_group_name: str, vault_name: str) -> dict[str, Any]:
        """
        Delete Key Vault by name.

        Args:
            subscription_id (str): Subscription ID.
            resource_group_name (str): Resource group name.
            vault_name (str): Key Vault name.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        full_url = urljoin(
            self.azure_cloud.endpoints.resource_manager,
            f"subscriptions/{subscription_id}/resourceGroups/"
            f"{resource_group_name}/providers/Microsoft.KeyVault/vaults/{vault_name}",
        )

        return self.http_request("DELETE", full_url=full_url, ok_codes=[200, 204])

    def get_key_vault_request(self, subscription_id: str, resource_group_name: str, vault_name: str) -> dict[str, Any]:
        """
        Retrieve Key Vault by name.

        Args:
            subscription_id (str): Subscription ID.
            resource_group_name (str): Resource group name.
            vault_name (str): Key Vault name.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        full_url = urljoin(
            self.azure_cloud.endpoints.resource_manager,
            f"subscriptions/{subscription_id}/resourceGroups/"
            f"{resource_group_name}/providers/Microsoft.KeyVault/vaults/{vault_name}",
        )
        return self.http_request("GET", full_url=full_url, ok_codes=[200])

    def list_key_vaults_request(
        self, subscription_id: str = None, limit: int = DEFAULT_LIMIT, offset: int = DEFAULT_OFFSET
    ) -> list[dict]:
        """
        List Key Vaults by limit and offset arguments from the specified resource group and subscription.

        Args:
            subscription_id (str): Subscription ID.
            limit(int): limit the number of key vaults to return.Default is 50.
            offset(int): First index to retrieve from. Default is 0.
        Returns:
            Dict[str, Any]: API response from Azure.
        """
        ful_url = urljoin(
            self.azure_cloud.endpoints.resource_manager,
            f"subscriptions/{subscription_id}/providers/Microsoft.KeyVault/vaults?$top={limit}",
        )
        response = self.http_request("GET", full_url=ful_url, ok_codes=[200])
        return self.get_entities_independent_of_pages(response, limit, offset)

    def update_access_policy_request(
        self,
        subscription_id: str,
        resource_group_name: str,
        vault_name: str,
        operation_kind: str,
        object_id: str,
        keys: list[str],
        secrets: list[str],
        certificates: list[str],
        storage: list[str],
    ) -> dict[str, Any]:
        """
        Update access policy of an existing Key Vault.

        Args:
            subscription_id (str): Subscription ID.
            resource_group_name (str): Resource group name.
            vault_name (str): Key Vault name.
            operation_kind (str): The operation to make on the access policy.
            object_id (str): The object ID of a user, service principal or security group in the Azure Active Directory.
            keys (List[str]): Permissions to keys.
            secrets (List[str]): Permissions to secrets.
            certificates (List[str]): Permissions to certificates.
            storage (List[str]): Permissions to storage accounts.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        permissions = self.config_vault_permission(keys, secrets, certificates, storage)
        data = {
            "properties": {
                "accessPolicies": [{"objectId": object_id, "permissions": permissions, "tenantId": self.ms_client.tenant_id}]
            }
        }
        full_url = urljoin(
            self.azure_cloud.endpoints.resource_manager,
            f"subscriptions/{subscription_id}/resourceGroups/"
            f"{resource_group_name}/providers/Microsoft.KeyVault/vaults/"
            f"{vault_name}/accessPolicies/{operation_kind}",
        )

        return self.http_request("PUT", full_url=full_url, data=data, ok_codes=[200, 201])

    def get_key_request(self, vault_name: str, key_name: str, key_version: str) -> dict[str, Any]:
        """
        Get the public part of a stored key.

        Args:
            vault_name (str): Key Vault name.
            key_name (str): Key name.
            key_version (str): Key version.

        Returns:
            Dict[str, Any]: API response from Azure.
        """

        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/keys/{key_name}"
        if key_version:
            url = url + f"/{key_version}"
        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource())

        return response

    def list_keys_request(self, vault_name: str, limit: int, offset: int) -> list[dict]:
        """List keys in the specified Key Vault.

        Args:
            vault_name(str): Key Vault name.
            limit (str): Limit on the number of certificates to return. Default value is 50.
            offset(int): First index to retrieve from. Default value is 0.

        Returns:
            Dict[str, Any]: API response from Azure.

        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/keys"
        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource(), ok_codes=[200])

        return self.get_entities_independent_of_pages(response, limit, offset, self.get_vault_resource())

    def delete_key_request(self, vault_name: str, key_name: str) -> dict[str, Any]:
        """
        Delete a key of any type from storage in Azure Key vault.

        Args:
            vault_name (str): key vault's name.
            key_name (str): The name of the key to delete.

        Returns:
            Dict[str, Any]: response json
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/keys/{key_name}"
        response = self.http_request("DELETE", full_url=url, resource=self.get_vault_resource())

        return response

    def get_secret_request(self, vault_name: str, secret_name: str, secret_version: str) -> dict[str, Any]:
        """
        Retrieve secret by name from the specified key vault.

        Args:
            vault_name (str): Key vault's name.
            secret_name (str): The name of the secret to retrieve.
            secret_version (str) : The version of the secret.
        Returns:
            Dict[str, Any]: API response from Azure.
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/secrets/{secret_name}"
        if secret_version:
            url = url + f"/{secret_version}"
        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource())

        return response

    def list_secrets_request(self, vault_name: str, limit: int, offset: int) -> list[dict]:
        """
        List secrets by limit and offset from the specified Key Vault.

        Args:
            vault_name (str): Key Vault name.
            limit(int): Maximum number of secrets to retrieve.Default is 50.
            offset(int): First index to retrieve from. Default value is 0.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/secrets"
        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource())

        return self.get_entities_independent_of_pages(response, limit, offset, self.get_vault_resource())

    def delete_secret_request(self, vault_name: str, secret_name: str) -> dict[str, Any]:
        """
        Delete a secret by name from the specified Key Vault.

        Args:
            vault_name (str): Key vault's name.
            secret_name (str): The name of the secret to delete.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/secrets/{secret_name}"
        response = self.http_request("DELETE", full_url=url, resource=self.get_vault_resource())
        return response

    def get_certificate_request(self, vault_name: str, certificate_name: str, certificate_version: str) -> dict[str, Any]:
        """
        Retrieve certificate from the specified Key Vault.

        Args:
            vault_name (str): key vault's name.
            certificate_name (str): the name of the certificate to retrieve.
            certificate_version(str): The version of the certificate
        Returns:
            Dict[str, Any]: API response from Azure.
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/certificates/{certificate_name}"
        if certificate_version:
            url = url + f"/{certificate_version}"
        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource())

        return response

    def list_certificates_request(self, vault_name: str, limit: int, offset: int) -> list[dict]:
        """
        List certificates from the specified Key Vault.

        Args:
            vault_name (str): Key Vault name of the certificate.
            limit(int):maximum number of certificates to retrieve. Default is 50.
            offset (int): First index to retrieve from. Default value is 0.

        Returns:
            Dict[str, Any]: response json
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/certificates"

        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource())

        return self.get_entities_independent_of_pages(response, limit, offset, self.get_vault_resource())

    def get_certificate_policy_request(self, vault_name: str, certificate_name: str) -> dict[str, Any]:
        """
        Retrieve policy of the specified certificate.

        Args:
            vault_name (str): Key Vault name.
            certificate_name (str): the name of the certificate to retrieve its policy.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        url = f"https://{vault_name}{self.azure_cloud.suffixes.keyvault_dns}/certificates/{certificate_name}/policy"
        response = self.http_request("GET", full_url=url, resource=self.get_vault_resource())

        return response

    def list_subscriptions_request(self):
        """
        List all subscriptions.

        Returns:
            Dict[str, Any]: API response from Azure.
        """
        url = urljoin(self.azure_cloud.endpoints.resource_manager, "subscriptions?")
        response = self.http_request(
            "GET", full_url=url, resource=self.get_management_resource(), params={"api-version": "2020-01-01"}
        )
        return self.get_entities_independent_of_pages(
            first_page=response, limit=DEFAULT_LIMIT, offset=DEFAULT_OFFSET, resource=self.get_management_resource()
        )

    def list_resource_groups_request(self, subscription_id: str, tag: str, limit: int) -> list[dict]:
        """
        List all resource groups.

        Args:
            subscription_id (str): Subscription ID.
            tag str: Tag to filter by.
            limit (int): Maximum number of resource groups to retrieve. Default is 50.

        Returns:
            List[dict]: API response from Azure.
        """
        full_url = urljoin(self.azure_cloud.endpoints.resource_manager, f"subscriptions/{subscription_id}/resourcegroups?")
        filter_by_tag = azure_tag_formatter(tag) if tag else None

        response = self.http_request(
            "GET",
            full_url=full_url,
            resource=self.get_management_resource(),
            params={"$filter": filter_by_tag, "$top": limit, "api-version": "2021-04-01"},
            ok_codes=[200],
        )
        return self.get_entities_independent_of_pages(
            first_page=response, limit=limit, offset=DEFAULT_OFFSET, resource=self.get_management_resource()
        )

    """ INTEGRATION HELPER METHODS  """

    def config_vault_permission(
        self, keys: list[str], secrets: list[str], certificates: list[str], storage: list[str]
    ) -> dict[str, Any]:
        """
        Returns the permissions field of an access policy property of a Key Vault.

        Args:
            keys (List[str]): Permissions to keys.
            secrets (List[str]): Permissions to secrets.
            certificates (List[str]): Permissions to certificates.
            storage (List[str]): Permissions to storage accounts.

        Returns:
            Dict[str,Any]: permissions.
        """
        permissions = {}
        if keys:
            permissions["keys"] = keys
        if secrets:
            permissions["secrets"] = secrets
        if certificates:
            permissions["certificates"] = certificates
        if storage:
            permissions["storage"] = storage
        return permissions

    def config_vault_network_acls(
        self, default_action: str, bypass: str, vnet_sub_id: str, ignore_missing_vnet_service_endpoint: bool, ip_rules: list[str]
    ) -> dict[str, Any]:
        """
        Configure the network acl property of a Key Vault.

        Args:
            default_action (str): Default action.
            bypass (str): Tells what traffic can bypass network rules.
            vnet_sub_id (str): Full resource id of a vnet subnet.
            ignore_missing_vnet_service_endpoint (bool): Specify whether NRP will ignore the check.
            ip_rules (List[str]):The list of IP address rules.

        Returns:
            Dict[str,Any]: Network acls property.
        """
        network_acls: dict[str, Any] = {}
        if default_action:
            network_acls["defaultAction"] = default_action
        if bypass:
            network_acls["bypass"] = bypass
        if vnet_sub_id:
            network_acls["virtualNetworkRules"] = [
                {"id": vnet_sub_id, "ignoreMissingVnetServiceEndpoint": ignore_missing_vnet_service_endpoint}
            ]

        if ip_rules:
            network_acls["ipRules"] = []
            for ip in ip_rules:
                network_acls["ipRules"].append({"value": ip})

        return network_acls

    def config_vault_properties(
        self,
        object_id: str,
        tenant_id: str,
        enabled_for_deployment: bool,
        enabled_for_disk_encryption: bool,
        enabled_for_template_deployment: bool,
        sku_name: str,
        permissions: dict[str, Any],
        network_acls: dict[str, Any],
    ):
        """
        Configure the properties of a vault on create or update command.

        Args:
            object_id (str): The object ID of a user, service principal or security group in the Azure Active Directory.
            tenant_id (str):An identity that have access to the key vault.
            enabled_for_deployment (bool): permission for Azure VM to retrieve certificates stored as secrets.
            enabled_for_disk_encryption (bool): permission for Azure Disk Encryption to retrieve secrets.
            enabled_for_template_deployment (bool): permission for Azure Resource Manager to retrieve secrets.
            sku_name (str):Sku name.
            permissions (Dict[str,Any]): Key Vault access policy property.
            network_acls (Dict[str,Any]): Key Vault network acls property.

        Returns:
            Dict[str,Any]: Key Vault properties.
        """
        properties = {
            "accessPolicies": [{"objectId": object_id, "permissions": permissions, "tenantId": tenant_id}],
            "enabledForDeployment": enabled_for_deployment,
            "enabledForDiskEncryption": enabled_for_disk_encryption,
            "enabledForTemplateDeployment": enabled_for_template_deployment,
            "sku": {"family": "A", "name": sku_name},
            "tenantId": tenant_id,
        }

        if network_acls:
            properties["networkAcls"] = network_acls

        return properties

    def get_entities_independent_of_pages(
        self, first_page: dict[str, Any], limit: int, offset: int, resource: Optional[str] = None
    ) -> list[dict]:
        """
        List the entities according to the offset and limit arguments,
        following the first API call to the endpoint.
        The main purpose here is to list the entities regardless the
        restriction of the first API call - which returns only 25 entities at most.
        Used only for list commands.

        Args:
            first_page (Dict[str, Any]): The first list of entities which returned by the first API call.
            limit (int): limit on the number of entities to retrieve to the user.
            offset (int): first index to return from.
            resource (str | None): Azure resource. Default's to management resource.

        Returns:
            List[dict]: List of Key Vaults/Keys/Secrets/Certificates.
        """
        resource = resource or self.get_management_resource()
        entities = first_page.get("value", [])
        next_page_url = first_page.get("nextLink")
        # more entities to get
        while next_page_url and len(entities) < offset + limit:
            response = self.http_request("GET", full_url=next_page_url, resource=resource)

            entities = entities + response.get("value", [])
            next_page_url = response.get("nextLink")
        if offset > len(entities):
            return []
        return entities[offset : limit + offset]

    def get_secret_credentials(self, key_vault_name: str, secret_name: str):
        try:
            response = self.get_secret_request(key_vault_name, secret_name, "")
            secret_value = response["value"]
            return {"user": secret_name, "password": secret_value, "name": f"{key_vault_name}/{secret_name}"}
        except Exception:  # in case the secret does not exist in the vault
            return None


""" INTEGRATIONS COMMANDS"""


def create_or_update_key_vault_command(client: KeyVaultClient, args: dict[str, Any], params: dict[str, Any]) -> CommandResults:
    """
    Create or update Key Vault in the specified subscription.

    Args:
        client (KeyVaultClient):Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.
        params (Dict[str, Any]): Configuration parameters from XSOAR.

    Returns:
       CommandResults: outputs, readable outputs and raw response for XSOAR.
    """
    vault_name = args["vault_name"]
    object_id = args["object_id"]

    location = args.get("location", "westus")
    sku_name = args.get("sku_name", "standard")

    # access policy arguments
    keys_permissions = argToList(
        args.get("keys", ["get", "list", "update", "create", "import", "delete", "recover", "backup", "restore"])
    )

    secrets_permissions = argToList(args.get("secrets", ["get", "list", "set", "delete", "recover", "backup", "restore"]))
    certificates_permissions = argToList(
        args.get(
            "certificates",
            [
                "get",
                "list",
                "update",
                "create",
                "import",
                "delete",
                "recover",
                "backup",
                "restore",
                "managecontacts",
                "manageissuers",
                "getissuers",
                "listissuers",
                "setissuers",
                "deleteissuers",
            ],
        )
    )

    storage_accounts_permissions = argToList(
        args.get("storage", ["get", "list", "delete", "set", "update", "regeneratekey", "getsas", "listsas"])
    )

    enabled_for_deployment = argToBoolean(args.get("enabled_for_deployment", True))
    enabled_for_disk_encryption = argToBoolean(args.get("enabled_for_disk_encryption", True))
    enabled_for_template_deployment = argToBoolean(args.get("enabled_for_template_deployment", True))

    # network acl arguments
    default_action = args.get("default_action", "")
    bypass = args.get("bypass", "")
    vnet_subnet_id = args.get("vnet_subnet_id", "")
    ignore_missing_vnet_service_endpoint = argToBoolean(args.get("ignore_missing_vnet_service_endpoint", True))
    ip_rules = argToList(args.get("ip_rules"))
    # subscription_id and resource_group_name arguments can be passed as command arguments or as configuration parameters,
    # if both are passed as arguments, the command arguments will be used.
    subscription_id = get_from_args_or_params(params=params, args=args, key="subscription_id")
    resource_group_name = get_from_args_or_params(params=params, args=args, key="resource_group_name")

    response = client.create_or_update_key_vault_request(
        subscription_id,
        resource_group_name,
        vault_name,
        object_id,
        location,
        sku_name,
        keys_permissions,
        secrets_permissions,
        certificates_permissions,
        storage_accounts_permissions,
        enabled_for_deployment,
        enabled_for_disk_encryption,
        enabled_for_template_deployment,
        default_action,
        bypass,
        vnet_subnet_id,
        ignore_missing_vnet_service_endpoint,
        ip_rules,
    )

    readable_output = tableToMarkdown(
        f"{vault_name} Information",
        response,
        ["id", "name", "type", "location"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )

    return CommandResults(
        outputs_prefix="AzureKeyVault.KeyVault",
        outputs_key_field="id",
        outputs=response,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )


def delete_key_vault_command(client: KeyVaultClient, args: dict[str, Any], params: dict[str, Any]) -> CommandResults:
    """
    Delete Key Vault by name.

    Args:
        client (KeyVaultClient):Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.
        params (Dict[str, Any]): Configuration parameters from XSOAR.
    Returns:
       CommandResults: Command results with raw response, outputs and readable outputs.
    """

    vault_name = args["vault_name"]
    # subscription_id and resource_group_name arguments can be passed as command arguments or as configuration parameters,
    # if both are passed as arguments, the command arguments will be used.
    subscription_id = get_from_args_or_params(params=params, args=args, key="subscription_id")
    resource_group_name = get_from_args_or_params(params=params, args=args, key="resource_group_name")

    response = client.delete_key_vault_request(
        subscription_id=subscription_id, resource_group_name=resource_group_name, vault_name=vault_name
    )
    message = ""
    if response.get("status_code") == 200:
        message = f"Deleted Key Vault {vault_name} successfully."
    elif response.get("status_code") == 204:
        message = f"Key Vault {vault_name} does not exists."

    return CommandResults(readable_output=message)


def get_key_vault_command(client: KeyVaultClient, args: dict[str, Any], params: dict[str, Any]) -> CommandResults:
    """
    Retrieve Key Vault by name.

    Args:
        client (KeyVaultClient):Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.
        params (Dict[str, Any]): Configuration parameters from XSOAR.
    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.
    """
    vault_name = args["vault_name"]
    # subscription_id and resource_group_name arguments can be passed as command arguments or as configuration parameters,
    # if both are passed as arguments, the command arguments will be used.
    subscription_id = get_from_args_or_params(params=params, args=args, key="subscription_id")
    resource_group_name = get_from_args_or_params(params=params, args=args, key="resource_group_name")
    response = client.get_key_vault_request(
        subscription_id=subscription_id, resource_group_name=resource_group_name, vault_name=vault_name
    )

    readable_output = tableToMarkdown(
        f"{vault_name} Information",
        response,
        ["id", "name", "type", "location"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )
    return CommandResults(
        outputs_prefix="AzureKeyVault.KeyVault",
        outputs_key_field="id",
        outputs=response,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )


def list_key_vaults_command(client: KeyVaultClient, args: dict[str, Any], params: dict[str, Any]) -> CommandResults:
    """List Key Vaults associated with the subscription and within the specified resource group.

    Args:
        client (KeyVaultClient):Azure Key Vault API client
        args (Dict[str, Any]): Command arguments from XSOAR.
        params (Dict[str, Any]): Configuration parameters from XSOAR.
    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.
    """

    limit = arg_to_number(args.get("limit")) or DEFAULT_LIMIT
    offset = arg_to_number(args.get("offset")) or DEFAULT_OFFSET
    # subscription_id can be passed as a command argument or as a configuration parameter.
    # If both are passed, the command argument is used.
    subscription_id = get_from_args_or_params(params=params, args=args, key="subscription_id")
    response = client.list_key_vaults_request(subscription_id=subscription_id, limit=limit, offset=offset)

    readable_output = tableToMarkdown(
        "Key Vaults List", response, ["id", "name", "type", "location"], removeNull=True, headerTransform=string_to_table_header
    )
    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.KeyVault",
        outputs_key_field="id",
        outputs=response,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def update_access_policy_command(client: KeyVaultClient, args: dict[str, Any], params: dict[str, Any]) -> CommandResults:
    """
    Updates access policy of a key vault in the specified subscription.

    Args:
        client (KeyVaultClient):Azure Key Vault API client
        args (Dict[str, Any]): Command arguments from XSOAR.
        params (Dict[str, Any]): Configuration parameters from XSOAR.
    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.
    """
    vault_name = args["vault_name"]
    operation_kind = args["operation_kind"]
    object_id = args["object_id"]
    keys = argToList(args.get("keys"))
    secrets = argToList(args.get("secrets"))
    certificates = argToList(args.get("certificates"))
    storage_accounts = argToList(args.get("storage", []))
    # subscription_id and resource_group_name arguments can be passed as command arguments or as configuration parameters,
    # if both are passed as arguments, the command arguments will be used.
    subscription_id = get_from_args_or_params(params=params, args=args, key="subscription_id")
    resource_group_name = get_from_args_or_params(params=params, args=args, key="resource_group_name")

    response = client.update_access_policy_request(
        subscription_id, resource_group_name, vault_name, operation_kind, object_id, keys, secrets, certificates, storage_accounts
    )

    readable_output = tableToMarkdown(
        f"{vault_name} Updated Access Policy",
        response,
        ["id", "name", "type", "location"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )

    return CommandResults(
        outputs_prefix="AzureKeyVault.VaultAccessPolicy",
        outputs_key_field="id",
        outputs=response,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )


def get_key_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """Get the public part of a stored key.

    Args:
        client (KeyVaultClient): Azure Key Vault API client
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    key_name = args["key_name"]
    key_version = args.get("key_version", "")

    response = client.get_key_request(vault_name, key_name, key_version)
    cloned_response = copy.deepcopy(response)
    outputs = copy.deepcopy(response)
    outputs["attributes"] = convert_time_attributes_to_iso(outputs["attributes"])
    outputs["key_vault_name"] = vault_name

    readable_key_info = convert_key_info_to_readable(cloned_response["key"])
    readable_attrib = convert_attributes_to_readable(cloned_response["attributes"])

    readable_output = tableToMarkdown(
        f"{key_name} Information",
        {**readable_key_info, **readable_attrib},
        ["key_id", "enabled", "json_web_key_type", "key_operations", "create_time", "update_time", "expiry_time"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )

    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Key",
        outputs_key_field="kid",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def list_keys_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    List keys in the specified vault, in XSOAR's format, according to limit and offset arguments.

    Args:
        client (KeyVaultClient): Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    limit = arg_to_number(args.get("limit")) or DEFAULT_LIMIT
    offset = arg_to_number(args.get("offset")) or DEFAULT_OFFSET
    response = client.list_keys_request(vault_name, limit, offset)
    outputs = copy.deepcopy(response)
    readable_response = []

    for key in outputs:
        readable_response.append(
            {
                "key_id": key.get("kid"),
                "managed": key.get("managed"),
                **convert_attributes_to_readable(key.get("attributes", {}).copy()),
            }
        )
        key[VAULT_NAME_CONTEXT_FIELD] = vault_name
        key["attributes"] = convert_time_attributes_to_iso(key["attributes"])

    readable_output = tableToMarkdown(
        f"{vault_name} Keys List",
        readable_response,
        ["key_id", "enabled", "create_time", "update_time", "expiry_time"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )

    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Key",
        outputs_key_field="kid",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def delete_key_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    Delete a key of any type from storage in Azure Key vault.

    Args:
        client (KeyVaultClient): Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    key_name = args["key_name"]
    response = client.delete_key_request(vault_name, key_name)

    outputs = copy.deepcopy(response)
    outputs["deletedDate"] = convert_timestamp_to_readable_date(outputs["deletedDate"])
    outputs["scheduledPurgeDate"] = convert_timestamp_to_readable_date(outputs["scheduledPurgeDate"])

    readable_response = copy.deepcopy(outputs)
    readable_response["keyId"] = readable_response["key"]["kid"]

    outputs["attributes"] = convert_time_attributes_to_iso(outputs["attributes"])
    outputs[VAULT_NAME_CONTEXT_FIELD] = vault_name

    readable_output = tableToMarkdown(
        f"Delete {key_name}",
        readable_response,
        ["keyId", "recoveryId", "deletedDate", "scheduledPurgeDate"],
        removeNull=True,
        headerTransform=pascalToSpace,
    )
    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Key",
        outputs_key_field="recoveryId",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def get_secret_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    Retrieve secret from the specified Key Vault

    Args:
        client (KeyVaultClient):  Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    secret_name = args["secret_name"]
    secret_version = args.get("secret_version", "")
    response = client.get_secret_request(vault_name, secret_name, secret_version)
    outputs = copy.deepcopy(response)
    outputs["attributes"] = convert_time_attributes_to_iso(outputs["attributes"])
    readable_response = {
        "secret_id": response.get("id"),
        "managed": response.get("managed"),
        "key_id": response.get("kid"),
        **convert_attributes_to_readable(response.get("attributes", {}).copy()),
    }
    outputs[VAULT_NAME_CONTEXT_FIELD] = vault_name

    readable_output = tableToMarkdown(
        f"{secret_name} Information",
        readable_response,
        ["secret_id", "enabled", "create_time", "update_time", "expiry_time"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )
    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Secret",
        outputs_key_field="id",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def list_secrets_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    List secrets in the specified key vault.

    Args:
        client (KeyVaultClient): Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    limit = arg_to_number(args.get("limit")) or DEFAULT_LIMIT
    offset = arg_to_number(args.get("offset")) or DEFAULT_OFFSET
    response = client.list_secrets_request(vault_name, limit, offset)
    outputs = copy.deepcopy(response)
    readable_response = []

    for secret in outputs:
        readable_response.append(
            {
                "secret_id": secret.get("id"),
                "managed": secret.get("managed"),
                **convert_attributes_to_readable(secret.get("attributes", {}).copy()),
            }
        )
        secret[VAULT_NAME_CONTEXT_FIELD] = vault_name
        secret["attributes"] = convert_time_attributes_to_iso(secret["attributes"])

    readable_output = tableToMarkdown(
        f"{vault_name} Secrets List",
        readable_response,
        ["secret_id", "enabled", "create_time", "update_time", "expiry_time"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )

    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Secret",
        outputs_key_field="id",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def delete_secret_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    Delete secret from the specified Key Vault.

    Args:
        client (KeyVaultClient): Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    secret_name = args["secret_name"]

    response = client.delete_secret_request(vault_name, secret_name)

    outputs = copy.deepcopy(response)
    outputs["deletedDate"] = convert_timestamp_to_readable_date(outputs["deletedDate"])
    outputs["scheduledPurgeDate"] = convert_timestamp_to_readable_date(outputs["scheduledPurgeDate"])

    readable_response = copy.deepcopy(outputs)
    outputs["attributes"] = convert_time_attributes_to_iso(outputs["attributes"])
    outputs[VAULT_NAME_CONTEXT_FIELD] = vault_name

    readable_response["secretId"] = readable_response.pop("id")
    readable_output = tableToMarkdown(
        f"Delete {secret_name}",
        readable_response,
        ["secretId", "recoveryId", "deletedDate", "scheduledPurgeDate"],
        removeNull=True,
        headerTransform=pascalToSpace,
    )
    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Secret",
        outputs_key_field="recoveryId",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def get_certificate_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    Get information about a certificate.

    Args:
        client (KeyVaultClient): Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args.get("vault_name", "")
    certificate_name = args.get("certificate_name", "")
    certificate_version = args.get("certificate_version", "")
    response = client.get_certificate_request(vault_name, certificate_name, certificate_version)

    outputs = copy.deepcopy(response)
    outputs["attributes"] = convert_time_attributes_to_iso(outputs["attributes"])
    outputs["policy"]["attributes"] = convert_time_attributes_to_iso(outputs["policy"]["attributes"])

    readable_response = {
        "certificate_id": response.get("id"),
        **convert_attributes_to_readable(response.get("attributes", {}).copy()),
    }
    outputs[VAULT_NAME_CONTEXT_FIELD] = vault_name

    readable_output = tableToMarkdown(
        f"{certificate_name} Information",
        readable_response,
        ["certificate_id", "enabled", "create_time", "update_time", "expiry_time"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )
    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Certificate",
        outputs_key_field="id",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def list_certificates_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    List certificates in the specified Key Vault.

    Args:
        client (KeyVaultClient): Azure Key Vault API client.
        args (Dict[str, Any]): Command arguments from XSOAR.


    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    limit = arg_to_number(args.get("limit")) or DEFAULT_LIMIT
    offset = arg_to_number(args.get("offset")) or DEFAULT_OFFSET

    response = client.list_certificates_request(vault_name, limit, offset)
    outputs = copy.deepcopy(response)

    readable_response = []
    for certificate in outputs:
        readable_response.append(
            {"certificate_id": certificate.get("id"), **convert_attributes_to_readable(certificate.get("attributes", {}).copy())}
        )
        certificate[VAULT_NAME_CONTEXT_FIELD] = vault_name
        certificate["attributes"] = convert_time_attributes_to_iso(certificate["attributes"])

    readable_output = tableToMarkdown(
        f"{vault_name} Certificates List",
        readable_response,
        ["certificate_id", "enabled", "create_time", "update_time", "expiry_time"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )

    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.Certificate",
        outputs_key_field="id",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
        ignore_auto_extract=True,
    )

    return command_results


def get_certificate_policy_command(client: KeyVaultClient, args: dict[str, Any]) -> CommandResults:
    """
    Retrieve policy of the specified certificate.

    Args:
        client (KeyVaultClient):  Azure Key Vault API client.
        args (Dict[str, Any]): command arguments.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    vault_name = args["vault_name"]
    certificate_name = args["certificate_name"]
    response = client.get_certificate_policy_request(vault_name, certificate_name)
    outputs = copy.deepcopy(response)
    outputs["attributes"] = convert_time_attributes_to_iso(outputs["attributes"])
    outputs["CertificateName"] = certificate_name

    readable_output = tableToMarkdown(
        f"{certificate_name} Policy Information",
        outputs,
        ["id", "key_props", "secret_props", "x509_props", "issuer", "attributes"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )
    command_results = CommandResults(
        outputs_prefix="AzureKeyVault.CertificatePolicy",
        outputs_key_field="id",
        outputs=outputs,
        raw_response=response,
        readable_output=readable_output,
    )

    return command_results


def list_subscriptions_command(client: KeyVaultClient) -> CommandResults:
    """
    List all subscriptions in the tenant.

    Args:
        client (KeyVaultClient):  Azure Key Vault API client.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    response = client.list_subscriptions_request()

    readable_output = tableToMarkdown(
        "Subscriptions List",
        response,
        ["subscriptionId", "tenantId", "state", "displayName"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )
    return CommandResults(
        outputs_prefix="AzureKeyVault.Subscription",
        outputs_key_field="id",
        outputs=response,
        raw_response=response,
        readable_output=readable_output,
    )


def list_resource_groups_command(client: KeyVaultClient, args: dict[str, Any], params: dict[str, Any]) -> CommandResults:
    """
    List all resource groups in the subscription.

    Args:
        client (KeyVaultClient):  Azure Key Vault API client.
        args (Dict[str, Any]): command arguments.
        params (Dict[str, Any]): configuration parameters.

    Returns:
        CommandResults: Command results with raw response, outputs and readable outputs.

    """
    tag = args.get("tag", "")
    limit = arg_to_number(args.get("limit")) or DEFAULT_LIMIT
    # subscription_id can be passed as a command argument or as a configuration parameter.
    # If both are passed, the command argument is used.
    subscription_id = get_from_args_or_params(params=params, args=args, key="subscription_id")

    response = client.list_resource_groups_request(subscription_id=subscription_id, tag=tag, limit=limit)

    readable_output = tableToMarkdown(
        "Resource Groups List",
        response,
        ["name", "location", "tags", "properties.provisioningState"],
        removeNull=True,
        headerTransform=string_to_table_header,
    )
    return CommandResults(
        outputs_prefix="AzureKeyVault.ResourceGroup",
        outputs_key_field="id",
        outputs=response,
        raw_response=response,
        readable_output=readable_output,
    )


def test_module(client: KeyVaultClient, params: dict[str, Any]) -> None:
    """
    Test instance parameters validity.
    Displays an appropriate message in case of invalid parameters.

    Args:
        client (KeyVaultClient):  Azure Key Vault API client.
        params (Dict[str, Any]): configuration parameters.

    Returns:
        None
    """
    try:
        subscription_id = params.get("subscription_id")
        client.ms_client.get_access_token(resource=client.get_management_resource())
        client.ms_client.get_access_token(resource=client.get_vault_resource())
        client.list_key_vaults_request(subscription_id=subscription_id, limit=1, offset=0)
        return_results("ok")

    except Exception:
        raise


def fetch_credentials(
    client: KeyVaultClient,
    key_vaults_to_fetch_from: list[str],
    secrets_to_fetch: list[str],
    credentials_name: str,
    fetch_mode: str = STORE_IN_CORTEX_MODE,
) -> None:
    """
    Fetch credentials from secrets which reside in the specified Key Vaults list.
    This command supports two scenarios:
    1. Fetch a specific set of credentials: assuming that the credentials name is written
       in the format of: KEY_VAULT_NAME/SECRET_NAME. In this case, when credentials_name != None, the secret value is always
       fetched live from Azure Key Vault (this is the runtime lookup used by both modes).
    2. Fetch credentials based on instance parameters: key_vaults list and secret list.
       The behavior of this scenario depends on ``fetch_mode``:
       - "Store in Cortex" (default): the actual secret values are fetched and returned so
         Cortex stores them in the credentials store.
       - "External Credentials Vault (on-demand)": only the credential names
         (KEY_VAULT_NAME/SECRET_NAME) are returned, with empty passwords. No secret values
         are fetched from Azure Key Vault and nothing is persisted in Cortex. The value
         is fetched live only when an integration requests a specific credential by identifier.
    Args:
        client (KeyVaultClient):  Azure Key Vault API client.
        key_vaults_to_fetch_from (List[str]): List of Key Vaults to fetch secrets from.
        secrets_to_fetch (List[str]): List of secrets to fetch.
        credentials_name (str): Name of a specific set of credentials to fetch.
        fetch_mode (str): The credentials fetch mode. One of STORE_IN_CORTEX_MODE or ON_DEMAND_MODE.

    Returns:
        None
    """
    credentials = []

    if credentials_name:
        credentials_name_arr = credentials_name.split("/")
        key_vault = credentials_name_arr[0]
        secret = credentials_name_arr[1]
        credentials = [client.get_secret_credentials(key_vault, secret)]

    else:
        if len(key_vaults_to_fetch_from) == 0:
            return_results("No key vaults to fetch secrets from were specified.")
        if len(secrets_to_fetch) == 0:
            return_results("No secrets were specified.")
        for key_vault in key_vaults_to_fetch_from:
            for secret in secrets_to_fetch:
                if fetch_mode == ON_DEMAND_MODE:
                    # On-demand mode: return only the credential name, without fetching the secret value.
                    credentials.append({"user": secret, "password": "", "name": f"{key_vault}/{secret}"})
                else:
                    secret_cred = client.get_secret_credentials(key_vault, secret)
                    if secret_cred:
                        credentials.append(secret_cred)

    demisto.credentials(credentials)


def convert_attributes_to_readable(attributes: dict[str, Any]) -> dict[str, Any]:
    """
    Convert attributes fields to be readable for the user.

    Args:
        attributes (Dict[str, Any]): Object attributes field.

    Returns:
        Dict[str, Any] : Readable attributes.

    """
    attributes_fields_mapper = {
        "nbf": "should_not_be_retrieved_Before",
        "exp": "expiry_time",
        "created": "create_time",
        "updated": "update_time",
        "recoveryLevel": "recovery_level",
    }

    for key, value in attributes_fields_mapper.items():
        if key in attributes:
            if key != "recoveryLevel":
                attributes[value] = convert_timestamp_to_readable_date(attributes.pop(key))
            else:
                attributes[value] = attributes.pop(key)
    return attributes


def convert_key_info_to_readable(key_info: dict[str, Any]) -> dict[str, Any]:
    """
    Convert key fields to be readable for the user.

    Args:
        key_info (Dict[str, Any]): key field of Key object.

    Returns:
        Dict[str, Any] : Readable key information.

    """
    key_fields = {
        "kid": "key_id",
        "kty": "json_web_key_type",
        "key_ops": "key_operations",
        "n": "RSA_modulus",
        "e": "RSA_public_components",
    }
    for key, value in key_fields.items():
        if key in key_info:
            key_info[value] = key_info.pop(key)

    return key_info


def convert_time_attributes_to_iso(attributes: dict[str, Any]) -> dict[str, Any]:
    """
    Convert attributes fields to be readable for the user.

    Args:
        attributes (Dict[str, Any]): Object attributes field.

    Returns:
        Dict[str, Any] : attributes property with time fields in ISO 8601 format.

    """
    time_attributes_fields = {
        "nbf",
        "exp",
        "created",
        "updated",
    }

    for field in attributes:
        if field in time_attributes_fields:
            attributes[field] = convert_timestamp_to_readable_date(attributes[field])

    return attributes


def convert_timestamp_to_readable_date(timestamp: int) -> str:
    """
    Convert timestamp number to readable date.
    Args:
        timestamp (Dict[str, Any]): timestamp as integer.

    Returns:
        str : Date in ISO 8601 format.
    """
    return datetime.utcfromtimestamp(timestamp).isoformat()


def main() -> None:  # pragma: no cover
    params: dict[str, Any] = demisto.params() or {}
    args: dict[str, Any] = demisto.args() or {}
    key_vaults_to_fetch_from = argToList(params.get("key_vaults", []))
    secrets_to_fetch = argToList(params.get("secrets", []))
    credentials_fetch_mode = params.get("credentials_fetch_mode", STORE_IN_CORTEX_MODE)
    verify_certificate: bool = not params.get("insecure", False)
    proxy = params.get("proxy", False)
    identifier = args.get("identifier", "")
    azure_cloud = get_azure_cloud(params, "AzureKeyVault")
    managed_identities_client_id = get_azure_managed_identities_client_id(params)
    command = demisto.command()
    demisto.debug(f"Command being called is {command}")
    try:
        client_secret = params.get("credentials", {}).get("password", "")
        certificate_thumbprint = params.get("credentials_certificate_thumbprint", {}).get("password") or params.get(
            "certificate_thumbprint"
        )
        private_key = params.get("private_key")
        if not managed_identities_client_id and not client_secret and not (certificate_thumbprint and private_key):
            raise DemistoException(
                "Client Secret or Certificate Thumbprint and Private Key must be provided. For further information see https://xsoar.pan.dev/docs/reference/articles/microsoft-integrations---authentication"
            )  # noqa: E501

        urllib3.disable_warnings()
        client: KeyVaultClient = KeyVaultClient(
            tenant_id=params.get("tenant_id", None),
            client_id=params.get("client_id", None),
            client_secret=client_secret,
            subscription_id=params.get("subscription_id", None),
            resource_group_name=params.get("resource_group_name", None),
            verify=verify_certificate,
            proxy=proxy,
            certificate_thumbprint=certificate_thumbprint,
            private_key=private_key,
            managed_identities_client_id=managed_identities_client_id,
            azure_cloud=azure_cloud,
        )

        commands_with_args = {
            "azure-key-vault-key-get": get_key_command,
            "azure-key-vault-key-list": list_keys_command,
            "azure-key-vault-key-delete": delete_key_command,
            "azure-key-vault-secret-get": get_secret_command,
            "azure-key-vault-secret-list": list_secrets_command,
            "azure-key-vault-secret-delete": delete_secret_command,
            "azure-key-vault-certificate-get": get_certificate_command,
            "azure-key-vault-certificate-list": list_certificates_command,
            "azure-key-vault-certificate-policy-get": get_certificate_policy_command,
        }
        commands_without_args = {"azure-key-vault-subscriptions-list": list_subscriptions_command}

        commands_with_params = {"test-module": test_module}

        commands_with_args_and_params = {
            "azure-key-vault-create-update": create_or_update_key_vault_command,
            "azure-key-vault-delete": delete_key_vault_command,
            "azure-key-vault-get": get_key_vault_command,
            "azure-key-vault-list": list_key_vaults_command,
            "azure-key-vault-access-policy-update": update_access_policy_command,
            "azure-key-vault-resource-group-list": list_resource_groups_command,
        }

        if command in commands_without_args:
            return_results(commands_without_args[command](client))
        elif command in commands_with_args:
            return_results(commands_with_args[command](client, args))
        elif command in commands_with_params:
            return_results(commands_with_params[command](client, params))
        elif command in commands_with_args_and_params:
            return_results(commands_with_args_and_params[command](client, args, params))
        elif demisto.command() == "fetch-credentials":
            fetch_credentials(client, key_vaults_to_fetch_from, secrets_to_fetch, identifier, credentials_fetch_mode)
        elif demisto.command() == "azure-key-vault-auth-reset":
            return_results(reset_auth())
        else:
            raise NotImplementedError(f"{command} command is not implemented.")

    except Exception as error:
        str_error = str(error)
        custom_message = f"Failed to execute {command} command.\nError: \n"
        if "InvalidSubscriptionId" in str_error:
            custom_message += "Invalid or missing subscription ID. Please verify your subscription ID."
        elif "SubscriptionNotFound" in str_error:
            custom_message += "The given subscription ID could not be found."
        elif "perform action" in str_error:
            custom_message += "The client does not have Key Vault permissions to \
the given resource group name or the resource group name does not exist."

        return_error(custom_message + "\n" + str_error if hasattr(error, "message") else custom_message)


if __name__ in ("__main__", "__builtin__", "builtins"):
    main()