From nobody Mon Sep 16 19:19:39 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1530901970149613.4801020694165; Fri, 6 Jul 2018 11:32:50 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A241EC049D4B; Fri, 6 Jul 2018 18:32:49 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9313F9F78; Fri, 6 Jul 2018 18:32:49 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 855521800B68; Fri, 6 Jul 2018 18:32:49 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w66IWmlN014122 for ; Fri, 6 Jul 2018 14:32:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id BDA6B5D76F; Fri, 6 Jul 2018 18:32:48 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B2C795D761 for ; Fri, 6 Jul 2018 18:32:45 +0000 (UTC) Received: from mail-pf0-f182.google.com (mail-pf0-f182.google.com [209.85.192.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1931C4E90D for ; Fri, 6 Jul 2018 18:32:35 +0000 (UTC) Received: by mail-pf0-f182.google.com with SMTP id u16-v6so9079787pfh.3 for ; Fri, 06 Jul 2018 11:32:35 -0700 (PDT) Received: from localhost.localdomain ([112.196.135.85]) by smtp.gmail.com with ESMTPSA id o4-v6sm19941545pfa.128.2018.07.06.11.32.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Jul 2018 11:32:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kOXd9DWlCBm5o/u/XbO4C5KZVIoy9k5KT7s5BPOVcOg=; b=ZPKQH0SXkxrbk9ysgMOOyJ5NG4iWur2HPKUHCUyckDT0Mrd29HOqGF+frYFQ3DMF4J IQ1ufIqI/nnkGrihaVap1Pb3a1Kg623iB6g88tVyhGwB2VoyrFAU1TDqX/0tyUh++wVN hZ3QFp9eEEpBToMpjljNq8rqRZmNw2qpZWPe1eUfymUiS2Ci1Um9/GvwR4UfH6hg0Dgi UYfqhgpCDHz31Ilny8sCCRl2AiD3D16XhMRpNGd9MyToNs1oUoeZOLoK17iHPfR2j3RC NTQbwGu+9J/Whu3bYaJ6lU1Q0k6a9bXNj9i5Lw7pIkXxM7Rl9WdlJtCdAwyQsnuwF2Iv sx9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kOXd9DWlCBm5o/u/XbO4C5KZVIoy9k5KT7s5BPOVcOg=; b=TR4YyYvFgaH9uO3dG+2DxLKTraj9yfMkZylQvjk9mIi3w9Nx5bASkHHJ5S3yqthhkb ngdExdnSdRLwvgqPVvMnUtCRzI1cd/bIvgg2kRY/dlakNCQGv0qfOuguuowjo4aToxaq DB9YH1/7Xw8loPRT8E5lUViLP9Q3YUMXeIfbh5I0KxUzNSfESLlorGAobk9zhSS7BgTr HrmRG9KAhV4fCOI/46TXRS6ojL5UQUr6JvdbjnC16USNkwYoLXnoJmaoETiZL0JhoR3v XF33oKk7UF1NL1t2RbD2kEY0L3g71ncyYPqo8b80LX5zTkvcjfd7kPrF7mFPTKd1I5ZO 4S/w== X-Gm-Message-State: APt69E3k2iRV5x2LpdkEX3pB8HGldnD3P4uZOkhX64kVZewWrxmNh+IQ 5rYi0+t5nVPCU3xzBZ6UjjHl2A== X-Google-Smtp-Source: AAOMgpdeU3CysnmI585QjM3jVmhpeCVwhYRtX2C3UrjQB1fxkSSs1vQjV8qjZSCjAHAy5bdsH6LXXA== X-Received: by 2002:a62:a50e:: with SMTP id v14-v6mr11669030pfm.121.1530901954124; Fri, 06 Jul 2018 11:32:34 -0700 (PDT) From: Shubham Jain To: patchew-devel@redhat.com Date: Sat, 7 Jul 2018 00:02:04 +0530 Message-Id: <20180706183207.31842-2-shubhamjain7495@gmail.com> In-Reply-To: <20180706183207.31842-1-shubhamjain7495@gmail.com> References: <20180706183207.31842-1-shubhamjain7495@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 06 Jul 2018 18:32:35 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 06 Jul 2018 18:32:35 +0000 (UTC) for IP:'209.85.192.182' DOMAIN:'mail-pf0-f182.google.com' HELO:'mail-pf0-f182.google.com' FROM:'shubhamjain7495@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.551 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, SPF_PASS, T_DKIM_INVALID) 209.85.192.182 mail-pf0-f182.google.com 209.85.192.182 mail-pf0-f182.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: patchew-devel@redhat.com Cc: Shubham Jain Subject: [Patchew-devel] [PATCH v4 1/4] Changes in Patchew cli to use rest-api X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 06 Jul 2018 18:32:49 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Disabled CSRF authentication until OAuth authentication, since DRF leads = to csrf error while handling sessionauthentication. - Added general rest_api function to make request to apis and get response. --- api/rest.py | 6 ++++++ patchew-cli | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/api/rest.py b/api/rest.py index 9ec0ae8..45dab6e 100644 --- a/api/rest.py +++ b/api/rest.py @@ -25,6 +25,12 @@ from rest_framework.response import Response import rest_framework from mbox import addr_db_to_rest, MboxMessage from rest_framework.parsers import JSONParser, BaseParser +from rest_framework.authentication import SessionAuthentication + +class CsrfExemptSessionAuthentication(SessionAuthentication): + + def enforce_csrf(self, request): + return # To not perform the csrf check previously happening =20 SEARCH_PARAM =3D 'q' =20 diff --git a/patchew-cli b/patchew-cli index 174d1e6..2069885 100755 --- a/patchew-cli +++ b/patchew-cli @@ -92,6 +92,40 @@ class SubCommand(object): r =3D None return r =20 + def rest_api_do(self, url_cmd, request_method=3D'get', content_type=3D= None, data=3DNone): + logging.debug("API call '%s':" % url_cmd) + logging.debug("data:\n%s" % data) + cookie =3D http.cookiejar.MozillaCookieJar(COOKIE_FILENAME) + try: + cookie.load() + except IOError: + pass + except http.cookiejar.LoadError: + print("Error while loading cookie", COOKIE_FILENAME) + pass + handler =3D urllib.request.HTTPCookieProcessor(cookie) + opener =3D urllib.request.build_opener(handler) + if url_cmd.startswith("http"): + url =3D url_cmd + else: + url =3D self.base_url + '/api/v1/' + url_cmd + '/' + if data is None: + post_data =3D "" + else: + post_data =3D data + req =3D urllib.request.Request(url, data=3Dbytes(post_data, encodi= ng=3D"utf-8"), method=3Drequest_method.upper()) + if content_type is not None: + req.add_header('Content-Type', content_type) + resp =3D opener.open(req) + cookie.save(ignore_discard=3DTrue, ignore_expires=3DTrue) + respdata =3D resp.read() + logging.debug("Server response:\n%s" % (respdata or "")) + if respdata: + r =3D json.loads(respdata.decode("utf-8")) + else: + r =3D None + return r + =20 def do(self, args, argv): """Do command""" print("Not implemented") --=20 2.15.1 (Apple Git-101) _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel