def __init__(self, config): super(BaseAction, self).__init__(config) self.credentials = { 'region': None, 'aws_access_key_id': None, 'aws_secret_access_key': None } self.userdata = None if config.get('st2_user_data', None): try: with open(config['st2_user_data'], 'r') as fp: self.userdata = fp.read() except IOError as e: self.logger.error(e) # Note: In old static config credentials and region are under "setup" key and with a new # dynamic config values are top-level access_key_id = config.get('aws_access_key_id', None) secret_access_key = config.get('aws_secret_access_key', None) region = config.get('region', None) if access_key_id and secret_access_key: self.credentials['aws_access_key_id'] = access_key_id self.credentials['aws_secret_access_key'] = secret_access_key self.credentials['region'] = region elif 'setup' in config: # Assume old-style config self.credentials = config['setup'] self.resultsets = ResultSets()
def __init__(self, config): super(BaseAction, self).__init__(config) if config['st2_user_data'] is not "": self.userdata = open(config['st2_user_data'], 'r').read() else: self.userdata = None self.setup = config['setup'] self.resultsets = ResultSets()
def __init__(self, config): super(BaseAction, self).__init__(config) self.credentials = { 'region': None, 'aws_access_key_id': None, 'aws_secret_access_key': None } self.debug = config.get('debug', False) self.userdata = None if config.get('st2_user_data', None): # Check if string "looks" like a normal absolute path if os.path.isabs(config['st2_user_data'] ) and '\n' not in config['st2_user_data']: # Read in default user data from file try: with open(config['st2_user_data'], 'r') as fp: self.userdata = fp.read() except IOError as e: self.logger.error(e) else: self.userdata = config['st2_user_data'] # Note: In old static config credentials and region are under "setup" key and with a new # dynamic config values are top-level access_key_id = config.get('aws_access_key_id', None) secret_access_key = config.get('aws_secret_access_key', None) region = config.get('region', None) if access_key_id == "None": access_key_id = None if secret_access_key == "None": secret_access_key = None if access_key_id and secret_access_key: self.credentials['aws_access_key_id'] = access_key_id self.credentials['aws_secret_access_key'] = secret_access_key elif 'setup' in config: # Assume old-style config self.credentials = config['setup'] if region: self.credentials['region'] = region self.session = Session( aws_access_key_id=self.credentials['aws_access_key_id'], aws_secret_access_key=self.credentials['aws_secret_access_key']) self.account_id = self.session.client('sts').get_caller_identity().get( 'Account') self.cross_roles = { arn.split(':')[4]: arn for arn in self.config.get('actions', {}).get('roles', []) } self.resultsets = ResultSets()