コード例 #1
0
ファイル: serializers.py プロジェクト: ravi-daffodil/Secberus
    def validate(self, data):
        collection = Collection.get_loaded_collection(name='AwsCredentials')
        obj = SimpleQuery.get_by_example(collection,
                                         example_data={
                                             'company':
                                             self.context['company'],
                                             'external_id': data['external_id']
                                         })
        if obj:
            raise serializers.ValidationError(
                "External id already exist for a company")

        obj = SimpleQuery.get_by_example(collection,
                                         example_data={
                                             'company':
                                             self.context['company'],
                                             'role_arn': data['role_arn']
                                         })
        if obj:
            raise serializers.ValidationError("Role Arn already exist")

        obj = SimpleQuery.get_by_example(collection,
                                         example_data={
                                             'company':
                                             self.context['company'],
                                             'account_name':
                                             data['account_name']
                                         })
        if obj:
            raise serializers.ValidationError(
                "Account name already exist for a company")
        return data
コード例 #2
0
ファイル: basic.py プロジェクト: morsdatum/ArangoPy
    def test_get_document_by_example(self):
        uid = self.col1_doc1.key
        doc = SimpleQuery.get_by_example(collection=self.test_1_col, example_data={
            '_key': uid,
        })

        self.assertDocumentsEqual(doc, self.col1_doc1)
コード例 #3
0
ファイル: serializers.py プロジェクト: ravi-daffodil/Secberus
 def create(self, validated_data):
     #Init Arango Models
     AwsCredentials.init()
     Companies.init()
     account_obj = AwsCredentials.objects.get(
         _id=str(validated_data['account_id']))
     obj = Collection.get_loaded_collection(name='ScheduleIntervalSettings')
     SimpleQuery.update_by_example(
         obj, {
             'account_id': str(account_obj.document),
             'service': str(validated_data['service']),
         }, {
             'service': validated_data['service'],
             'repeat_delay': validated_data['repeat_delay']
         })
     response = SimpleQuery.get_by_example(
         obj,
         example_data={
             'account_id': str(account_obj.document),
             'service': str(validated_data['service'])
         })
     headers = {"Content-Type": "application/json"}
     url = FOXX_BASE_URL + "execute/" + urllib.quote_plus(
         str(response)) + "/" + str(self.context['user']) + "/edit"
     response = requests.get(url, headers=headers)
     return response
コード例 #4
0
ファイル: transaction.py プロジェクト: morsdatum/ArangoPy
    def test_create_document(self):

        trans = Transaction(collections={
            'write': [
                self.operating_collection,
            ]
        })

        # Uses already chosen database as usual
        collection = trans.collection(name=self.operating_collection)
        collection.create_document(data={
            'test': 'foo'
        })

        ctrl = TransactionController()

        transaction_result = ctrl.start(transaction=trans)

        transaction_doc = create_document_from_result_dict(transaction_result['result'], self.test_1_col.api)

        created_doc = SimpleQuery.get_by_example(self.test_1_col, example_data={
            '_id': transaction_doc.id
        })

        self.assertDocumentsEqual(transaction_doc, created_doc)
コード例 #5
0
    def test_get_no_document(self):
        doc = SimpleQuery.get_by_example(collection=self.test_1_col,
                                         example_data={
                                             '_key': 'dddd',
                                         })

        self.assertEqual(doc, None)
コード例 #6
0
ファイル: utils.py プロジェクト: ravi-daffodil/Secberus
def company(self):
    collection = Collection.get_loaded_collection(name='UserCompanies')
    obj = SimpleQuery.get_by_example(collection,
                                     example_data={
                                         'user': int(self.id),
                                         'active': True
                                     })
    return obj.company
コード例 #7
0
    def test_get_document_by_example(self):
        uid = self.col1_doc1.key
        doc = SimpleQuery.get_by_example(collection=self.test_1_col,
                                         example_data={
                                             '_key': uid,
                                         })

        self.assertDocumentsEqual(doc, self.col1_doc1)
コード例 #8
0
ファイル: models.py プロジェクト: domenikjones/ArangoPy
    def get(self, **kwargs):
        """
        """

        collection = self._model_class.collection_instance

        doc = SimpleQuery.get_by_example(collection=collection, example_data=kwargs)

        if doc is None:
            return None

        model = self._create_model_from_doc(doc=doc)

        return model
コード例 #9
0
ファイル: models.py プロジェクト: garym/ArangoPy
    def get(self, **kwargs):
        """
        """

        collection = self._model_class.collection_instance

        doc = SimpleQuery.get_by_example(collection=collection,
                                         example_data=kwargs)

        if doc is None:
            return None

        model = self._create_model_from_doc(doc=doc)

        return model
