簡體   English   中英

如何在 Bash 腳本中調用 Secret

[英]How To Call Secrets within a Bash Script

所以我知道一種在 Powershell 腳本和 Python 腳本中處理秘密的方法。 我很好奇是否有辦法在 bash 腳本中調用 json、yml 或 json 對象。 您將使用什么以及如何在腳本中動態調用它們。

這是腳本:

#!/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>

它說我正在通過 slack 插入一個網絡鈎子鏈接。 有沒有辦法在類似於python中的以下json方法中調用它?

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']}

我也知道可以制作一個xml文件並將其作為秘密加載到Powershell腳本中。 我只需要一些關於如何在 shell 腳本中使用機密的指導。

相當於 Python 的webhook_url = (config['slack_config']['slack_target_url'])將是webhook_url="$(jq --raw-output .slack_config.slack_target_url secrets.json)" 演示:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM