Пример #1
0
    def _threadDoGETJob(self, request):

        begin = request.hydrus_args['begin']

        path = SC.GetUpdatePath(self._service_key, begin)

        response_context = HC.ResponseContext(200, path=path, is_yaml=True)

        return response_context
Пример #2
0
    def _threadDoGETJob(self, request):

        hash = request.hydrus_args['hash']

        # don't I need to check that we aren't stealing the file from another service?

        path = SC.GetPath('thumbnail', hash)

        response_context = HC.ResponseContext(200, path=path)

        return response_context
Пример #3
0
    def post(self):
        user = SessionUtil.get_user_id(request.form['session'])
        if not user:
            return {'status': ServerConstants.STATUS_INVALID_SESSION}
        iid = request.form['insight_id']
        req_type = request.form['type']

        try:
            if req_type == "photo":
                ServerConstants.device_command_listener(iid, {"action": "cap_photo"})
            elif req_type == "audio":
                ServerConstants.device_command_listener(iid, {"action": "cap_audio"})
            elif req_type == "video":
                ServerConstants.device_command_listener(iid, {"action": "cap_video"})
            elif req_type == "setSystemEnabled":
                enabled = 'true' == request.form['enable']
                ServerConstants.device_command_listener(iid, {"action": "config_change", "system_enabled": enabled})
        except DeviceNotOnlineException:
            return {"status": ServerConstants.STATUS_DEVICE_OFFLINE}
        return {'status': '0'}
Пример #4
0
    def _test_repo(self, host, port, service_type):

        # set up connection

        service_identifier = HC.ClientServiceIdentifier(
            os.urandom(32), service_type, 'service')

        credentials = CC.Credentials(host, port, self._access_key)

        connection = CC.ConnectionToService(service_identifier, credentials)

        # news

        news = 'this is the news'

        connection.Post('news', news=news)

        written = HC.app.GetWrite('news')

        [(args, kwargs)] = written

        (written_service_identifier, written_news) = args

        self.assertEqual(news, written_news)

        # num_petitions

        num_petitions = 23

        HC.app.SetRead('num_petitions', num_petitions)

        response = connection.Get('num_petitions')

        self.assertEqual(response['num_petitions'], num_petitions)

        # petition

        petition = 'petition'

        HC.app.SetRead('petition', petition)

        response = connection.Get('petition')

        self.assertEqual(response['petition'], petition)

        # update

        update = 'update'

        update_key = os.urandom(32)

        path = SC.GetExpectedPath('update', update_key)

        with open(path, 'wb') as f:
            f.write(update)

        HC.app.SetRead('update_key', update_key)

        response = connection.Get('update', begin=100)

        self.assertEqual(response, update)

        try:
            os.remove(path)
        except:
            pass

        connection.Post('update', update=update)

        written = HC.app.GetWrite('update')

        [(args, kwargs)] = written

        (written_service_identifier, written_account, written_update) = args

        self.assertEqual(update, written_update)
Пример #5
0
    def _test_file_repo(self, host, port):

        # set up connection

        service_identifier = HC.ClientServiceIdentifier(
            os.urandom(32), HC.FILE_REPOSITORY, 'service')

        credentials = CC.Credentials(host, port, self._access_key)

        connection = CC.ConnectionToService(service_identifier, credentials)

        file_connection = httplib.HTTPConnection(host, port, timeout=10)

        # file

        path = SC.GetExpectedPath('file', self._file_hash)

        with open(path, 'wb') as f:
            f.write('file')

        response = connection.Get('file', hash=self._file_hash.encode('hex'))

        self.assertEqual(response, 'file')

        try:
            os.remove(path)
        except:
            pass

        path = HC.STATIC_DIR + os.path.sep + 'hydrus.png'

        with open(path, 'rb') as f:
            file = f.read()

        connection.Post('file', file=file)

        written = HC.app.GetWrite('file')

        [(args, kwargs)] = written

        (written_service_identifier, written_account, written_file_dict) = args

        self.assertEqual(
            written_file_dict['hash'],
            '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3'
        )
        self.assertEqual(written_file_dict['ip'], '127.0.0.1')
        self.assertEqual(written_file_dict['height'], 200)
        self.assertEqual(written_file_dict['width'], 200)
        self.assertEqual(written_file_dict['mime'], 2)
        self.assertEqual(written_file_dict['size'], 5270)

        # ip

        (ip, timestamp) = ('94.45.87.123', HC.GetNow() - 100000)

        HC.app.SetRead('ip', (ip, timestamp))

        response = connection.Get('ip', hash=self._file_hash.encode('hex'))

        self.assertEqual(response['ip'], ip)
        self.assertEqual(response['timestamp'], timestamp)

        # thumbnail

        path = SC.GetExpectedPath('thumbnail', self._file_hash)

        with open(path, 'wb') as f:
            f.write('thumb')

        response = connection.Get('thumbnail',
                                  hash=self._file_hash.encode('hex'))

        self.assertEqual(response, 'thumb')

        try:
            os.remove(path)
        except:
            pass
