Exemplo n.º 1
0
    def handler(cls, options, config):
        """Fetches the configuration for a service
        Args:
            options (argparse.Namespace): Basically a namedtuple with the service setting
            config (StreamAlert.config): The configuration of StreamAlert
        Returns:
            bool: False if errors occurred, True otherwise
        """
        service = options.service
        output = StreamAlertOutput.create_dispatcher(service, config)

        # Get the descriptors for the service. No need to check service
        # as this is handled by argparse choices
        configured_descriptors = [
            descriptor for descriptor in config["outputs"][service]
            if 'sample' not in descriptor
        ]

        # Set the descriptors to get the secrets for
        descriptors = options.descriptors if options.descriptors else configured_descriptors

        LOGGER.debug('Getting secrets for service %s and descriptors %s',
                     service, descriptors)

        credentials = []
        for descriptor in descriptors:
            if descriptor not in configured_descriptors:
                LOGGER.error('Invalid descriptor %s, it doesn\'t exist',
                             descriptor)
                return False

            creds = output._load_creds(descriptor)  # pylint: disable=protected-access
            creds['descriptor'] = descriptor
            credentials.append(creds)

        print('\nService Name:', service)
        print(json.dumps(credentials, indent=2, sort_keys=True), '\n')
Exemplo n.º 2
0
    def _create_dispatcher(self, output):
        """Create a dispatcher for the given output.

        Args:
            output (str): Alert output, e.g. "aws-sns:topic-name"

        Returns:
            OutputDispatcher: Based on the output type.
                Returns None if the output is invalid or not defined in the config.
        """
        try:
            service, descriptor = output.split(':')
        except ValueError:
            LOGGER.error(
                'Improperly formatted output [%s]. Outputs for rules must '
                'be declared with both a service and a descriptor for the '
                'integration (ie: \'slack:my_channel\')', output)
            return None

        if service not in self.config or descriptor not in self.config[service]:
            LOGGER.error('The output \'%s\' does not exist!', output)
            return None

        return StreamAlertOutput.create_dispatcher(service, self.config)
Exemplo n.º 3
0
def test_create_dispatcher():
    """StreamAlertOutput - Create Dispatcher"""
    dispatcher = StreamAlertOutput.create_dispatcher('aws-s3', CONFIG)
    assert_is_instance(dispatcher, S3Output)