Exemplo n.º 1
0
class Mellon(application.YamlCliAppMixin):

    logger = logging.getLogger(__name__)
    app_zcml = (mellon, 'configure.zcml')

    def go(self):
        v_iter = component.getUtility(container.ISparcPyDictValueIterator)
        self.logger.info(
            u"searching for MellonFileProviderFactory entries in config file")
        for d in v_iter.values(
                self.get_config(), 'MellonFileProviderFactory'
        ):  #d is dict of MellonFileProviderFactories keys
            fprovider = component.createObject(
                d['name'],
                d)  #assumes named factory provides IMellonFileProviderFactory
            if not mellon.IMellonFileProvider.providedBy(fprovider):
                self.logger.warn(
                    u"expected factory %s to create objects providing IMellonFileProvider, skipping"
                    % str(d['name']))
                continue
            self.logger.info(
                u"found MellonFileProviderFactory config entry with name: {}".
                format(d['name']))
            try:
                for f in fprovider:  # iterate the files in the provider
                    wht_lstd = False
                    for wht_lst in component.subscribers((f, ),
                                                         mellon.IWhitelist):
                        for wht_lst_info in wht_lst:
                            self.logger.info(
                                u"skipping white-listed file: {} because {}".
                                format(f, wht_lst_info))
                            wht_lstd = True
                    if not wht_lstd:
                        self.logger.info(
                            u"searching for secrets in file: {}".format(f))
                        for s in f:  # iterate the data snippets in the file (s provides ISnippet)
                            #App reporters should subscribe to this event feed.  Each
                            #reporter is responsible to find/execute the sniffers and
                            #also to insure whitelisted secrets are not reported on.
                            event.notify(
                                SnippetAvailableForSecretsSniffEvent(s))
            except Exception:
                traceback.print_exc()
        self.logger.info(
            u"completed MellonFileProviderFactory config file entry search")
Exemplo n.º 2
0
import transaction
from ZODB.POSException import ConflictError
from zope.component import adapts
from zope.component import queryAdapter
from zope.event import notify
from zope.interface import implements
from zc.queue.interfaces import IQueue
from sparc.publish import RecoverablePublishingError
from sparc.publish import IPublisher
from sparc.publish import IPublisherQueue
from sparc.publish.events import PublisherQueuePublishedEvent

from sparc.logging import logging
logger = logging.getLogger(__name__)

class PublisherQueueForZCQueue(object):
    """A queue of objects that can be published
    
    This adapter allows for a thread-safe, concurrent-safe ZODB-based queue
    """
    implements(IPublisherQueue)
    adapts(IQueue)
    
    def __init__(self, context):
        self.context = context # concurrency-safe persistent queue implementation
    
    # IPublisherQueue
    def enqueue(self, item):
        """Add object into the queue"""
        if not queryAdapter(item, IPublisher):
            raise TypeError('could not adapt.  expected item to be adaptable to IPublisher')
Exemplo n.º 3
0
from entropy import shannon_entropy
from zope import component
from zope import interface
from sparc.configuration import container
import mellon

from sparc.logging import logging
logger = logging.getLogger(__name__)


@interface.implementer(mellon.ISecretSniffer)
@component.adapter(mellon.IUnicodeSnippet)
class EntropyUnicodeSecretSniffer(object):
    @classmethod
    def get_config(cls):
        sm = component.getSiteManager()
        config = sm.getUtility(mellon.IMellonApplication).get_config()
        return container.IPyContainerConfigValue(config).\
                                                    get('MellonEntropySniffer')

    config = None

    def __init__(self, context):
        self.context = context
        if not EntropyUnicodeSecretSniffer.config:
            logger.debug(u"Entropy config not yet loaded, initializing...")
            EntropyUnicodeSecretSniffer.config = EntropyUnicodeSecretSniffer.get_config(
            )
            logger.debug(u"Entropy config initialization complete.")

    def create_secret(self, score, matched_data):
Exemplo n.º 4
0
 def setLoggers(self, args):
     logger = logging.getLogger() # root logger
     if args.verbose:
         logger.setLevel('INFO')
     if args.debug:
         logger.setLevel('DEBUG')
Exemplo n.º 5
0
 def setLoggers(self, args):
     logger = logging.getLogger() # root logger
     if args.verbose:
         logger.setLevel('INFO')
     if args.debug:
         logger.setLevel('DEBUG')