【问题标题】:How To Call Secrets within a Bash Script如何在 Bash 脚本中调用 Secret
【发布时间】:2020-07-05 12:52:13
【问题描述】:

所以我知道一种在 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 插入一个 web-hook 链接。 有没有办法在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 脚本中处理秘密的指导。

【问题讨论】:

    标签: linux bash shell automation scripting


    【解决方案1】:

    与 Python 的 webhook_url = (config['slack_config']['slack_target_url']) 等效的 Bash 将是 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-23
      • 1970-01-01
      • 2018-06-19
      • 2015-09-01
      相关资源
      最近更新 更多