简体   繁体   中英

How To Call Secrets within a Bash Script

So I know of a way to work with secrets in Powershell Scripts and in Python Scripts. I am curious if there is a way to call json, yml, or json objects within a bash script. What would you use and how can one call them dynamically within the script.

Here is the script:

#!/bin/bash
# ===========================================================
# Created By: Richard Barrett
# Organization: Mirantis
# Department: Customer Success Operation
# Purpose: Send Message to Slack Channel
# Date: 03/20/2020
# ===========================================================
# Use Messages in this command syntax
# curl -X POST -H 'Content-type: application/json' --data '{"text":"BODY"}' <insert_URL>

# Generalt Message:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Please see the following links for Handovers and Change Requests that may impact your shift."}' https://hooks.slack.com/services/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

# Messages for Handover:
curl -X POST -H 'Content-type: application/json' --data '{"text":"Handovers: https://mirantis.my.salesforce.com/00O2S000003g25h"}' <insert_URL>

# Message for All Change Requests:
curl -X POST -H 'Content-type: application/json' --data '{"text":"All Change Requests: https://mirantis.my.salesforce.com/00O2S000004INH1"}' <insert_URL>

# Message for Change Requests in Ready to Execute
# curl -X POST -H 'Content-type: application/json' --data '{"text":"All CRs in Ready to Execute:"}' <insert_URL>

Where it says I am inserting a web-hook link via slack. Is there a way to call this in similar to the following json method in python?

with open('secrets.json','r') as f:
      config = json.load(f)

# Set the webhook_url to the one provided by Slack when you create the webhook at https://my.slack.com/services/new/incoming-webhook/
# webhook_url = 'https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX'
# slack_data = {'text': "BODY"}
webhook_url = (config['slack_config']['slack_target_url'])
slack_message_1={'text': config['slack_messages']['message_1']}
slack_message_2={'text': config['slack_messages']['message_2']}
slack_message_3={'text': config['slack_messages']['message_3']}

I also know that one can make an xml file and load that into the Powershell script as a secret. I just need some direction on how to work with secrets in a shell script.

The Bash equivalent to Python's webhook_url = (config['slack_config']['slack_target_url']) would be webhook_url="$(jq --raw-output .slack_config.slack_target_url secrets.json)" . Demo:

$ echo '{"slack_config": {"slack_target_url": "URL"}}' | jq --raw-output .slack_config.slack_target_url
URL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM