Example #1
0
    def ensureHtaccess(self, ppa):
        """Generate a .htaccess for `ppa`."""
        if self.options.dryrun:
            return

        # 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.archiveroot, ".htaccess")
        if not os.path.exists(htaccess_filename):
            # It's not there, so create it.
            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 ensureHtaccess(self, ppa):
        """Generate a .htaccess for `ppa`."""
        if self.options.dryrun:
            return

        # 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")
        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)
            self.logger.debug("Created .htaccess for %s" % ppa.displayname)
Example #3
0
def _setupHtaccess(archive, pubconf, log):
    """Setup .htaccess/.htpasswd files for an archive.
    """
    if not archive.private:
        # FIXME: JRV 20101108 leftover .htaccess and .htpasswd files
        # should be removed when support for making existing 3PA's public
        # is added; bug=376072
        return

    htaccess_path = os.path.join(pubconf.htaccessroot, ".htaccess")
    htpasswd_path = os.path.join(pubconf.htaccessroot, ".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)
        passwords = htpasswd_credentials_for_archive(archive)
        write_htpasswd(htpasswd_path, passwords)
Example #4
0
    def test_write_htaccess(self):
        # write_access can write a correct htaccess file.
        fd, filename = tempfile.mkstemp()
        os.close(fd)

        write_htaccess(filename, "/some/distroot")
        self.assertTrue(os.path.isfile(filename),
                        "%s is not present when it should be" % filename)
        self.addCleanup(os.remove, filename)

        contents = [
            "",
            "AuthType           Basic",
            "AuthName           \"Token Required\"",
            "AuthUserFile       /some/distroot/.htpasswd",
            "Require            valid-user",
        ]

        file = open(filename, "r")
        file_contents = file.read().splitlines()
        file.close()

        self.assertEqual(contents, file_contents)
    def test_write_htaccess(self):
        # write_access can write a correct htaccess file.
        fd, filename = tempfile.mkstemp()
        os.close(fd)

        write_htaccess(filename, "/some/distroot")
        self.assertTrue(
            os.path.isfile(filename),
            "%s is not present when it should be" % filename)
        self.addCleanup(os.remove, filename)

        contents = [
            "",
            "AuthType           Basic",
            "AuthName           \"Token Required\"",
            "AuthUserFile       /some/distroot/.htpasswd",
            "Require            valid-user",
            ]

        file = open(filename, "r")
        file_contents = file.read().splitlines()
        file.close()

        self.assertEqual(contents, file_contents)