Skip to content

Commit e14dae2

Browse files
committed
address review comments
Signed-off-by: Matthew Peveler <[email protected]>
1 parent 9022b57 commit e14dae2

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ In order of precedence:
5858
If you are experiencing issues with *tldr*, consider deleting the cache files before trying other measures.
5959

6060
### SSL Inspection
61-
* `TLDR_IGNORE_SSL=1` will disable SSL certificate inspection
61+
62+
For networks that sit behind a proxy, it may be necessary to disable SSL verification for the client to function. Setting the following:
63+
64+
* `TLDR_ALLOW_INSECURE=1`
65+
66+
will disable SSL certificate inspection. This __should be avoided__ unless absolutely necessary.
6267

6368
### Colors
6469

@@ -86,4 +91,4 @@ can either use the `--source` flag when using tldr or by specifying the followin
8691
* defaults to `https://raw.githubusercontent.com/tldr-pages/tldr/master/pages`
8792
* it can also point to local directory using `file:///path/to/directory`
8893
* `TLDR_DOWNLOAD_CACHE_LOCATION` to control where to pull a zip of all pages from
89-
* defaults to `https://tldr-pages.github.io/assets/tldr.zip`
94+
* defaults to `https://tldr-pages.github.io/assets/tldr.zip`

tldr.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,11 @@
2626
)
2727
USE_CACHE = int(os.environ.get('TLDR_CACHE_ENABLED', '1')) > 0
2828
MAX_CACHE_AGE = int(os.environ.get('TLDR_CACHE_MAX_AGE', 24))
29-
IGNORE_SSL = int(os.environ.get('TLDR_IGNORE_SSL','0'))
30-
31-
ignore_ctx = ssl.create_default_context()
32-
ignore_ctx .check_hostname = False
33-
ignore_ctx .verify_mode = ssl.CERT_NONE
34-
35-
36-
29+
URLOPEN_CONTEXT = None
30+
if int(os.environ.get('TLDR_ALLOW_INSECURE', '0')) == 1:
31+
URLOPEN_CONTEXT = ssl.create_default_context()
32+
URLOPEN_CONTEXT.check_hostname = False
33+
URLOPEN_CONTEXT.verify_mode = ssl.CERT_NONE
3734

3835
OS_DIRECTORIES = {
3936
"linux": "linux",
@@ -97,7 +94,7 @@ def get_page_for_platform(command, platform, remote=None):
9794
else:
9895
page_url = get_page_url(platform, command, remote)
9996
try:
100-
data = urlopen(Request(page_url, headers=REQUEST_HEADERS), context=ignore_ctx).read()
97+
data = urlopen(Request(page_url, headers=REQUEST_HEADERS), context=URLOPEN_CONTEXT).read()
10198
data_downloaded = True
10299
except Exception:
103100
data = load_page_from_cache(command, platform)
@@ -110,7 +107,7 @@ def get_page_for_platform(command, platform, remote=None):
110107

111108
def update_page_for_platform(command, platform, remote=None):
112109
page_url = get_page_url(platform, command, remote)
113-
data = urlopen(Request(page_url, headers=REQUEST_HEADERS), context=ignore_ctx).read()
110+
data = urlopen(Request(page_url, headers=REQUEST_HEADERS), context=URLOPEN_CONTEXT).read()
114111
store_page_to_cache(data, command, platform)
115112

116113

@@ -231,7 +228,7 @@ def update_cache():
231228
req = urlopen(Request(
232229
DOWNLOAD_CACHE_LOCATION,
233230
headers=REQUEST_HEADERS
234-
))
231+
), context=URLOPEN_CONTEXT)
235232
zipfile = ZipFile(BytesIO(req.read()))
236233
pattern = re.compile(r'pages/(.+)/(.+)\.md')
237234
cached = 0
@@ -281,8 +278,6 @@ def main():
281278

282279
colorama.init(strip=options.color)
283280

284-
other_options = [str('-'.join(other_options))]
285-
286281
if options.update_cache:
287282
update_cache()
288283
return

0 commit comments

Comments
 (0)