-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: install dependencies with custom cert behind https proxy (#7)
* feat: install dependencies with custom cert behind https proxy * fix: change to https protocol for git
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import os | ||
import logging | ||
import subprocess | ||
import sys | ||
|
||
logger = logging.getLogger() | ||
handler = logging.StreamHandler(sys.stdout) | ||
logger.setLevel(logging.INFO) | ||
logger.addHandler(handler) | ||
|
||
proxy_url = os.environ.get("ALL_PROXY") | ||
if proxy_url is not None: | ||
# Just try to check if proxy is http or https | ||
# This does not validate the full url format | ||
scheme = proxy_url.split(":")[0] | ||
|
||
if scheme == "https": | ||
logger.info("Creating certificate bundle with proxy root CA, and installing 'awsiotsdk', 'cbor' and 'psutil'") | ||
try: | ||
import certifi | ||
|
||
except ImportError: | ||
try: | ||
from pip._vendor import certifi | ||
except Exception: | ||
logger.exception( | ||
"Error creating certificate bundle with proxy root CA. Python certifi module is not available on the device") | ||
sys.exit(1) | ||
try: | ||
with open(certifi.where(), 'r') as certify_root_ca, open(os.environ.get("GG_ROOT_CA_PATH"), 'r') as gg_root_ca, open('./ca-bundle.crt', 'w') as custom_cert_bundle: | ||
custom_cert_bundle.write(certify_root_ca.read()) | ||
custom_cert_bundle.write(gg_root_ca.read()) | ||
except Exception: | ||
logger.exception("Error creating certificate bundle with proxy root CA") | ||
sys.exit(1) | ||
try: | ||
subprocess.check_call( | ||
[sys.executable, '-m', 'pip', 'install', '--cert', './ca-bundle.crt', 'awsiotsdk', 'cbor', 'psutil', '--user']) | ||
sys.exit(0) | ||
except Exception: | ||
logger.exception( | ||
"Error installing dependencies. Please set 'UseInstaller' to 'False' and pre-install 'awsiotsdk', 'cbor' and 'psutil'") | ||
sys.exit(1) | ||
|
||
logger.info("Installing 'awsiotsdk', 'cbor' and 'psutil'") | ||
try: | ||
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'awsiotsdk', 'cbor', 'psutil', '--user']) | ||
except Exception: | ||
logger.exception( | ||
"Error installing dependencies. Please set 'UseInstaller' to 'False' and pre-install 'awsiotsdk', 'cbor' and 'psutil'") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
git+git://github.com/aws-samples/aws-iot-device-defender-agent-sdk-python.git@a3d27c51311e12625bd0b774e8b730ead3bc515d | ||
git+https://github.com/aws-samples/aws-iot-device-defender-agent-sdk-python.git@a3d27c51311e12625bd0b774e8b730ead3bc515d |