Skip to content

Commit

Permalink
Merge pull request #296 from transifex/custom-ca-bundle
Browse files Browse the repository at this point in the history
CLI option for custom CA certificate bundle file
  • Loading branch information
deathbird authored Jun 30, 2020
2 parents 5edf1ed + b3cd3dc commit e5aa2b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion txclib/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from urllib3.exceptions import SSLError

from txclib import utils
from txclib import utils, web
from txclib.log import set_log_level, logger
from txclib.parsers import tx_main_parser
from txclib.exceptions import AuthenticationError
Expand Down Expand Up @@ -62,6 +62,8 @@ def main(argv=None):
elif options.debug:
set_log_level('DEBUG')

web.cacerts_file = options.cacert

# find .tx
path_to_tx = options.root_dir or utils.find_dot_tx()

Expand Down
12 changes: 12 additions & 0 deletions txclib/parsers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

import argparse
import os
import sys

Expand All @@ -11,6 +12,11 @@
'mapping', 'mapping-remote', 'mapping-bulk'
)

def check_file_exists(file=None):
if file and not os.path.isfile(file):
raise argparse.ArgumentTypeError(
'certificate file %s not found' % file)


def tx_main_parser():
description = "This is the Transifex command line client which"\
Expand Down Expand Up @@ -46,6 +52,12 @@ def tx_main_parser():
default=(os.name == 'nt' or not sys.stdout.isatty()),
help="disable colors in the output of commands"
)
# set a private CA cert bundle file to override the system one
parser.add_argument(
"--cacert", action="store", dest="cacert", default=None,
help="set path to CA certificate bundle file",
metavar='/path/to/ca-cert-bundle-file', type=check_file_exists
)
parser.add_argument(
"command", action="store", help="TX command", nargs='?', default=None
)
Expand Down
6 changes: 6 additions & 0 deletions txclib/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@
import txclib


cacerts_file = None

def user_agent_identifier():
"""Return the user agent for the client."""
client_info = (txclib.__version__, platform.system(), platform.machine())
return "txclient/%s (%s %s)" % client_info


def certs_file():
return cacerts_file or system_certs_file()


def system_certs_file():
if platform.system() == 'Windows':
return os.path.join(txclib.utils.get_base_dir(), 'cacert.pem')
else:
Expand Down

0 comments on commit e5aa2b7

Please sign in to comment.