コード例 #10
0
 def get(self, request, format='json'):
     """
         API View that receives a GET request.
         and will return a single random unused external id.
     """
     obj = Collection.get_loaded_collection(name='AwsExternalIds')
     document = SimpleQuery.get_by_example(obj,
                                           example_data={
                                               'used': False,
                                           },
                                           allow_multiple=True)
     if document:
         external_id = Document(random.choice(document), '',
                                'AwsExternalIds',
                                client.api).retrieve()['external_id']
     else:
         external_id = "Not found"
     return Response(external_id, status=status.HTTP_201_CREATED)
コード例 #11
0
ファイル: serializers.py プロジェクト: ravi-daffodil/Secberus
    def validate(self, data):
        collection = Collection.get_loaded_collection(
            name='ScheduleIntervalSettings')
        obj = SimpleQuery.get_by_example(collection,
                                         example_data={
                                             'account_id':
                                             str(data['account_id']),
                                             'service': str(data['service']),
                                         })
        if not obj:
            raise serializers.ValidationError(
                "A setting for the given service with this account not exist")

        AwsCredentials.init()
        Companies.init()
        aws_obj = AwsCredentials.objects.get(_id=str(data['account_id']))
        if str(aws_obj.company.id) != str(self.context['company']):
            raise serializers.ValidationError(
                'Companies account are different for Aws and currenly logged in User'
            )

        return data
コード例 #12
0
    def test_create_document(self):

        trans = Transaction(
            collections={'write': [
                self.operating_collection,
            ]})

        # Uses already chosen database as usual
        collection = trans.collection(name=self.operating_collection)
        collection.create_document(data={'test': 'foo'})

        ctrl = TransactionController()

        transaction_result = ctrl.start(transaction=trans)

        transaction_doc = create_document_from_result_dict(
            transaction_result['result'], self.test_1_col.api)

        created_doc = SimpleQuery.get_by_example(
            self.test_1_col, example_data={'_id': transaction_doc.id})

        self.assertDocumentsEqual(transaction_doc, created_doc)
コード例 #13
0
ファイル: basic.py プロジェクト: morsdatum/ArangoPy
    def test_get_no_document(self):
        doc = SimpleQuery.get_by_example(collection=self.test_1_col, example_data={
            '_key': 'dddd',
        })

        self.assertEqual(doc, None)
コード例 #14
0
ファイル: utils.py プロジェクト: ravi-daffodil/Secberus
def get_default_role():
    obj = Collection.get_loaded_collection(name='Roles')
    return SimpleQuery.get_by_example(obj, example_data={'slug': 'user'})
コード例 #15
0
    def create(self, validated_data):
        user = User.objects.create_user(
                    username=validated_data['email'],
                    password=validated_data['password'],
                    email=validated_data['email'],
                    first_name=validated_data['first_name'],
                    last_name=validated_data['last_name'] if 'last_name' in validated_data else '',
                    is_active=False
                )
        try:
            # Saving data into UserProfile collection
            UserProfiles.init()
            obj = UserProfiles()
            obj.user = int(user.id)
            obj.country = str(validated_data['country'])
            obj.state = str(validated_data['state'])
            obj.phone_number = str(validated_data['phone_number'])
            obj.role = str(get_default_role().id)
            obj.save()


            # Saving company into collection
            Companies.init()
            obj = Companies()
            obj.name = str(validated_data['company'])
            obj.save()

            # Assign User to Company
            collection = Collection.get_loaded_collection(name='UserCompanies')
            doc = collection.create_document()
            doc.user = int(user.id)
            doc.company =  str(obj.id)
            doc.active =  True
            doc.created_on = str(datetime.datetime.now())
            doc.save()

        except Exception as e:
            # Removing data saved into document if any error occured
            collection = Collection.get_loaded_collection(name='UserProfiles')
            obj = SimpleQuery.get_by_example(collection, example_data={
                'user': int(user.id),
            })
            if obj:
                Document(obj.id, '', 'UserProfiles', client.api).delete()

            collection = Collection.get_loaded_collection(name='Companies')
            obj = SimpleQuery.get_by_example(collection, example_data={
                'name': str(validated_data['company']),
            })
            if obj:
                Document(obj.id, '', 'Companies', client.api).delete()

            collection = Collection.get_loaded_collection(name='UserCompanies')
            obj = SimpleQuery.get_by_example(collection, example_data={
                'user': int(user.id),
                'company': str(obj.id)
            })
            if obj:
                Document(obj.id, '', 'UserCompanies', client.api).delete()
            raise Exception('Error Occured '+str(e))
        return user
コード例 #16
0
    def validate_company(self, data):
        collection = Collection.get_loaded_collection(name='Companies')
        if SimpleQuery.get_by_example(collection, example_data= {'name': str(data)}):
            raise serializers.ValidationError("Company already exist")

        return data