示例#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

        if self.detect_defaults:
            return parsed_args

        self.defaults = dict((key, copy.deepcopy(self.parser.get_default(key)))
                             for key in vars(parsed_args))

        # Do any post-parsing homework here

        if self.verb == "renew":
            parsed_args.noninteractive_mode = True

        if parsed_args.staging or parsed_args.dry_run:
            self.set_test_server(parsed_args)

        if parsed_args.csr:
            self.handle_csr(parsed_args)

        if parsed_args.must_staple:
            parsed_args.staple = True

        if parsed_args.validate_hooks:
            hooks.validate_hooks(parsed_args)

        return parsed_args
示例#2
0
文件: cli.py 项目: benileo/certbot
    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

        if self.detect_defaults:
            return parsed_args

        self.defaults = dict((key, copy.deepcopy(self.parser.get_default(key)))
                             for key in vars(parsed_args))

        # Do any post-parsing homework here

        if self.verb == "renew":
            parsed_args.noninteractive_mode = True

        if parsed_args.staging or parsed_args.dry_run:
            self.set_test_server(parsed_args)

        if parsed_args.csr:
            self.handle_csr(parsed_args)

        if parsed_args.must_staple:
            parsed_args.staple = True

        if parsed_args.validate_hooks:
            hooks.validate_hooks(parsed_args)

        return parsed_args
示例#3
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)
示例#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)
示例#5
0
    def test_validation_order(self, mock_validate_hook):
        # This ensures error messages are about deploy hook when appropriate
        config = mock.Mock(deploy_hook=None, pre_hook=None,
                           post_hook=None, renew_hook=None)
        hooks.validate_hooks(config)

        order = [call[0][1] for call in mock_validate_hook.call_args_list]
        self.assertTrue('pre' in order)
        self.assertTrue('post' in order)
        self.assertTrue('deploy' in order)
        self.assertEqual(order[-1], 'renew')
示例#6
0
def _post_logging_setup(config, plugins, cli_args):
    """Perform any setup or configuration tasks that require a logger."""

    # This needs logging, but would otherwise be in HelpfulArgumentParser
    if config.validate_hooks:
        hooks.validate_hooks(config)

    cli.possible_deprecation_warning(config)

    logger.debug("certbot version: %s", certbot.__version__)
    # do not log `config`, as it contains sensitive data (e.g. revoke --key)!
    logger.debug("Arguments: %r", cli_args)
    logger.debug("Discovered plugins: %r", plugins)
示例#7
0
文件: main.py 项目: rlugojr/certbot
def _post_logging_setup(config, plugins, cli_args):
    """Perform any setup or configuration tasks that require a logger."""

    # This needs logging, but would otherwise be in HelpfulArgumentParser
    if config.validate_hooks:
        hooks.validate_hooks(config)

    cli.possible_deprecation_warning(config)

    logger.debug("certbot version: %s", certbot.__version__)
    # do not log `config`, as it contains sensitive data (e.g. revoke --key)!
    logger.debug("Arguments: %r", cli_args)
    logger.debug("Discovered plugins: %r", plugins)
示例#8
0
    def test_validation_order(self, mock_validate_hook):
        # This ensures error messages are about deploy hook when appropriate
        config = mock.Mock(deploy_hook=None,
                           pre_hook=None,
                           post_hook=None,
                           renew_hook=None)
        hooks.validate_hooks(config)

        order = [call[0][1] for call in mock_validate_hook.call_args_list]
        self.assertTrue('pre' in order)
        self.assertTrue('post' in order)
        self.assertTrue('deploy' in order)
        self.assertEqual(order[-1], 'renew')
示例#9
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

        if self.detect_defaults:
            return parsed_args

        # Do any post-parsing homework here

        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 []
                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.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)

        hooks.validate_hooks(parsed_args)

        return parsed_args
示例#10
0
文件: cli.py 项目: Torrus/certbot
    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

        if self.detect_defaults:
            return parsed_args

        self.defaults = dict((key, copy.deepcopy(self.parser.get_default(key)))
                             for key in vars(parsed_args))

        # Do any post-parsing homework here

        if self.verb == "renew" and not parsed_args.dialog_mode:
            parsed_args.noninteractive_mode = True

        if parsed_args.staging or parsed_args.dry_run:
            self.set_test_server(parsed_args)

        if parsed_args.csr:
            self.handle_csr(parsed_args)

        if parsed_args.must_staple:
            parsed_args.staple = True

        # Avoid conflicting args
        conficting_args = ["quiet", "noninteractive_mode", "text_mode"]
        if parsed_args.dialog_mode:
            for arg in conficting_args:
                if getattr(parsed_args, arg):
                    raise errors.Error(
                        ("Conflicting values for displayer."
                        " {0} conflicts with dialog_mode").format(arg)
                    )
        elif parsed_args.verbose_count > flag_default("verbose_count"):
            parsed_args.text_mode = True

        if parsed_args.validate_hooks:
            hooks.validate_hooks(parsed_args)

        return parsed_args
示例#11
0
文件: cli.py 项目: pmorawik/certbot
    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

        if self.detect_defaults:
            return parsed_args

        self.defaults = dict((key, copy.deepcopy(self.parser.get_default(key)))
                             for key in vars(parsed_args))

        # Do any post-parsing homework here

        if self.verb == "renew" and not parsed_args.dialog_mode:
            parsed_args.noninteractive_mode = True

        if parsed_args.staging or parsed_args.dry_run:
            self.set_test_server(parsed_args)

        if parsed_args.csr:
            self.handle_csr(parsed_args)

        if parsed_args.must_staple:
            parsed_args.staple = True

        # Avoid conflicting args
        conficting_args = ["quiet", "noninteractive_mode", "text_mode"]
        if parsed_args.dialog_mode:
            for arg in conficting_args:
                if getattr(parsed_args, arg):
                    raise errors.Error(
                        ("Conflicting values for displayer."
                        " {0} conflicts with dialog_mode").format(arg)
                    )
        elif parsed_args.verbose_count > flag_default("verbose_count"):
            parsed_args.text_mode = True

        if parsed_args.validate_hooks:
            hooks.validate_hooks(parsed_args)

        return parsed_args
示例#12
0
文件: cli.py 项目: diegodaddy/certbot
    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

        if self.detect_defaults:
            return parsed_args

        # Do any post-parsing homework here

        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 []
                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.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)

        hooks.validate_hooks(parsed_args)

        return parsed_args
示例#13
0
 def _call(cls, *args, **kwargs):
     from certbot.hooks import validate_hooks
     return validate_hooks(*args, **kwargs)
示例#14
0
 def _call(cls, *args, **kwargs):
     from certbot.hooks import validate_hooks
     return validate_hooks(*args, **kwargs)