← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~wgrant/launchpad/htaccess-in-archiveroot into lp:launchpad

 

William Grant has proposed merging lp:~wgrant/launchpad/htaccess-in-archiveroot into lp:launchpad.

Commit message:
Move P3A .htaccess and .htpasswd down into archiveroot (eg. /wgrant/ppa/ubuntu/.htaccess instead of /wgrant/ppa/.htaccess) so we can have PPAs for different distros with the same name.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)
Related bugs:
  Bug #1338438 in Launchpad itself: "P3A .htaccess should be inside archiveroot"
  https://bugs.launchpad.net/launchpad/+bug/1338438

For more details, see:
https://code.launchpad.net/~wgrant/launchpad/htaccess-in-archiveroot/+merge/225783

Move P3A .htaccess and .htpasswd down into archiveroot (eg. /wgrant/ppa/ubuntu/.htaccess instead of /wgrant/ppa/.htaccess) so we can have PPAs for different distros with the same name.

This can't be done until we deny directory listings on production. Additionally, the existing files will need to be moved between the last run of the old code and the first run of the new, which I'll handle with ops.
-- 
https://code.launchpad.net/~wgrant/launchpad/htaccess-in-archiveroot/+merge/225783
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~wgrant/launchpad/htaccess-in-archiveroot into lp:launchpad.
=== modified file 'lib/lp/archivepublisher/config.py'
--- lib/lp/archivepublisher/config.py	2014-06-09 09:32:21 +0000
+++ lib/lp/archivepublisher/config.py	2014-07-07 08:32:05 +0000
@@ -41,11 +41,8 @@
     if archive.is_ppa:
         if archive.private:
             pubconf.distroroot = ppa_config.private_root
-            pubconf.htaccessroot = os.path.join(
-                pubconf.distroroot, archive.owner.name, archive.name)
         else:
             pubconf.distroroot = ppa_config.root
-            pubconf.htaccessroot = None
         pubconf.archiveroot = os.path.join(
             pubconf.distroroot, archive.owner.name, archive.name,
             archive.distribution.name)

=== modified file 'lib/lp/archivepublisher/publishing.py'
--- lib/lp/archivepublisher/publishing.py	2014-07-03 04:51:30 +0000
+++ lib/lp/archivepublisher/publishing.py	2014-07-07 08:32:05 +0000
@@ -124,14 +124,14 @@
         # is added; bug=376072
         return
 
-    htaccess_path = os.path.join(pubconf.htaccessroot, ".htaccess")
-    htpasswd_path = os.path.join(pubconf.htaccessroot, ".htpasswd")
+    htaccess_path = os.path.join(pubconf.archiveroot, ".htaccess")
+    htpasswd_path = os.path.join(pubconf.archiveroot, ".htpasswd")
     # After the initial htaccess/htpasswd files
     # are created generate_ppa_htaccess is responsible for
     # updating the tokens.
     if not os.path.exists(htaccess_path):
         log.debug("Writing htaccess file.")
-        write_htaccess(htaccess_path, pubconf.htaccessroot)
+        write_htaccess(htaccess_path, pubconf.archiveroot)
         passwords = htpasswd_credentials_for_archive(archive)
         write_htpasswd(htpasswd_path, passwords)
 

=== modified file 'lib/lp/archivepublisher/scripts/generate_ppa_htaccess.py'
--- lib/lp/archivepublisher/scripts/generate_ppa_htaccess.py	2013-06-20 05:50:00 +0000
+++ lib/lp/archivepublisher/scripts/generate_ppa_htaccess.py	2014-07-07 08:32:05 +0000
@@ -69,12 +69,12 @@
         # The publisher Config object does not have an
         # interface, so we need to remove the security wrapper.
         pub_config = getPubConfig(ppa)
-        htaccess_filename = os.path.join(pub_config.htaccessroot, ".htaccess")
+        htaccess_filename = os.path.join(pub_config.archiveroot, ".htaccess")
         if not os.path.exists(htaccess_filename):
             # It's not there, so create it.
-            if not os.path.exists(pub_config.htaccessroot):
-                os.makedirs(pub_config.htaccessroot)
-            write_htaccess(htaccess_filename, pub_config.htaccessroot)
+            if not os.path.exists(pub_config.archiveroot):
+                os.makedirs(pub_config.archiveroot)
+            write_htaccess(htaccess_filename, pub_config.archiveroot)
             self.logger.debug("Created .htaccess for %s" % ppa.displayname)
 
     def generateHtpasswd(self, ppa):
