def __init__(self, credentials, url=None, region='us-east-1', proxyinfo=None): if not url: endpoint = CloudFormationClient.endpointForRegion(region) else: endpoint = url self.using_instance_identity = ( not credentials or not credentials.access_key) and util.is_ec2() if not self.using_instance_identity: if not region: region = CloudFormationClient.regionForEndpoint(endpoint) if not region: raise ValueError('Region is required for AWS V4 Signatures') signer = CFNSigner() if self.using_instance_identity else V4Signer( region, 'cloudformation') super(CloudFormationClient, self).__init__(credentials, True, endpoint, signer, proxyinfo=proxyinfo) log.debug("CloudFormation client initialized with endpoint %s", endpoint)
def __init__(self, stack_name, hooks, sqs_client, cfn_client, multi_threaded): """Takes a list of Hook objects and processes them""" self.stack_name = stack_name self.hooks = self._hooks_by_path(hooks) self.sqs_client = sqs_client self.cfn_client = cfn_client self.multi_threaded = multi_threaded if not self.multi_threaded: log.debug("Enabled single threading mode."); if util.is_ec2(): self.listener_id = util.get_instance_id() elif not cfn_client.using_instance_identity: self.listener_id = socket.getfqdn() else: raise ValueError("Could not retrieve instance id") self._creds_provider = AutoRefreshingCredentialsProvider(self.cfn_client, self.stack_name, self.listener_id) self.queue_url = None self._create_storage_dir() self._runfile = os.path.join(self.storage_dir, 'commands_run.json') self._commands_run = self._load_commands_run() if not 'by_id' in self._commands_run: self._commands_run['by_id'] = {} if not 'by_day' in self._commands_run: self._commands_run['by_day'] = {} self._currently_running = set() self._currently_running_lock = threading.RLock() self._commands_run_lock = threading.RLock()
def __init__(self, stack_name, hooks, sqs_client, cfn_client): """Takes a list of Hook objects and processes them""" self.stack_name = stack_name self.hooks = self._hooks_by_path(hooks) self.sqs_client = sqs_client self.cfn_client = cfn_client self.listener_id = util.get_instance_id() if util.is_ec2() else socket.getfqdn() self._create_shelf_dir() self._creds_provider = AutoRefreshingCredentialsProvider(self.cfn_client, self.stack_name, self.listener_id) self.queue_url = None
def sign(self, verb, base_url, params, creds, in_headers=None, timestamp=None): base_url = self._normalize_url(base_url) if not util.is_ec2(): raise ValueError("Cannot use CFN signature outside of EC2") document = util.get_instance_identity_document() signature = util.get_instance_identity_signature() new_headers = dict({} if in_headers is None else in_headers) new_headers['Authorization'] = 'CFN_V1 %s:%s' % (base64.b64encode(document), signature.replace('\n', '')) return (verb, base_url, params, new_headers)
def sign(self, verb, base_url, params, creds, in_headers={}, timestamp=None): base_url = self._normalize_url(base_url) if not util.is_ec2(): raise ValueError("Cannot use CFN signature outside of EC2") document = util.get_instance_identity_document() signature = util.get_instance_identity_signature() new_headers = dict(in_headers) new_headers['Authorization'] = 'CFN_V1 %s:%s' % (base64.b64encode(document), signature.replace('\n', '')) return (verb, base_url, params, new_headers)
def __init__(self, stack_name, hooks, sqs_client, cfn_client): """Takes a list of Hook objects and processes them""" self.stack_name = stack_name self.hooks = self._hooks_by_path(hooks) self.sqs_client = sqs_client self.cfn_client = cfn_client if util.is_ec2(): self.listener_id = util.get_instance_id() elif not cfn_client.using_instance_identity: self.listener_id = socket.getfqdn() else: raise ValueError("Could not retrieve instance id") self._create_shelf_dir() self._creds_provider = AutoRefreshingCredentialsProvider(self.cfn_client, self.stack_name, self.listener_id) self.queue_url = None
def __init__(self, credentials, url=None, region='us-east-1', proxyinfo=None): if not url: endpoint = CloudFormationClient.endpointForRegion(region) else: endpoint = url self.using_instance_identity = ( not credentials or not credentials.access_key) and util.is_ec2() if not self.using_instance_identity and ( not credentials or not credentials.access_key or not credentials.secret_key): raise ValueError( 'In order to sign requests, 169.254.169.254 must be accessible or valid credentials must ' 'be set. Please ensure your proxy environment variables allow access to 169.254.169.254 ' '(NO_PROXY) or that your credentials have a valid access key and secret key.' ) if not self.using_instance_identity: if not region: region = CloudFormationClient.regionForEndpoint(endpoint) if not region: raise ValueError('Region is required for AWS V4 Signatures') signer = CFNSigner() if self.using_instance_identity else V4Signer( region, 'cloudformation') super(CloudFormationClient, self).__init__(credentials, True, endpoint, signer, proxyinfo=proxyinfo) log.debug("CloudFormation client initialized with endpoint %s", endpoint)
def __init__(self, stack_name, hooks, sqs_client, cfn_client, multi_threaded): """Takes a list of Hook objects and processes them""" self.stack_name = stack_name self.hooks = self._hooks_by_path(hooks) self.sqs_client = sqs_client self.cfn_client = cfn_client self.multi_threaded = multi_threaded if not self.multi_threaded: log.debug("Enabled single threading mode.") if util.is_ec2(): self.listener_id = util.get_instance_id() elif not cfn_client.using_instance_identity: self.listener_id = socket.getfqdn() else: raise ValueError("Could not retrieve instance id") self._creds_provider = AutoRefreshingCredentialsProvider( self.cfn_client, self.stack_name, self.listener_id) self.queue_url = None self._create_storage_dir() self._runfile = os.path.join(self.storage_dir, 'commands_run.json') self._commands_run = self._load_commands_run() if not 'by_id' in self._commands_run: self._commands_run['by_id'] = {} if not 'by_day' in self._commands_run: self._commands_run['by_day'] = {} self._currently_running = set() self._currently_running_lock = threading.RLock() self._commands_run_lock = threading.RLock()
def __init__(self, credentials, url=None, region='us-east-1', proxyinfo=None): if not url: endpoint = CloudFormationClient.endpointForRegion(region) else: endpoint = url self.using_instance_identity = (not credentials or not credentials.access_key) and util.is_ec2() if not self.using_instance_identity: if not region: region = CloudFormationClient.regionForEndpoint(endpoint) if not region: raise ValueError('Region is required for AWS V4 Signatures') signer = CFNSigner() if self.using_instance_identity else V4Signer(region, 'cloudformation') super(CloudFormationClient, self).__init__(credentials, True, endpoint, signer, proxyinfo=proxyinfo) log.debug("CloudFormation client initialized with endpoint %s", endpoint)