Exemple #1
0
    def test_parse_context(self):
        """AppIntegrationConfig - Parse Context"""
        mock_context = get_mock_context()
        result = AppConfig._parse_context(mock_context)

        assert_equal(AppConfig.remaining_ms, mock_context.get_remaining_time_in_millis)
        assert_equal(AppConfig.remaining_ms(), 100)
        assert_equal(result['function_name'], FUNCTION_NAME)
Exemple #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()
Exemple #3
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()
Exemple #4
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'})
Exemple #5
0
def test_handler_bad_type(config_mock, failure_mock):
    """App Integration - Test Handler, Bad Service Type"""
    base_config = get_valid_config_dict('duo_auth')
    base_config.update({'type': 'bad_type', 'current_state': 'running'})
    config_mock.return_value = AppConfig(base_config)
    handler(None, get_mock_context())

    failure_mock.assert_called()
Exemple #6
0
    def test_get_param(self):
        """AppIntegrationConfig - Get parameter"""
        param, _ = AppConfig._get_parameters(
            ['{}_config'.format(FUNCTION_NAME)])

        assert_items_equal(
            param['{}_config'.format(FUNCTION_NAME)].keys(),
            {'cluster', 'app_name', 'type', 'prefix', 'schedule_expression'})
Exemple #7
0
def test_handler_success(gather_mock, config_mock, failure_mock):
    """App Integration - Test Handler, Success"""
    base_config = get_valid_config_dict('duo_auth')
    config_mock.return_value = AppConfig(base_config)
    gather_mock.return_value = None
    handler(None, get_mock_context())

    failure_mock.assert_not_called()
Exemple #8
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')
Exemple #9
0
 def test_get_param_client_error(self):
     """AppIntegrationConfig - Get parameter, Exception"""
     self.mock_ssm.raise_exception = True
     AppConfig._get_parameters([])
Exemple #10
0
 def test_get_param_bad_value(self):
     """AppIntegrationConfig - Get parameter, bad json value"""
     config_name = '{}_config'.format(FUNCTION_NAME)
     with patch.dict(AppConfig.SSM_CLIENT._parameters, {config_name: 'bad json'}):
         AppConfig._get_parameters([config_name])
Exemple #11
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()
Exemple #12
0
 def setup(self):
     self._app = SlackIntegrationsApp(
         AppConfig(get_valid_config_dict('slack')))
Exemple #13
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)
 def setup(self):
     """Setup before each method"""
     self._app = AppIntegration(AppConfig(get_valid_config_dict('duo_admin')))
def test_get_app_exception_type():
    """App Integration - App Base, Get App Exception for No 'type'"""
    config = AppConfig(get_valid_config_dict('duo_auth'))
    del config['type']
    get_app(config)
Exemple #16
0
 def setup(self):
     """Setup before each method"""
     self._app = SalesforceApp(AppConfig(get_valid_config_dict('salesforce')))
Exemple #17
0
 def setup(self):
     """Setup before each method"""
     self._config = AppConfig.load_config(get_mock_context())
Exemple #18
0
 def setup(self):
     """Setup before each method"""
     self._app = OneLoginApp(AppConfig(get_valid_config_dict('onelogin')))
Exemple #19
0
 def setup(self):
     """Setup before each method"""
     self._app = BoxApp(AppConfig(
         get_valid_config_dict('box_admin_events')))
def test_get_app():
    """App Integration - App Base, Get App"""
    config = AppConfig(get_valid_config_dict('duo_auth'))
    app = get_app(config)
    assert_is_not_none(app)
Exemple #21
0
 def setup(self):
     self._app = SlackAccessApp(AppConfig(get_valid_config_dict('slack')))
def test_get_app_exception_invalid():
    """App Integration - App Base, Get App Exception for Invalid Service"""
    config = AppConfig(get_valid_config_dict('duo_auth'))
    config['type'] = 'bad_service_type'
    get_app(config)
Exemple #23
0
 def setup(self):
     """Setup before each method"""
     self._app = GSuiteReportsApp(
         AppConfig(get_valid_config_dict('gsuite_admin')))
 def setup(self):
     """Setup before each method"""
     self._app = DuoApp(AppConfig(get_valid_config_dict('duo')))
Exemple #25
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())