Esempio n. 1
0
    def __init__(self, **kwargs):
        """
            constructor receive a **kwargs as the **kwargs in the sqlalchemy
            create_engine() method (see sqlalchemy docs)
            You must add to this **kwargs an 'url' key with the url to your
            database
            This constructor will :
            - create all the necessary obj to discuss with the DB
            - create all the mapping(ORM)

            todo : suport the : sqlalchemy.engine_from_config

            :param **kwargs:
            :raises: ValueError if no url is given,
                    all exception sqlalchemy can throw
            ie sqlite in memory url='sqlite://' echo=True
            ie sqlite file on hd url='sqlite:////tmp/reportdb.sql' echo=True
            ie mysql url='mysql+mysqldb://scott:tiger@localhost/foo'
        """
        NmapBackendPlugin.__init__(self)
        self.engine = None
        self.url = None
        self.Session = sessionmaker()

        if 'url' not in kwargs:
            raise ValueError
        self.url = kwargs['url']
        del kwargs['url']
        try:
            self.engine = create_engine(self.url, **kwargs)
            Base.metadata.create_all(bind=self.engine, checkfirst=True)
            self.Session.configure(bind=self.engine)
        except:
            raise
Esempio n. 2
0
    def __init__(self, **kwargs):
        """
            constructor receive a **kwargs as the **kwargs in the sqlalchemy
            create_engine() method (see sqlalchemy docs)
            You must add to this **kwargs an 'url' key with the url to your
            database
            This constructor will :
            - create all the necessary obj to discuss with the DB
            - create all the mapping(ORM)

            todo : suport the : sqlalchemy.engine_from_config

            :param **kwargs:
            :raises: ValueError if no url is given,
                    all exception sqlalchemy can throw
            ie sqlite in memory url='sqlite://' echo=True
            ie sqlite file on hd url='sqlite:////tmp/reportdb.sql' echo=True
            ie mysql url='mysql+mysqldb://scott:tiger@localhost/foo'
        """
        NmapBackendPlugin.__init__(self)
        self.engine = None
        self.url = None
        self.Session = sessionmaker()

        if 'url' not in kwargs:
            raise ValueError
        self.url = kwargs['url']
        del kwargs['url']
        try:
            self.engine = create_engine(self.url, **kwargs)
            Base.metadata.create_all(bind=self.engine, checkfirst=True)
            self.Session.configure(bind=self.engine)
        except:
            raise
Esempio n. 3
0
 def __init__(self, dbname=None):
     NmapBackendPlugin.__init__(self)
     conn = sqlite3.connect(dbname)
     curs = conn.cursor()
     # Create table if not exist
     curs.execute('''CREATE TABLE f not exists reports
             (date text, trans text, symbol text, qty real, price real)''')
 def __init__(self, dbname=None, store=None, **kwargs):
     NmapBackendPlugin.__init__(self)
     if dbname is not None:
         self.dbname = dbname
     if store is not None:
         self.store = store
     self.dbclient = MongoClient(**kwargs)
     self.collection = self.dbclient[self.dbname][self.store]
Esempio n. 5
0
 def __init__(self, dbname=None, store=None, **kwargs):
     NmapBackendPlugin.__init__(self)
     if dbname is not None:
         self.dbname = dbname
     if store is not None:
         self.store = store
     self.dbclient = MongoClient(**kwargs)
     self.collection = self.dbclient[self.dbname][self.store]
Esempio n. 6
0
    def __init__(self, **kwargs):
        NmapBackendPlugin.__init__(self)
        self.engine = None
        self.url = None
        self.Session = sessionmaker()

        if 'url' not in kwargs:
            raise ValueError
        self.url = kwargs['url']
        del kwargs['url']
        try:
            self.engine = create_engine(self.url, **kwargs)
            Base.metadata.create_all(bind=self.engine, checkfirst=True)
            self.Session.configure(bind=self.engine)
        except:
            raise
Esempio n. 7
0
 def __init__(self, **kwargs):
     """
         - create the conn object
         - create the bucket (if it doesn't exist)
             - if not given, awsaccessKey_nmapreport
         - may raise exception (ie in case of conflict bucket name)
         - sample :
         To connect to walrus:
         from libnmap.plugins.backendpluginFactory import
                         BackendPluginFactory
         walrusBackend =
           BackendPluginFactory.create(
                 plugin_name='s3',
                 host="walrus.ecc.eucalyptus.com",
                 path="/services/Walrus",port=8773,
                 is_secure=False,
                 aws_access_key_id='UU72FLVJCAYRATLXI70YH',
                 aws_secret_access_key=
                            'wFg7gP5YFHjVlxakw1g1uCC8UR2xVW5ax9ErZCut')
        To connect to S3:
        mybackend_S3 =
          BackendPluginFactory.create(
             plugin_name='s3',
             is_secure=True,
             aws_access_key_id='MYACCESSKEY',
             aws_secret_access_key='MYSECRET')
     """
     NmapBackendPlugin.__init__(self)
     try:
         calling_format = OrdinaryCallingFormat()
         if 'bucket' not in kwargs:
             self.bucket_name = ''.join(
                 [kwargs['aws_access_key_id'].lower(),
                  "_nmapreport"])
         else:
             self.bucket_name = kwargs['bucket']
             del kwargs['bucket']
         kwargs['calling_format'] = calling_format
         self.conn = S3Connection(**kwargs)
         self.bucket = self.conn.lookup(self.bucket_name)
         if self.bucket is None:
             self.bucket = self.conn.create_bucket(self.bucket_name)
     except:
         raise
Esempio n. 8
0
 def __init__(self, **kwargs):
     """
      - create the conn object
      - create the bucket (if it doesn't exist)
          - if not given, awsaccessKey_nmapreport
      - may raise exception (ie in case of conflict bucket name)
      - sample :
      To connect to walrus:
      from libnmap.plugins.backendpluginFactory import
                      BackendPluginFactory
      walrusBackend =
        BackendPluginFactory.create(
              plugin_name='s3',
              host="walrus.ecc.eucalyptus.com",
              path="/services/Walrus",port=8773,
              is_secure=False,
              aws_access_key_id='UU72FLVJCAYRATLXI70YH',
              aws_secret_access_key=
                         'wFg7gP5YFHjVlxakw1g1uCC8UR2xVW5ax9ErZCut')
     To connect to S3:
     mybackend_S3 =
       BackendPluginFactory.create(
          plugin_name='s3',
          is_secure=True,
          aws_access_key_id='MYACCESSKEY',
          aws_secret_access_key='MYSECRET')
     """
     NmapBackendPlugin.__init__(self)
     try:
         calling_format = OrdinaryCallingFormat()
         if "bucket" not in kwargs:
             self.bucket_name = "".join(
                 [kwargs["aws_access_key_id"].lower(), "_nmapreport"]
             )
         else:
             self.bucket_name = kwargs["bucket"]
             del kwargs["bucket"]
         kwargs["calling_format"] = calling_format
         self.conn = S3Connection(**kwargs)
         self.bucket = self.conn.lookup(self.bucket_name)
         if self.bucket is None:
             self.bucket = self.conn.create_bucket(self.bucket_name)
     except Exception as e:
         raise Exception(e)
Esempio n. 9
0
 def __init__(self):
     NmapBackendPlugin.__init__(self)
     self.dict = {}