The ``--key`` option must be specified when ``--cert`` is a file. Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed.
(ctx: click.Context, param: click.Parameter, value: t.Any)
| 834 | |
| 835 | |
| 836 | def _validate_key(ctx: click.Context, param: click.Parameter, value: t.Any) -> t.Any: |
| 837 | """The ``--key`` option must be specified when ``--cert`` is a file. |
| 838 | Modifies the ``cert`` param to be a ``(cert, key)`` pair if needed. |
| 839 | """ |
| 840 | cert = ctx.params.get("cert") |
| 841 | is_adhoc = cert == "adhoc" |
| 842 | |
| 843 | try: |
| 844 | import ssl |
| 845 | except ImportError: |
| 846 | is_context = False |
| 847 | else: |
| 848 | is_context = isinstance(cert, ssl.SSLContext) |
| 849 | |
| 850 | if value is not None: |
| 851 | if is_adhoc: |
| 852 | raise click.BadParameter( |
| 853 | 'When "--cert" is "adhoc", "--key" is not used.', ctx, param |
| 854 | ) |
| 855 | |
| 856 | if is_context: |
| 857 | raise click.BadParameter( |
| 858 | 'When "--cert" is an SSLContext object, "--key" is not used.', |
| 859 | ctx, |
| 860 | param, |
| 861 | ) |
| 862 | |
| 863 | if not cert: |
| 864 | raise click.BadParameter('"--cert" must also be specified.', ctx, param) |
| 865 | |
| 866 | ctx.params["cert"] = cert, value |
| 867 | |
| 868 | else: |
| 869 | if cert and not (is_adhoc or is_context): |
| 870 | raise click.BadParameter('Required when using "--cert".', ctx, param) |
| 871 | |
| 872 | return value |
| 873 | |
| 874 | |
| 875 | class SeparatedPathType(click.Path): |