add proxy
This commit is contained in:
@@ -47,48 +47,48 @@ class AWSProviderWithProxy(Provider):
|
||||
proxy_url = self._format_proxy_url(self.current_proxy)
|
||||
|
||||
user_data_script = f"""#!/bin/bash
|
||||
# 配置系统代理
|
||||
echo 'export http_proxy={proxy_url}' >> /etc/environment
|
||||
echo 'export https_proxy={proxy_url}' >> /etc/environment
|
||||
echo 'export HTTP_PROXY={proxy_url}' >> /etc/environment
|
||||
echo 'export HTTPS_PROXY={proxy_url}' >> /etc/environment
|
||||
# 配置系统代理
|
||||
echo 'export http_proxy={proxy_url}' >> /etc/environment
|
||||
echo 'export https_proxy={proxy_url}' >> /etc/environment
|
||||
echo 'export HTTP_PROXY={proxy_url}' >> /etc/environment
|
||||
echo 'export HTTPS_PROXY={proxy_url}' >> /etc/environment
|
||||
|
||||
# 配置apt代理
|
||||
cat > /etc/apt/apt.conf.d/95proxy << EOF
|
||||
Acquire::http::Proxy "{proxy_url}";
|
||||
Acquire::https::Proxy "{proxy_url}";
|
||||
EOF
|
||||
# 配置apt代理
|
||||
cat > /etc/apt/apt.conf.d/95proxy << EOF
|
||||
Acquire::http::Proxy "{proxy_url}";
|
||||
Acquire::https::Proxy "{proxy_url}";
|
||||
EOF
|
||||
|
||||
# 配置chrome/chromium代理
|
||||
mkdir -p /etc/opt/chrome/policies/managed
|
||||
cat > /etc/opt/chrome/policies/managed/proxy.json << EOF
|
||||
{{
|
||||
"ProxyMode": "fixed_servers",
|
||||
"ProxyServer": "{self.current_proxy.host}:{self.current_proxy.port}"
|
||||
}}
|
||||
EOF
|
||||
# 配置chrome/chromium代理
|
||||
mkdir -p /etc/opt/chrome/policies/managed
|
||||
cat > /etc/opt/chrome/policies/managed/proxy.json << EOF
|
||||
{{
|
||||
"ProxyMode": "fixed_servers",
|
||||
"ProxyServer": "{self.current_proxy.host}:{self.current_proxy.port}"
|
||||
}}
|
||||
EOF
|
||||
|
||||
# 配置firefox代理
|
||||
mkdir -p /etc/firefox/policies
|
||||
cat > /etc/firefox/policies/policies.json << EOF
|
||||
{{
|
||||
"policies": {{
|
||||
"Proxy": {{
|
||||
"Mode": "manual",
|
||||
"HTTPProxy": "{self.current_proxy.host}:{self.current_proxy.port}",
|
||||
"HTTPSProxy": "{self.current_proxy.host}:{self.current_proxy.port}",
|
||||
"UseHTTPProxyForAllProtocols": true
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
EOF
|
||||
# 配置firefox代理
|
||||
mkdir -p /etc/firefox/policies
|
||||
cat > /etc/firefox/policies/policies.json << EOF
|
||||
{{
|
||||
"policies": {{
|
||||
"Proxy": {{
|
||||
"Mode": "manual",
|
||||
"HTTPProxy": "{self.current_proxy.host}:{self.current_proxy.port}",
|
||||
"HTTPSProxy": "{self.current_proxy.host}:{self.current_proxy.port}",
|
||||
"UseHTTPProxyForAllProtocols": true
|
||||
}}
|
||||
}}
|
||||
}}
|
||||
EOF
|
||||
|
||||
# 重新加载环境变量
|
||||
source /etc/environment
|
||||
# 重新加载环境变量
|
||||
source /etc/environment
|
||||
|
||||
# 记录代理配置日志
|
||||
echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.port}" >> /var/log/proxy-setup.log
|
||||
"""
|
||||
# 记录代理配置日志
|
||||
echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.port}" >> /var/log/proxy-setup.log
|
||||
"""
|
||||
|
||||
return base64.b64encode(user_data_script.encode()).decode()
|
||||
|
||||
@@ -99,7 +99,7 @@ echo "$(date): Configured proxy {self.current_proxy.host}:{self.current_proxy.po
|
||||
else:
|
||||
return f"{proxy.protocol}://{proxy.host}:{proxy.port}"
|
||||
|
||||
def start_emulator(self, path_to_vm: str, headless: bool):
|
||||
def start_emulator(self, path_to_vm: str, headless: bool, os_type: str):
|
||||
logger.info("Starting AWS VM with proxy configuration...")
|
||||
ec2_client = boto3.client('ec2', region_name=self.region)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user