Skip to content

Commit 6211507

Browse files
committed
Set up Python module interception, to inject cert into Stripe
1 parent 087eaf6 commit 6211507

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,6 @@ pids
5151
typings/
5252
yarn-debug.log*
5353
yarn-error.log*
54+
55+
__pycache__
56+
*.pyc

overrides/pythonpath/stripe.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys, os
2+
3+
try:
4+
import importlib
5+
if not hasattr(importlib, 'reload'):
6+
raise Exception('wrong importlib')
7+
except:
8+
import imp
9+
importlib = imp
10+
11+
def _load_real_stripe():
12+
override_path = os.path.dirname(os.path.abspath(__file__))
13+
14+
original_sys_path = list(sys.path)
15+
sys.path = [p for p in sys.path if p != override_path]
16+
del sys.modules['stripe']
17+
import stripe
18+
sys.path = original_sys_path
19+
20+
def _inject_http_toolkit_certificate():
21+
import stripe
22+
stripe.ca_bundle_path = os.environ['SSL_CERT_FILE']
23+
24+
_load_real_stripe()
25+
_inject_http_toolkit_certificate()
26+
27+
# Re-export all public fields from Stripe
28+
from stripe import *
29+
# Load a few extra notable private fields, for max compatibility
30+
from stripe import __path__, __file__, __doc__

src/interceptors/terminal/terminal-env-overrides.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const PATH_VAR_SEPARATOR = process.platform === 'win32' ? ';' : ':';
66

77
const OVERRIDES_DIR = path.join(__dirname, '..', '..', '..', 'overrides');
88
const OVERRIDE_RUBYGEMS_PATH = path.join(OVERRIDES_DIR, 'gems');
9+
const OVERRIDE_PYTHONPATH = path.join(OVERRIDES_DIR, 'pythonpath');
910

1011
export const OVERRIDE_BIN_PATH = path.join(OVERRIDES_DIR, 'path');
1112

@@ -44,9 +45,15 @@ export function getTerminalEnvVars(
4445

4546
// Prepend our bin overrides into $PATH
4647
'PATH': `${OVERRIDE_BIN_PATH}${PATH_VAR_SEPARATOR}${process.env.PATH}`,
48+
4749
// Prepend our Ruby gem overrides into $LOAD_PATH
4850
'RUBYLIB': process.env.RUBYLIB
4951
? `${OVERRIDE_RUBYGEMS_PATH}:${process.env.RUBYLIB}`
50-
: OVERRIDE_RUBYGEMS_PATH
52+
: OVERRIDE_RUBYGEMS_PATH,
53+
54+
// Prepend our Python package overrides into $PYTHONPATH
55+
'PYTHONPATH': process.env.PYTHONPATH
56+
? `${OVERRIDE_PYTHONPATH}:${process.env.PYTHONPATH}`
57+
: OVERRIDE_PYTHONPATH
5158
};
5259
}

0 commit comments

Comments
 (0)