export specific secret value as an environment variable
Hello 1Password Community :)
I am trying to fetch and export a specific secret value as an environment variable:
what I tried: - Note that I replaced the actual gcp location with [gcp location]
export AIRFLOW_SERVICE_ACCOUNT=$(op item get --cache --format=json [gcp location] | jq -r '.fields[]|select(.id="secret")|.value')
Then I fetch the environment variable as follows:
airflow_service_account = os.environ["AIRFLOW_SERVICE_ACCOUNT"]
service_account_json = "service-account.json"
with open(service_account_json, "w") as f:
f.write(airflow_service_account)
Error:
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 5)
when I run the following in the terminal:
op item get --cache --format=json [gcp location] | jq -r '.fields[]|select(.id="secret")|.value'
I get the following result (note that I replaced private data with the word bla
null
{
"type": "service_account",
"project_id": "bla",
"private_key_id": "bla",
"private_key": "-----BEGIN PRIVATE KEY-----\nbla\n-----END PRIVATE KEY-----\n",
"client_email": "bla",
"client_id": "bla",
"auth_uri": "bla",
"token_uri": "bla",
"auth_provider_x509_cert_url": "bla",
"client_x509_cert_url": "bla"
}
I hope I was clear enough in my description.
Does anyone know what modifications I need to do to properly fetch this concerned service-account dict?
Thank you for your time :)
1Password Version: 7.9.4
Extension Version: Not Provided
OS Version: macOS 12.3.1
