コード例 #1
0
 def set_customer(self, customer):
     if customer != BASE_DATABASE:
         c = self.find({'domain': customer})
         if c.data is not None:
             return MongoEngine().set_collection_name(c.data['db_name'])
     else:
         MongoEngine().set_collection_name(BASE_DATABASE)
コード例 #2
0
    def __init__(self, *args, **kwargs):
        super(AnsibleEngineTests, self).__init__(*args, **kwargs)

        # Drop previous database
        Customer().set_customer(TESTING_DATABASE)
        MongoEngine().drop_collection(TESTING_DATABASE, 'hosts')
        MongoEngine().drop_collection(TESTING_DATABASE, 'playbooks')
コード例 #3
0
    def __init__(self, *args, **kwargs):
        super(DumpTests, self).__init__(*args, **kwargs)

        # Drop previous database
        Customer().set_customer(TESTING_DATABASE)
        MongoEngine().drop_collection(TESTING_DATABASE, 'hosts')
        MongoEngine().drop_collection(TESTING_DATABASE, 'playbooks')

        self.root = './'
        self.base_path = 'files-generated'
        self.domain = 'domain.com'
        self.sub_path_hosts = 'hosts'
        self.sub_path_playbooks = 'playbooks'
コード例 #4
0
 def get():
     mongo = MongoEngine().status()
     docker = DockerEngine().status()
     hc = mongo['is_up'] and docker['is_up']
     code = 200 if hc else 500
     return {
         'ok': hc
     }, code
コード例 #5
0
    def get():
        user = Login().get_username(request.headers['x-access-token'])
        is_admin = User().is_admin(user)

        return {
            'mongo': MongoEngine().status(is_admin),
            'docker': DockerEngine().status()
        }, 200
コード例 #6
0
 def is_customer(self, customer):
     MongoEngine().set_collection_name(BASE_DATABASE)
     if customer == '':
         return True
     elif customer != BASE_DATABASE:
         c = self.find({'domain': customer})
         if c.data is not None and c.data['enabled']:
             return True
     return False
コード例 #7
0
 def setUp(self):
     Customer().set_customer(TESTING_DATABASE)
     MongoEngine().drop_collection(TESTING_DATABASE, 'users')
     User().insert({
         'type': 'admin',
         'first_name': 'admin',
         'last_name': 'admin',
         'username': '******',
         'email': '*****@*****.**',
         'password': '******'
     })
コード例 #8
0
    def setUp(self):
        Customer().set_customer(TESTING_DATABASE)
        MongoEngine().drop_collection(TESTING_DATABASE, 'customers')
        User().insert({
            'type': 'admin',
            'first_name': 'admin-user',
            'last_name': 'admin-user',
            'username': '******',
            'email': 'admin-user',
            'password': '******'
        })

        logged_user = Login().login(Auth('admin-user', 'admin-user'))
        self.headers = {
            'Content-Type': 'application/json',
            'x-access-token': logged_user.data['token']
        }
コード例 #9
0
ファイル: login.py プロジェクト: harvestcore/IPManager
    def __new__(cls, *args, **kwargs):
        if not cls.engine:
            cls.engine = super(TestingLogin, cls).__new__(cls, *args, **kwargs)

            Customer().set_customer(TESTING_DATABASE)
            MongoEngine().drop(TESTING_DATABASE)
            User().insert({
                'type': 'admin',
                'first_name': 'admin',
                'last_name': 'admin',
                'username': '******',
                'email': '*****@*****.**',
                'password': '******'
            })

            logged_user = Login().login(Auth('admin', 'admin'))
            cls.headers = {
                'Content-Type': 'application/json',
                'x-access-token': logged_user.data['token']
            }

        return cls.engine
コード例 #10
0
    def insert(self, item=None):
        if item is None or not item or \
                'domain' not in item or 'db_name' not in item:
            return False

        self.set_customer(BASE_DATABASE)

        if MongoEngine().get_client() is not None:
            found = self.find(criteria={
                'domain': item['domain'],
                'db_name': item['db_name']
            },
                              projection={
                                  'domain': 1,
                                  'db_name': 1
                              }).data

            if found is not None:
                return False

        insertion = super().insert(data=item)

        return insertion
コード例 #11
0
ファイル: test_login.py プロジェクト: harvestcore/IPManager
    def __init__(self, *args, **kwargs):
        super(UserTests, self).__init__(*args, **kwargs)

        # Drop previous database
        Customer().set_customer(TESTING_DATABASE)
        MongoEngine().drop_collection(TESTING_DATABASE, 'users')
コード例 #12
0
 def setUp(self):
     Customer().set_customer(TESTING_DATABASE)
     MongoEngine().drop_collection(TESTING_DATABASE, 'hosts')
     MongoEngine().drop_collection(TESTING_DATABASE, 'playbooks')
コード例 #13
0
 def cursor(self):
     if self.table_name != '':
         return MongoEngine().get_client()[self.table_name]
     return None
コード例 #14
0
 def setUp(self):
     Customer().set_customer(TESTING_DATABASE)
     MongoEngine().drop_collection(TESTING_DATABASE, 'machines')