Пример #1
0
    def is_authenticated(self, request, **kwargs):
        """
        Finds the user and checks their API key.

        Should return either ``True`` if allowed, ``False`` if not or an
        ``HttpResponse`` if you need something custom.
        """

        try:
            p4env = P4Env(request)
        except ValueError:
            return self._unauthorized()

        if not p4env.user or not p4env.password:
            return self._unauthorized()

        p4login = P4Login(p4env)

        status = p4login.login_status()

        if status:
            request.p4env = p4env

        request._read_started = False

        return status
Пример #2
0
    def obj_get(self, bundle, **kwargs):
        req_args = {}
        for k in bundle.request.GET:
            req_args[k] = bundle.request.GET[k]

        runner = self._meta.runner_class(P4Env(bundle.request), **req_args)

        return P4Object(initial=runner.run())
Пример #3
0
    def get_identifier(self, request):
        """
        Provides a unique string identifier for the requestor.

        This implementation returns the user's username.
        """
        username, api_key = P4Env.extract_credentials(request)
        return username or 'nouser'
Пример #4
0
    def obj_get(self, bundle, **kwargs):
        req_args = {'client': kwargs['pk']}
        for k in bundle.request.GET:
            req_args[k] = bundle.request.GET[k]

        runner = P4ClientRunner(P4Env(bundle.request), **req_args)

        result = runner.run()

        data = {
            'message': result.stdout if result.succeeded else result.stderr,
            'client': kwargs['pk'],
        }
        return P4Object(initial=data)
Пример #5
0
    def obj_create(self, bundle, **kwargs):

        p4client = P4Client(P4Env(bundle.request))
        if 'client' in bundle.data:
            workspace = p4client.create_temp_workspace(bundle.data['client'])
        else:
            workspace = p4client.create_temp_workspace()

        data = {
            'client': os.path.basename(workspace),
            'workspace': workspace,
        }

        bundle.obj = P4Object(initial=data)

        return bundle
Пример #6
0
    def get_object_list(self, request):
        req_args = {'list': True}
        for k in request.GET:
            req_args[k] = request.GET[k]

        runner = P4ClientRunner(P4Env(request), **req_args)

        message = runner.run()

        if message.succeeded:
            result = []
            output_messages = message.stdout.splitlines()
            for msg in output_messages:
                result.append(
                    P4Object(initial={
                        'message': msg,
                        'client': msg.split()[1]
                    }))
            return result
        else:
            raise ValueError(message.stdout)
Пример #7
0
 def obj_delete(self, bundle, **kwargs):
     client = kwargs['pk']
     p4client = P4Client(P4Env(bundle.request))
     p4client.delete_temp_workspace(client)