From patchwork Wed Aug 17 21:16:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael-Doyle Hudson X-Patchwork-Id: 3491 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 7B67F23F42 for ; Wed, 17 Aug 2011 21:16:16 +0000 (UTC) Received: from mail-ew0-f52.google.com (mail-ew0-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id B428EA18022 for ; Wed, 17 Aug 2011 21:16:15 +0000 (UTC) Received: by ewy28 with SMTP id 28so755843ewy.11 for ; Wed, 17 Aug 2011 14:16:15 -0700 (PDT) Received: by 10.213.14.67 with SMTP id f3mr1490687eba.56.1313615775362; Wed, 17 Aug 2011 14:16:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.213.102.5 with SMTP id e5cs43601ebo; Wed, 17 Aug 2011 14:16:15 -0700 (PDT) Received: by 10.227.163.137 with SMTP id a9mr1243162wby.74.1313615774149; Wed, 17 Aug 2011 14:16:14 -0700 (PDT) Received: from indium.canonical.com (indium.canonical.com [91.189.90.7]) by mx.google.com with ESMTPS id fu6si4013369wbb.21.2011.08.17.14.16.13 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 17 Aug 2011 14:16:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) client-ip=91.189.90.7; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of bounces@canonical.com designates 91.189.90.7 as permitted sender) smtp.mail=bounces@canonical.com Received: from ackee.canonical.com ([91.189.89.26]) by indium.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QtnTB-0000tW-HG for ; Wed, 17 Aug 2011 21:16:13 +0000 Received: from ackee.canonical.com (localhost [127.0.0.1]) by ackee.canonical.com (Postfix) with ESMTP id 7822EE0205 for ; Wed, 17 Aug 2011 21:16:13 +0000 (UTC) MIME-Version: 1.0 X-Launchpad-Project: lava-dashboard X-Launchpad-Branch: ~linaro-validation/lava-dashboard/trunk X-Launchpad-Message-Rationale: Subscriber X-Launchpad-Branch-Revision-Number: 252 X-Launchpad-Notification-Type: branch-revision To: Linaro Patch Tracker From: noreply@launchpad.net Subject: [Branch ~linaro-validation/lava-dashboard/trunk] Rev 252: add a put_ex xmlrpc method that returns the URL of the bundle rather than its sha1 Message-Id: <20110817211613.9637.43504.launchpad@ackee.canonical.com> Date: Wed, 17 Aug 2011 21:16:13 -0000 Reply-To: noreply@launchpad.net Sender: bounces@canonical.com Errors-To: bounces@canonical.com Precedence: bulk X-Generated-By: Launchpad (canonical.com); Revision="13697"; Instance="initZopeless config overlay" X-Launchpad-Hash: b8fa42f64a3fa65f472d28b30aa2d0ae5fcdcb0f Merge authors: Michael Hudson-Doyle (mwhudson) Related merge proposals: https://code.launchpad.net/~mwhudson/lava-dashboard/put-return-url/+merge/71806 proposed by: Michael Hudson-Doyle (mwhudson) review: Approve - Zygmunt Krynicki (zkrynicki) ------------------------------------------------------------ revno: 252 [merge] committer: Michael-Doyle Hudson branch nick: trunk timestamp: Thu 2011-08-18 09:14:27 +1200 message: add a put_ex xmlrpc method that returns the URL of the bundle rather than its sha1 modified: dashboard_app/xmlrpc.py --- lp:lava-dashboard https://code.launchpad.net/~linaro-validation/lava-dashboard/trunk You are subscribed to branch lp:lava-dashboard. To unsubscribe from this branch go to https://code.launchpad.net/~linaro-validation/lava-dashboard/trunk/+edit-subscription === modified file 'dashboard_app/xmlrpc.py' --- dashboard_app/xmlrpc.py 2011-07-22 01:04:53 +0000 +++ dashboard_app/xmlrpc.py 2011-08-17 10:33:41 +0000 @@ -25,6 +25,7 @@ import xmlrpclib from django.contrib.auth.models import User, Group +from django.core.urlresolvers import reverse from django.db import IntegrityError, DatabaseError from linaro_django_xmlrpc.models import ( ExposedAPI, @@ -91,59 +92,7 @@ """ return ".".join(map(str, __version__)) - @xml_rpc_signature('str', 'str', 'str', 'str') - def put(self, content, content_filename, pathname): - """ - Name - ---- - `put` (`content`, `content_filename`, `pathname`) - - Description - ----------- - Upload a bundle to the server. - - Arguments - --------- - `content`: string - Full text of the bundle. This *SHOULD* be a valid JSON - document and it *SHOULD* match the "Dashboard Bundle Format - 1.0" schema. The SHA1 of the content *MUST* be unique or a - ``Fault(409, "...")`` is raised. This is used to protect - from simple duplicate submissions. - `content_filename`: string - Name of the file that contained the text of the bundle. The - `content_filename` can be an arbitrary string and will be - stored along with the content for reference. - `pathname`: string - Pathname of the bundle stream where a new bundle should - be created and stored. This argument *MUST* designate a - pre-existing bundle stream or a ``Fault(404, "...")`` exception - is raised. In addition the user *MUST* have access - permission to upload bundles there or a ``Fault(403, "...")`` - exception is raised. See below for access rules. - - Return value - ------------ - If all goes well this function returns the SHA1 of the content. - - Exceptions raised - ----------------- - 404 - Either: - - - Bundle stream not found - - Uploading to specified stream is not permitted - 409 - Duplicate bundle content - - Rules for bundle stream access - ------------------------------ - The following rules govern bundle stream upload access rights: - - all anonymous streams are accessible - - personal streams are accessible to owners - - team streams are accessible to team members - - """ + def _put(self, content, content_filename, pathname): try: logging.debug("Getting bundle stream") bundle_stream = BundleStream.objects.accessible_by_principal(self.user).get(pathname=pathname) @@ -163,8 +112,125 @@ else: logging.debug("Deserializing bundle") bundle.deserialize() - logging.debug("Returning content_sha1") - return bundle.content_sha1 + return bundle + + @xml_rpc_signature('str', 'str', 'str', 'str') + def put(self, content, content_filename, pathname): + """ + Name + ---- + `put` (`content`, `content_filename`, `pathname`) + + Description + ----------- + Upload a bundle to the server. + + Arguments + --------- + `content`: string + Full text of the bundle. This *SHOULD* be a valid JSON + document and it *SHOULD* match the "Dashboard Bundle Format + 1.0" schema. The SHA1 of the content *MUST* be unique or a + ``Fault(409, "...")`` is raised. This is used to protect + from simple duplicate submissions. + `content_filename`: string + Name of the file that contained the text of the bundle. The + `content_filename` can be an arbitrary string and will be + stored along with the content for reference. + `pathname`: string + Pathname of the bundle stream where a new bundle should + be created and stored. This argument *MUST* designate a + pre-existing bundle stream or a ``Fault(404, "...")`` exception + is raised. In addition the user *MUST* have access + permission to upload bundles there or a ``Fault(403, "...")`` + exception is raised. See below for access rules. + + Return value + ------------ + If all goes well this function returns the SHA1 of the content. + + Exceptions raised + ----------------- + 404 + Either: + + - Bundle stream not found + - Uploading to specified stream is not permitted + 409 + Duplicate bundle content + + Rules for bundle stream access + ------------------------------ + The following rules govern bundle stream upload access rights: + - all anonymous streams are accessible + - personal streams are accessible to owners + - team streams are accessible to team members + + """ + bundle = self._put(content, content_filename, pathname) + logging.debug("Returning bundle SHA1") + return bundle.content_sha1 + + @xml_rpc_signature('str', 'str', 'str', 'str') + def put_ex(self, content, content_filename, pathname): + """ + Name + ---- + `put` (`content`, `content_filename`, `pathname`) + + Description + ----------- + Upload a bundle to the server. A variant on put_ex that returns the + URL of the bundle instead of its SHA1. + + Arguments + --------- + `content`: string + Full text of the bundle. This *SHOULD* be a valid JSON + document and it *SHOULD* match the "Dashboard Bundle Format + 1.0" schema. The SHA1 of the content *MUST* be unique or a + ``Fault(409, "...")`` is raised. This is used to protect + from simple duplicate submissions. + `content_filename`: string + Name of the file that contained the text of the bundle. The + `content_filename` can be an arbitrary string and will be + stored along with the content for reference. + `pathname`: string + Pathname of the bundle stream where a new bundle should + be created and stored. This argument *MUST* designate a + pre-existing bundle stream or a ``Fault(404, "...")`` exception + is raised. In addition the user *MUST* have access + permission to upload bundles there or a ``Fault(403, "...")`` + exception is raised. See below for access rules. + + Return value + ------------ + If all goes well this function returns the full URL of the bundle. + + Exceptions raised + ----------------- + 404 + Either: + + - Bundle stream not found + - Uploading to specified stream is not permitted + 409 + Duplicate bundle content + + Rules for bundle stream access + ------------------------------ + The following rules govern bundle stream upload access rights: + - all anonymous streams are accessible + - personal streams are accessible to owners + - team streams are accessible to team members + + """ + bundle = self._put(content, content_filename, pathname) + logging.debug("Returning permalink to bundle") + return self._context.request.build_absolute_uri( + reverse( + 'dashboard_app.views.redirect_to_bundle', + kwargs={'content_sha1':bundle.content_sha1})) def get(self, content_sha1): """