Пример #6
0
    def _test_repo(self, service, host, port):

        service_key = service.GetServiceKey()

        # news

        news = 'this is the news'

        service.Request(HC.POST, 'news', {'news': news})

        written = HC.app.GetWrite('news')

        [(args, kwargs)] = written

        (written_service_key, written_news) = args

        self.assertEqual(news, written_news)

        # num_petitions

        num_petitions = 23

        HC.app.SetRead('num_petitions', num_petitions)

        response = service.Request(HC.GET, 'num_petitions')

        self.assertEqual(response['num_petitions'], num_petitions)

        # petition

        petition = 'petition'

        HC.app.SetRead('petition', petition)

        response = service.Request(HC.GET, 'petition')

        self.assertEqual(response['petition'], petition)

        # update

        update = 'update'
        begin = 100

        path = SC.GetExpectedUpdatePath(service_key, begin)

        with open(path, 'wb') as f:
            f.write(update)

        response = service.Request(HC.GET, 'update', {'begin': begin})

        self.assertEqual(response, update)

        try:
            os.remove(path)
        except:
            pass

        service.Request(HC.POST, 'update', {'update': update})

        written = HC.app.GetWrite('update')

        [(args, kwargs)] = written

        (written_service_key, written_account, written_update) = args

        self.assertEqual(update, written_update)
Пример #7
0
    def _test_file_repo(self, service, host, port):

        info = service.GetInfo()

        info['access_key'] = self._access_key

        # file

        path = SC.GetExpectedPath('file', self._file_hash)

        with open(path, 'wb') as f:
            f.write('file')

        response = service.Request(HC.GET, 'file',
                                   {'hash': self._file_hash.encode('hex')})

        self.assertEqual(response, 'file')

        try:
            os.remove(path)
        except:
            pass

        path = HC.STATIC_DIR + os.path.sep + 'hydrus.png'

        with open(path, 'rb') as f:
            file = f.read()

        service.Request(HC.POST, 'file', {'file': file})

        written = HC.app.GetWrite('file')

        [(args, kwargs)] = written

        (written_service_key, written_account, written_file_dict) = args

        self.assertEqual(
            written_file_dict['hash'],
            '\xadm5\x99\xa6\xc4\x89\xa5u\xeb\x19\xc0&\xfa\xce\x97\xa9\xcdey\xe7G(\xb0\xce\x94\xa6\x01\xd22\xf3\xc3'
        )
        self.assertEqual(written_file_dict['ip'], '127.0.0.1')
        self.assertEqual(written_file_dict['height'], 200)
        self.assertEqual(written_file_dict['width'], 200)
        self.assertEqual(written_file_dict['mime'], 2)
        self.assertEqual(written_file_dict['size'], 5270)

        # ip

        (ip, timestamp) = ('94.45.87.123', HC.GetNow() - 100000)

        HC.app.SetRead('ip', (ip, timestamp))

        response = service.Request(HC.GET, 'ip',
                                   {'hash': self._file_hash.encode('hex')})

        self.assertEqual(response['ip'], ip)
        self.assertEqual(response['timestamp'], timestamp)

        # thumbnail

        path = SC.GetExpectedPath('thumbnail', self._file_hash)

        with open(path, 'wb') as f:
            f.write('thumb')

        response = service.Request(HC.GET, 'thumbnail',
                                   {'hash': self._file_hash.encode('hex')})

        self.assertEqual(response, 'thumb')

        try:
            os.remove(path)
        except:
            pass