Do not let file-* cmds to create containers
authorStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 28 Jan 2014 11:58:39 +0000 (13:58 +0200)
committerStavros Sachtouris <saxtouri@admin.grnet.gr>
Tue, 28 Jan 2014 11:58:39 +0000 (13:58 +0200)
Refs: #4992

kamaki/cli/commands/pithos.py
kamaki/clients/storage/__init__.py

index ae82dd4..f5652ef 100644 (file)
@@ -398,6 +398,13 @@ class file_modify(_pithos_container):
         self._run()
 
 
+def _assert_path(self, path_or_url):
+    if not self.path:
+        raiseCLIError(
+            'Directory path is missing in location %s' % path_or_url,
+            details=['Location format:    [[pithos://UUID]/CONTAINER/]PATH'])
+
+
 @command(file_cmds)
 class file_create(_pithos_container, _optional_output_cmd):
     """Create an empty file"""
@@ -418,6 +425,7 @@ class file_create(_pithos_container, _optional_output_cmd):
 
     def main(self, path_or_url):
         super(self.__class__, self)._run(path_or_url)
+        _assert_path(self, path_or_url)
         self._run()
 
 
@@ -429,12 +437,13 @@ class file_mkdir(_pithos_container, _optional_output_cmd):
     @errors.generic.all
     @errors.pithos.connection
     @errors.pithos.container
-    def _run(self):
+    def _run(self, path):
         self._optional_output(self.client.create_directory(self.path))
 
     def main(self, path_or_url):
         super(self.__class__, self)._run(path_or_url)
-        self._run()
+        _assert_path(self, path_or_url)
+        self._run(self.path)
 
 
 @command(file_cmds)
index d136139..fb168c4 100644 (file)
@@ -182,6 +182,7 @@ class StorageClient(Client):
         :returns: (dict) request headers
         """
         self._assert_container()
+        assert obj, 'Remote directory path is missing'
         path = path4url(self.account, self.container, obj)
         self.set_header('Content-Type', 'application/directory')
         self.set_header('Content-length', '0')