当前位置: 首页>>代码示例>>Python>>正文


Python Session.get_credentials方法代码示例

本文整理汇总了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
开发者ID:forestmonster,项目名称:diffy,代码行数:34,代码来源:plugin.py

示例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'},
开发者ID:miztiik,项目名称:AWS-Demos,代码行数:32,代码来源:setup-wordpress-in-ec2-in-5-minutes-with-boto.py


注:本文中的boto3.Session.get_credentials方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。