我在这里有一个api请求,该请求应检查某些SSL证书的有效性。到目前为止,我已经完成了脚本。现在我想使其自动化一点。我想要一个列表,我可以在其中插入域,并且应该将这些域分配给某些标签。我该如何最好地解决这个问题?
import requests
domain = [["test1.com", "test2.com"]]
tags = [["env:test1", "env:test2", "application:test1", "application:test2"]]
headers = {
'Content-Type': 'application/json',
}
params = (
('api_key', 'xxx'),
('application_key', 'xxx'),
)
data = '{\n "config":{\n "assertions":[\n {\n "operator": "isInMoreThan",\n "type": "certificate",\n "target": 10\n }\n ],\n "request":{\n "host": "domain_name_here",\n "port": 443\n }\n },\n "locations":[\n "aws:eu-central-1" \n ],\n "message":" @person@person.com @person2@person2.com\\nSSL Certificate for domain_name_here is going to expire in less than 10 days.",\n "name":"SSL Test on domain_name_here",\n "options":{\n "min_failure_duration": 0,\n "tick_every": 86400,\n "min_location_failed": 1\n },\n "tags":[\n "tag_here",\n "tag_here_2"\n ],\n "type":"api",\n "subtype": "ssl"\n}'
response = requests.post('https://example.com', headers=headers, data=data)
如您所见,我已经创建了一个列表。域和标记都一样。现在我希望脚本在域存在的情况下执行。在data =“ host”下:应该替换该域。在“名称”下:域也应替换。此外,我想在某些域上有目的地分配标签。
答案 0 :(得分:1)
您可能想要字典来映射它们。
以下示例使用Python 3.6 commits
字符串进行格式化;如果您需要支持较旧的Python 3,请替换为f
插值或%
调用。
.format()