0

I am new to AzureCLI script. I request some guidance here:

Please find the secret(masked value) from my Azure key vault.

{
"**attributes**": {

  "created": "2021-10-23T04:26:19+00:00",

  "enabled": true,

  "id": "https://app-kv-axderfctt.vault.azure.net/secrets/connectionstr/cbcncbc",

  "name": "connectionstr",

  "**value**": "\"{\\\"eventHubNameSpace\\\":\\\"Pji-11111111-132d-46f7-af0f-aq1234\\\",\\\"eventHubName\\\":\\\"pipeline-swswsw-fb95-4e16-8364-oiu8ikji\\\",\\\"**ConnectionString**\\\":\\\"Endpoint=sb://pji-uit8tihj-132d-46f7-af0f-89897899.servicebus.windows.net/;SharedAccessKeyName=343456-ddddd-4720-b3db-oi89087;SharedAccessKey=xxxx+xxxxxxxx=;EntityPath=pipeline-ttrgfrtyh-fb95-4e16-8364-897uy678i\\\"}\""

I am able to get the complete value but not the specific property(ConnectionString) using below command

CONNECTION_STRING=$(az keyvault secret show --vault-name ${{ parameters.KeyVault }} --name ${{ parameters.SecretName}}--query 'value.ConnectionString')
                    
echo "$CONNECTION_STRING"

I get below error: ERROR: incorrect usage: [Required] --value VALUE | --file PATH

Please advise on how to extract ConnectionString value excluding EntityPath by escaping slashes \\\.

Thanks in advance.

student
  • 1,001
  • 2
  • 12
  • 24

1 Answers1

0

I resolved this issue using jq library

  • task: Bash@3 displayName: "Parse WarmRepo Connection String" inputs: targetType: 'inline' script: | # Parse WarmRepo Connection String echo 'Parse WarmRepo Connection String'

                  #Refer https://stedolan.github.io/jq/ to know about jq queries
    
                  PipelineConnectionString=`jq -r '.ConnectionString' <<<'$(${{ parameters.StreamingPipelineName }}-EventHub-connectionString)'`