Ejemplo n.º 1
0
    def _publish_version(packages):
        """Publish Lambda versions"""
        for package in packages:
            if package.package_name in {'athena_partition_refresh', 'threat_intel_downloader'}:
                published = LambdaVersion(
                    config=config, package=package, clustered_deploy=False).publish_function()
            else:
                published = LambdaVersion(config=config, package=package).publish_function()
            if not published:
                return False

        return True
Ejemplo n.º 2
0
def test_publish_helper():
    """CLI - Publish Athena Function"""
    config = MockCLIConfig(config=basic_streamalert_config())
    package = AthenaPackage(version='1.0', config=config)
    publish = LambdaVersion(config=config,
                            clustered_deploy=False,
                            package=package)
    result = publish._publish_helper()

    assert_equal(
        config['lambda']['athena_partition_refresh_config']['current_version'],
        11)
    assert_true(result)
Ejemplo n.º 3
0
def test_publish_helper_clustered():
    """CLI - Publish Clustered Function"""
    config = MockCLIConfig(config=basic_streamalert_config())
    package = RuleProcessorPackage(version='1.0', config=config)
    publish = LambdaVersion(config=config,
                            clustered_deploy=True,
                            package=package)
    result = publish._publish_helper(cluster='prod')

    assert_true(result)
    assert_equal(
        config['clusters']['prod']['modules']['stream_alert']['rule_processor']
        ['current_version'], 11)
Ejemplo n.º 4
0
    def deploy(self, options):
        """Deploy the StreamAlert processor lambda function to staging/prod

        Staging:
            - build lambda package
            - upload to S3
            - update variables.json
            - run terraform apply

        Production:
            - publish latest version
            - update variables.json
            - run terraform apply
        """
        env = options.env
        func = options.func
        targets = ['module.stream_alert_{}'.format(x) for x in self.config['clusters'].keys()]

        if env == 'staging':
            if func == 'alert':
                alert_package = AlertPackage(
                    config=self.config,
                    version=stream_alert_version
                )
                alert_package.create_and_upload()
            elif func == 'output':
                output_package = OutputPackage(
                    config=self.config,
                    version=stream_alert_output_version
                )
                output_package.create_and_upload()
            elif func == '*':
                alert_package = AlertPackage(
                    config=self.config,
                    version=stream_alert_version
                )
                alert_package.create_and_upload()
                output_package = OutputPackage(
                    config=self.config,
                    version=stream_alert_output_version
                )
                output_package.create_and_upload()

        elif env == 'production':
            if func == 'alert':
                deploy = LambdaVersion(config=self.config)
                deploy.publish_function()
            else:
                logging.info('Unsupported production function: %s', func)

        self._tf_runner(targets=targets)
Ejemplo n.º 5
0
def test_version_helper():
    """CLI - Publish Helper"""
    package = AthenaPackage(version='1.0', config=basic_streamalert_config())
    publish = LambdaVersion(config=basic_streamalert_config(),
                            clustered_deploy=False,
                            package=package)
    current_version = 10
    fake_client = MockLambdaClient('athena', current_version=current_version)
    result = publish._version_helper(client=fake_client,
                                     function_name='test',
                                     code_sha_256='12345',
                                     date='2017-01-01')

    assert_equal(result, current_version + 1)
Ejemplo n.º 6
0
    def _publish_version(packages):
        """Publish Lambda versions"""
        for package in packages:
            if package.package_name == 'athena_partition_refresh':
                published = LambdaVersion(
                    config=CONFIG, package=package,
                    clustered_deploy=False).publish_function()
            else:
                published = LambdaVersion(config=CONFIG,
                                          package=package).publish_function()
            if not published:
                return False

        return True
Ejemplo n.º 7
0
 def publish_version(packages):
     """Publish Lambda versions"""
     for package in packages:
         LambdaVersion(
             config=CONFIG,
             package=package
         ).publish_function()
Ejemplo n.º 8
0
def test_version_helper_error(mock_logging):
    """CLI - Publish Helper Raises Error"""
    package = AthenaPackage(version='1.0', config=basic_streamalert_config())
    publish = LambdaVersion(config=basic_streamalert_config(),
                            clustered_deploy=False,
                            package=package)
    current_version = 10
    fake_client = MockLambdaClient('athena',
                                   current_version=current_version,
                                   throw_exception=True)
    result = publish._version_helper(client=fake_client,
                                     function_name='test',
                                     code_sha_256='12345',
                                     date='2017-01-01')

    assert_false(result)
    assert_true(mock_logging.error.called)