예제 #1
0
    def parse_args(self):
        """Parses command line arguments and returns the result.

        :returns: parsed command line arguments
        :rtype: argparse.Namespace

        """
        parsed_args = self.parser.parse_args(self.args)
        parsed_args.func = self.VERBS[self.verb]
        parsed_args.verb = self.verb

        # Do any post-parsing homework here

        # we get domains from -d, but also from the webroot map...
        if parsed_args.webroot_map:
            for domain in parsed_args.webroot_map.keys():
                if domain not in parsed_args.domains:
                    parsed_args.domains.append(domain)

        if parsed_args.staging or parsed_args.dry_run:
            if parsed_args.server not in (flag_default("server"),
                                          constants.STAGING_URI):
                conflicts = ["--staging"] if parsed_args.staging else []
                conflicts += ["--dry-run"] if parsed_args.dry_run else []
                if not self.detect_defaults:
                    raise errors.Error(
                        "--server value conflicts with {0}".format(
                            " and ".join(conflicts)))

            parsed_args.server = constants.STAGING_URI

            if parsed_args.dry_run:
                if self.verb not in ["certonly", "renew"]:
                    raise errors.Error(
                        "--dry-run currently only works with the "
                        "'certonly' or 'renew' subcommands (%r)" % self.verb)
                parsed_args.break_my_certs = parsed_args.staging = True
                if glob.glob(
                        os.path.join(parsed_args.config_dir,
                                     constants.ACCOUNTS_DIR, "*")):
                    # The user has a prod account, but might not have a staging
                    # one; we don't want to start trying to perform interactive registration
                    parsed_args.agree_tos = True
                    parsed_args.register_unsafely_without_email = True

        if parsed_args.csr:
            if parsed_args.allow_subset_of_names:
                raise errors.Error("--allow-subset-of-names "
                                   "cannot be used with --csr")
            self.handle_csr(parsed_args)

        if self.detect_defaults:  # plumbing
            parsed_args.store_false_vars = self.store_false_vars

        hooks.validate_hooks(parsed_args)

        return parsed_args
예제 #2
0
 def test_validate_hooks(self, mock_prog):
     config = mock.MagicMock(pre_hook="", post_hook="ls -lR", renew_hook="uptime")
     hooks.validate_hooks(config)
     self.assertEqual(mock_prog.call_count, 2)
     self.assertEqual(mock_prog.call_args_list[1][0][0], 'uptime')
     self.assertEqual(mock_prog.call_args_list[0][0][0], 'ls')
     mock_prog.return_value = None
     config = mock.MagicMock(pre_hook="explodinator", post_hook="", renew_hook="")
     self.assertRaises(errors.HookCommandNotFound, hooks.validate_hooks, config)
예제 #3
0
    def parse_args(self):
        """Parses command line arguments and returns the result.

        :returns: parsed command line arguments
        :rtype: argparse.Namespace

        """
        parsed_args = self.parser.parse_args(self.args)
        parsed_args.func = self.VERBS[self.verb]
        parsed_args.verb = self.verb

        # Do any post-parsing homework here

        # we get domains from -d, but also from the webroot map...
        if parsed_args.webroot_map:
            for domain in parsed_args.webroot_map.keys():
                if domain not in parsed_args.domains:
                    parsed_args.domains.append(domain)

        if parsed_args.staging or parsed_args.dry_run:
            if parsed_args.server not in (flag_default("server"), constants.STAGING_URI):
                conflicts = ["--staging"] if parsed_args.staging else []
                conflicts += ["--dry-run"] if parsed_args.dry_run else []
                if not self.detect_defaults:
                    raise errors.Error("--server value conflicts with {0}".format(
                        " and ".join(conflicts)))

            parsed_args.server = constants.STAGING_URI

            if parsed_args.dry_run:
                if self.verb not in ["certonly", "renew"]:
                    raise errors.Error("--dry-run currently only works with the "
                                       "'certonly' or 'renew' subcommands (%r)" % self.verb)
                parsed_args.break_my_certs = parsed_args.staging = True
                if glob.glob(os.path.join(parsed_args.config_dir, constants.ACCOUNTS_DIR, "*")):
                    # The user has a prod account, but might not have a staging
                    # one; we don't want to start trying to perform interactive registration
                    parsed_args.agree_tos = True
                    parsed_args.register_unsafely_without_email = True

        if parsed_args.csr:
            if parsed_args.allow_subset_of_names:
                raise errors.Error("--allow-subset-of-names "
                                   "cannot be used with --csr")
            self.handle_csr(parsed_args)

        if self.detect_defaults:  # plumbing
            parsed_args.store_false_vars = self.store_false_vars

        hooks.validate_hooks(parsed_args)

        return parsed_args
예제 #4
0
 def test_validate_hooks(self, mock_prog):
     config = mock.MagicMock(pre_hook="",
                             post_hook="ls -lR",
                             renew_hook="uptime")
     hooks.validate_hooks(config)
     self.assertEqual(mock_prog.call_count, 2)
     self.assertEqual(mock_prog.call_args_list[1][0][0], 'uptime')
     self.assertEqual(mock_prog.call_args_list[0][0][0], 'ls')
     mock_prog.return_value = None
     config = mock.MagicMock(pre_hook="explodinator",
                             post_hook="",
                             renew_hook="")
     self.assertRaises(errors.HookCommandNotFound, hooks.validate_hooks,
                       config)