本文整理汇总了Python中boto3.Session.get_credentials方法的典型用法代码示例。如果您正苦于以下问题:Python Session.get_credentials方法的具体用法?Python Session.get_credentials怎么用?Python Session.get_credentials使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类boto3.Session
的用法示例。
在下文中一共展示了Session.get_credentials方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: generate
# 需要导入模块: from boto3 import Session [as 别名]
# 或者: from boto3.Session import get_credentials [as 别名]
def generate(self, incident: str, **kwargs) -> List[str]:
"""Generates the commands that will be run on the host."""
logger.debug("Generating osquery payload.")
session = Session()
# TODO check for existence before deployment
# we run with these commands with diffy credentials so as to not pollute the on-instance credentials
creds = session.get_credentials()
region = kwargs.get("region", CONFIG.get("DIFFY_PAYLOAD_OSQUERY_REGION"))
key = kwargs.get("key", CONFIG.get("DIFFY_PAYLOAD_OSQUERY_KEY"))
if not region:
raise BadArguments(
"DIFFY_PAYLOAD_OSQUERY_REGION required for use with OSQuery plugin."
)
if not key:
raise BadArguments(
"DIFFY_PAYLOAD_OSQUERY_KEY required for use with OSQuery plugin."
)
commands: List[str] = [
f"export AWS_ACCESS_KEY_ID={creds.access_key}",
f"export AWS_SECRET_ACCESS_KEY={creds.secret_key}",
f"export AWS_SESSION_TOKEN={creds.token}",
f"cd $(mktemp -d -t binaries-{incident}-`date +%s`-XXXXXX)",
f"aws s3 --region {region} cp s3://{key} ./latest.tar.bz2 --quiet",
"tar xvf latest.tar.bz2 &>/dev/null",
]
commands += CONFIG.get("DIFFY_PAYLOAD_OSQUERY_COMMANDS")
return commands
示例2: Session
# 需要导入模块: from boto3 import Session [as 别名]
# 或者: from boto3.Session import get_credentials [as 别名]
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Check if the user has the Access & Secret key configured
import boto3
import time
from boto3 import Session
session = Session()
credentials = session.get_credentials()
current_credentials = credentials.get_frozen_credentials()
# Break & Exit if any of the key is not present
if current_credentials.access_key is None:
print("Access Key missing, use `aws configure` to setup")
exit()
if current_credentials.secret_key is None:
print("Secret Key missing, use `aws configure` to setup")
exit()
# VPC design for multi az deployments
globalVars = {}
globalVars['REGION_NAME'] = "ap-south-1"
globalVars['AZ1'] = "ap-south-1a"
globalVars['AZ2'] = "ap-south-1b"
globalVars['CIDRange'] = "10.240.0.0/23"
globalVars['az1_pvtsubnet_CIDRange'] = "10.240.0.0/25"
globalVars['az1_pubsubnet_CIDRange'] = "10.240.0.128/26"
globalVars['az1_sparesubnet_CIDRange'] = "10.240.0.192/26"
globalVars['az2_pvtsubnet_CIDRange'] = "10.240.1.0/25"
globalVars['az2_pubsubnet_CIDRange'] = "10.240.1.128/26"
globalVars['az2_sparesubnet_CIDRange'] = "10.240.1.192/26"
globalVars['Project'] = { 'Key': 'Name', 'Value': 'WordPress-Demo'}
globalVars['tags'] = [{'Key': 'Owner', 'Value': 'Miztiik'},