Esempio n. 1
0
def handler(event, context):
    """Main lambda handler use as the entry point

    Args:
        event (dict): Always empty (for now) event object
        context (LambdaContxt): AWS LambdaContext object
    """
    if event and 'full_run' in event:
        # TODO: implement support for historical runs via input events
        pass

    try:
        # Load the config from this context object, pulling info from parameter store
        config = AppConfig.load_config(context)

        # The config specifies what app this function is supposed to run
        app = get_app(config)

        # Run the gather operation
        app.gather()
    finally:
        # If the config was loaded, save a bad state if the current state is not
        # marked as a success (aka running)
        if 'config' in locals():
            if not config.is_success:
                config.mark_failure()
Esempio n. 2
0
def handler(event, context):
    """Main lambda handler use as the entry point

    Args:
        event (dict): Event object that can potentially contain details on what to
            during this invocation. An example of this is the 'invocation_type' key
            that is used as an override to allow for successive invocations (and in
            the future, support for historical invocations)
        context (LambdaContxt): AWS LambdaContext object
    """
    try:
        # Load the config from this context object, pulling info from parameter store
        # The event object can contain detail about what to do, ie: 'invocation_type'
        config = AppConfig.load_config(context, event)

        # The config specifies what app this function is supposed to run
        app = get_app(config)

        # Run the gather operation
        app.gather()
    finally:
        # If the config was loaded, save a bad state if the current state is still
        # marked as 'running' (aka not 'success' or 'partial' runs)
        if 'config' in locals() and config.is_running:
            config.mark_failure()
Esempio n. 3
0
 def setup(self):
     """Setup before each method"""
     self.ssm_patcher = patch.object(AppConfig, 'SSM_CLIENT',
                                     MockSSMClient())
     self.mock_ssm = self.ssm_patcher.start()
     self._config = AppConfig.load_config(
         get_mock_context(), {'invocation_type': 'successive_invoke'})
Esempio n. 4
0
    def test_determine_last_timestamp_box(self, time_mock):
        """AppIntegrationConfig - Determine Last Timestamp, Box"""
        with patch.object(AppConfig, 'SSM_CLIENT', MockSSMClient(app_type='box_admin_events')):
            self._config = AppConfig.load_config(get_mock_context(), None)

            # Reset the last timestamp to None
            self._config.last_timestamp = None

            # Use a mocked current time
            time_mock.return_value = 1234567890
            assert_equal(self._config._determine_last_time(), '2009-02-13T22:31:30-00:00')
Esempio n. 5
0
 def test_load_config_new_client(self, boto_mock):
     """AppIntegrationConfig - Load config, new SSM client"""
     boto_mock.return_value = MockSSMClient(app_type='onelogin_events')
     with patch.object(AppConfig, 'SSM_CLIENT', None):
         self._config = AppConfig.load_config(get_mock_context(), None)
         boto_mock.assert_called()
Esempio n. 6
0
 def test_is_successive_invocation(self):
     """AppIntegrationConfig - Is Successive Invocation"""
     assert_true(self._config.is_successive_invocation)
     self._config = AppConfig.load_config(get_mock_context(), None)
     assert_false(self._config.is_successive_invocation)
Esempio n. 7
0
 def setup(self):
     """Setup before each method"""
     self._config = AppConfig.load_config(get_mock_context())
Esempio n. 8
0
 def setup(self):
     """Setup before each method"""
     self.ssm_patcher = patch.object(AppConfig, 'SSM_CLIENT',
                                     MockSSMClient())
     self.mock_ssm = self.ssm_patcher.start()
     self._config = AppConfig.load_config(get_mock_context())