@@ -85,9 +85,9 @@
         """
         # Create a temporary file that will be a new .htpasswd.
         pub_config = getPubConfig(ppa)
-        if not os.path.exists(pub_config.htaccessroot):
-            os.makedirs(pub_config.htaccessroot)
-        fd, temp_filename = tempfile.mkstemp(dir=pub_config.htaccessroot)
+        if not os.path.exists(pub_config.archiveroot):
+            os.makedirs(pub_config.archiveroot)
+        fd, temp_filename = tempfile.mkstemp(dir=pub_config.archiveroot)
         os.close(fd)
 
         write_htpasswd(
@@ -106,7 +106,7 @@
         # The publisher Config object does not have an
         # interface, so we need to remove the security wrapper.
         pub_config = getPubConfig(ppa)
-        htpasswd_filename = os.path.join(pub_config.htaccessroot, ".htpasswd")
+        htpasswd_filename = os.path.join(pub_config.archiveroot, ".htpasswd")
 
         if (not os.path.isfile(htpasswd_filename) or
             not filecmp.cmp(htpasswd_filename, temp_htpasswd_file)):

=== modified file 'lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py'
--- lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py	2012-06-14 05:18:22 +0000
+++ lib/lp/archivepublisher/tests/test_generate_ppa_htaccess.py	2014-07-07 08:32:05 +0000
@@ -102,7 +102,7 @@
         # need to remove the security wrapper.
         pub_config = getPubConfig(self.ppa)
 
-        filename = os.path.join(pub_config.htaccessroot, ".htaccess")
+        filename = os.path.join(pub_config.archiveroot, ".htaccess")
         remove_if_exists(filename)
         script = self.getScript()
         script.ensureHtaccess(self.ppa)
@@ -112,7 +112,7 @@
             "",
             "AuthType           Basic",
             "AuthName           \"Token Required\"",
-            "AuthUserFile       %s/.htpasswd" % pub_config.htaccessroot,
+            "AuthUserFile       %s/.htpasswd" % pub_config.archiveroot,
             "Require            valid-user",
             "",
             ]
@@ -137,8 +137,7 @@
         # target file when it's renamed, so that os.rename() won't
         # complain about renaming across file systems.
         pub_config = getPubConfig(self.ppa)
-        self.assertEqual(
-            pub_config.htaccessroot, os.path.dirname(filename))
+        self.assertEqual(pub_config.archiveroot, os.path.dirname(filename))
 
         # Read it back in.
         file_contents = [
@@ -160,14 +159,14 @@
         # The publisher Config object does not have an interface, so we
         # need to remove the security wrapper.
         pub_config = getPubConfig(self.ppa)
-        filename = os.path.join(pub_config.htaccessroot, ".htpasswd")
+        filename = os.path.join(pub_config.archiveroot, ".htpasswd")
 
         # Write out a dummy .htpasswd
-        ensure_directory_exists(pub_config.htaccessroot)
+        ensure_directory_exists(pub_config.archiveroot)
         write_file(filename, FILE_CONTENT)
 
         # Write the same contents in a temp file.
-        fd, temp_filename = tempfile.mkstemp(dir=pub_config.htaccessroot)
+        fd, temp_filename = tempfile.mkstemp(dir=pub_config.archiveroot)
         file = os.fdopen(fd, "w")
         file.write(FILE_CONTENT)
         file.close()
@@ -333,8 +332,8 @@
     def ensureNoFiles(self):
         """Ensure the .ht* files don't already exist."""
         pub_config = getPubConfig(self.ppa)
-        htaccess = os.path.join(pub_config.htaccessroot, ".htaccess")
-        htpasswd = os.path.join(pub_config.htaccessroot, ".htpasswd")
+        htaccess = os.path.join(pub_config.archiveroot, ".htaccess")
+        htpasswd = os.path.join(pub_config.archiveroot, ".htpasswd")
         remove_if_exists(htaccess)
         remove_if_exists(htpasswd)
         return htaccess, htpasswd

=== modified file 'lib/lp/archivepublisher/tests/test_publisher.py'
--- lib/lp/archivepublisher/tests/test_publisher.py	2013-08-29 10:29:01 +0000
+++ lib/lp/archivepublisher/tests/test_publisher.py	2014-07-07 08:32:05 +0000
@@ -1225,7 +1225,7 @@
         # setupArchiveDirs is what actually configures the htaccess file.
         getPublisher(ppa, [], self.logger).setupArchiveDirs()
         pubconf = getPubConfig(ppa)
-        htaccess_path = os.path.join(pubconf.htaccessroot, ".htaccess")
+        htaccess_path = os.path.join(pubconf.archiveroot, ".htaccess")
         self.assertTrue(os.path.exists(htaccess_path))
         with open(htaccess_path, 'r') as htaccess_f:
             self.assertEqual(dedent("""
@@ -1233,10 +1233,10 @@
                 AuthName           "Token Required"
                 AuthUserFile       %s/.htpasswd
                 Require            valid-user
-                """) % pubconf.htaccessroot,
+                """) % pubconf.archiveroot,
                 htaccess_f.read())
 
-        htpasswd_path = os.path.join(pubconf.htaccessroot, ".htpasswd")
+        htpasswd_path = os.path.join(pubconf.archiveroot, ".htpasswd")
 
         # Read it back in.
         with open(htpasswd_path, "r") as htpasswd_f:


Follow ups