Skip to content
This repository

Add HTTPS unpropagation support #48

Merged
merged 2 commits into from almost 3 years ago

1 participant

Patrick Armstrong
Patrick Armstrong
Collaborator

These two patches add support for HTTPS unpropagation via an HTTP PUT. If you've copied a credential in for staging, you can use that to authenticate your PUT request.

Patrick Armstrong oldpatricka merged commit 8c72c22 into from May 11, 2011
Patrick Armstrong oldpatricka closed this May 11, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
90  control/src/python/workspacecontrol/defaults/imageprocurement/propagate_https.py
@@ -4,6 +4,7 @@
4 4
 from urlparse import urlparse
5 5
 import httplib
6 6
 import shutil
  7
+from array import array
7 8
 from propagate_adapter import PropagationAdapter
8 9
 from workspacecontrol.api.exceptions import *
9 10
 import workspacecontrol.main.wc_args as wc_args
@@ -26,7 +27,10 @@ def validate_propagate_source(self, imagestr):
26 27
             raise InvalidInput("invalid url, not https:// " + remote)
27 28
 
28 29
     def validate_unpropagate_target(self, imagestr):
29  
-        raise InvalidInput("HTTPS unpropagation is not supported.")
  30
+        url = urlparse(imagestr)
  31
+        #urlparse breaks the url into a tuple
  32
+        if url[0] != "https":
  33
+            raise InvalidInput("invalid url, not https:// " + remote)
30 34
 
31 35
     def propagate(self, remote_source, local_absolute_target):
32 36
         self.c.log.info("HTTPS propagation - remote source: %s" % remote_source)
@@ -45,10 +49,6 @@ def propagate(self, remote_source, local_absolute_target):
45 49
                 port = 80
46 50
             else:
47 51
                 port = 443
48  
-        except ValueError:
49  
-            errmsg = "%s doesn't seem to be a port (must be an integer)" % host_port[1]
50  
-            self.c.log.exception(errmsg)
51  
-            raise InvalidInput(errmsg)
52 52
         credential = self._get_credential()
53 53
         self.c.log.debug("server: %s port %s credential %s" % (host, port, credential))
54 54
         if credential:
@@ -75,7 +75,54 @@ def propagate(self, remote_source, local_absolute_target):
75 75
         self.c.log.info("Transfer complete.")
76 76
 
77 77
     def unpropagate(self, local_absolute_source, remote_target):
78  
-        raise InvalidInput("HTTP unpropagation is not supported.")
  78
+        self.c.log.info("HTTPS unpropagation - local source: %s" % local_absolute_source)
  79
+        self.c.log.info("HTTPS unpropagation - remote target: %s" % remote_target)
  80
+
  81
+        url = urlparse(remote_target)
  82
+        scheme = url[0]
  83
+        netloc = url[1]
  84
+        path = url[2] + "?" + url[4]
  85
+        host_port = netloc.split(":")
  86
+        host = host_port[0]
  87
+        try:
  88
+            port = int(host_port[1])
  89
+        except IndexError:
  90
+            if scheme == 'http':
  91
+                port = 80
  92
+            else:
  93
+                port = 443
  94
+        credential = self._get_credential()
  95
+        self.c.log.debug("server: %s port %s credential %s" % (host, port, credential))
  96
+
  97
+        if credential:
  98
+            connection = HTTPSConnectionCompat(host, port, strict=False, key_file=credential, cert_file=credential)
  99
+        else:
  100
+            connection = HTTPSConnectionCompat(host, port)
  101
+
  102
+        try:
  103
+            try:
  104
+                image = open(local_absolute_source)
  105
+                # We pass an mmaped string, because httplib doesn't support passing
  106
+                # file objects in Python 2.4
  107
+                image_size = os.stat(image.name).st_size
  108
+                try:
  109
+                    connection.request("PUT", path, image, headers={'content-length': image_size})
  110
+                except:
  111
+                    self.c.log.exception("Problem unpropagating to %s" % remote_target)
  112
+                    raise
  113
+            except:
  114
+                self.c.log.exception("Could not open %s" % local_absolute_source)
  115
+                raise
  116
+        finally:
  117
+            image.close()
  118
+
  119
+        response = connection.getresponse()
  120
+
  121
+        if response.status != 200:
  122
+            raise InvalidInput("Problem unpropagating to %s. Got: '%s'" % (remote_target, response.reason))
  123
+
  124
+        self.c.log.info("Transfer complete.")
  125
+
79 126
 
80 127
     def _get_credential(self):
81 128
         extra_args = self.p.get_arg_or_none(wc_args.EXTRA_ARGS)
@@ -141,3 +188,34 @@ def _get_handle_redirects(self, connection, path):
141 188
                 raise UnexpectedError(errmsg)
142 189
 
143 190
             return self._get_handle_redirects(connection, redirect_path)
  191
+
  192
+class HTTPSConnectionCompat(httplib.HTTPSConnection):
  193
+    """
  194
+    HTTPSConnectionCompat subclasses HTTPSConnection to allow us to
  195
+    send large files. This is not supported in the httplib that is bundled
  196
+    with Python 2.4.
  197
+
  198
+    Once Python 2.4 compatibility is dropped, feel free to use a the
  199
+    HTTPSConnection object included with Python.
  200
+    """
  201
+
  202
+    def send(self, data):
  203
+        """Send `data' to the server."""
  204
+
  205
+        if self.sock is None:
  206
+            if self.auto_open:
  207
+                self.connect()
  208
+            else:
  209
+                raise NotConnected()
  210
+
  211
+        if self.debuglevel > 0:
  212
+            print "send:", repr(data)
  213
+        blocksize = 8192
  214
+        if hasattr(data,'read') and not isinstance(data, array):
  215
+            if self.debuglevel > 0: print "sendIng a read()able"
  216
+            datablock = data.read(blocksize)
  217
+            while datablock:
  218
+                self.sock.sendall(datablock)
  219
+                datablock = data.read(blocksize)
  220
+        else:
  221
+            self.sock.sendall(data)
7  service/service/java/source/src/org/globus/workspace/xen/XenUtil.java
@@ -243,6 +243,13 @@ public static ArrayList constructUnpropagateCommand(VirtualMachine vm,
243 243
             cmd.add(notificationInfo);
244 244
         }
245 245
 
  246
+        final String credentialName = vm.getCredentialName();
  247
+        if (credentialName != null) {
  248
+
  249
+            cmd.add("--prop-extra-args");
  250
+            cmd.add("'credential=" + credentialName + "'");
  251
+        }
  252
+
246 253
         return cmd;
247 254
     }
248 255
 
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.