Skip to content

fix(cli): add ability to disable SSL verification #2717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions gitlab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,25 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
required=False,
default=os.getenv("GITLAB_URL"),
)
parser.add_argument(

ssl_verify_group = parser.add_mutually_exclusive_group()
ssl_verify_group.add_argument(
"--ssl-verify",
help=(
"Whether SSL certificates should be validated. [env var: GITLAB_SSL_VERIFY]"
"Path to a CA_BUNDLE file or directory with certificates of trusted CAs. "
"[env var: GITLAB_SSL_VERIFY]"
),
required=False,
default=os.getenv("GITLAB_SSL_VERIFY"),
)
ssl_verify_group.add_argument(
"--no-ssl-verify",
help="Disable SSL verification",
required=False,
dest="ssl_verify",
action="store_false",
)

Comment on lines +208 to +215
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the simplicity of this, but it doesn't fully fix #2714. We still cannot use environment variables (this is true for all of our booleans on the CLI). We'd need some kind of strtobool logic for those, and that maybe also falls back to strings for the ssl_verify arg. Also, the new flag doesn't have an env var equivalent this way like the others do. WDYT?

parser.add_argument(
"--timeout",
help=(
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ def test_base_parser():
assert args.verbose
assert args.gitlab == "gl_id"
assert args.config_file == ["foo.cfg", "bar.cfg"]
assert args.ssl_verify is None


def test_no_ssl_verify():
parser = cli._get_base_parser()
args = parser.parse_args(["--no-ssl-verify"])
assert args.ssl_verify is False


def test_v4_parse_args():
Expand Down