Esempio n. 1
0
 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
Esempio n. 2
0
    def validate(self, data):
        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
Esempio n. 3
0
    def create(self, validated_data):
        #Init Arango Models
        ScheduleIntervalSettings.init()
        AwsCredentials.init()
        Companies.init()

        obj = ScheduleIntervalSettings()
        obj.account_id = AwsCredentials.objects.get(
            _id=str(validated_data['account_id']))
        print(str(validated_data['service']))
        obj.service = str(validated_data['service'])
        print(obj)
        obj.repeat_delay = int(validated_data['repeat_delay'])
        obj.user = int(self.context['user'])
        obj.save()
        return obj.id
Esempio n. 4
0
    def create(self, validated_data):
        #Init Arango Models
        AwsCredentials.init()
        Companies.init()

        obj = AwsCredentials()
        obj.role_arn = str(validated_data['role_arn'])
        obj.external_id = str(validated_data['external_id'])
        obj.account_name = str(validated_data['account_name'])
        obj.company = Companies.objects.get(_id=str(self.context['company']))
        obj.user = int(self.context['user'])
        obj.save()
        collection = Collection.get_loaded_collection('AwsExternalIds')
        SimpleQuery.update_by_example(collection,
                                      {'external_id': obj.external_id}, {
                                          'used': True,
                                          'company': str(obj.company.id),
                                          'user': obj.user
                                      })
        return obj.id
Esempio n. 5
0
 def post(self, request, format='json'):
     """
         API View that receives a POST with a role_arn, external_id, service and user id.
         It validates the given url hits the aws puller.
     """
     serializer = PullerSerializer(
         data=request.data,
         context={'company': self.request.user.company()})
     if serializer.is_valid():
         try:
             AwsCredentials.init()
             Companies.init()
             obj = AwsCredentials.objects.get(
                 _id=str(request.data['account_id']))
             data, headers = {
                 'external_id': obj.external_id,
                 'role_arn': obj.role_arn,
                 'service': request.data['service'],
                 'user': self.request.user.id,
                 'account_id': obj.id
             }, {
                 'content-type': 'application/json',
             }
             url = FOXX_BASE_URL + "puller"
             response = requests.post(url,
                                      headers=headers,
                                      data=json.dumps(data))
             return Response(response.content,
                             status=status.HTTP_201_CREATED)
         except Exception as e:
             return Response({
                 "items": {},
                 "message": str(e),
             },
                             status=status.HTTP_400_BAD_REQUEST)
     return Response(
         {
             "items": serializer.errors,
             "message": "Unable to Pull",
         },
         status=status.HTTP_400_BAD_REQUEST)
Esempio n. 6
0
    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
Esempio n. 7
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