-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
840404a
commit 8ce332e
Showing
27 changed files
with
910 additions
and
522 deletions.
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
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
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,3 @@ | ||
[submodule "regtest/boltz"] | ||
path = regtest/boltz | ||
url = https://github.com/BoltzExchange/regtest |
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
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
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,17 @@ | ||
FROM python:3.10-slim | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
RUN pip install --upgrade pip | ||
|
||
COPY requirements.txt . | ||
RUN pip install --no-cache-dir -r requirements.txt | ||
|
||
COPY ssl_proxy.py . | ||
|
||
EXPOSE 51234 | ||
|
||
CMD ["gunicorn", "--bind", "0.0.0.0:51234", "--workers", "2", "ssl_proxy:app"] |
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,4 @@ | ||
services: | ||
ssl-proxy: | ||
network_mode: "host" | ||
build: . |
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,5 @@ | ||
flask==2.2.5 | ||
flask-cors==3.0.10 | ||
requests==2.28.2 | ||
gunicorn==20.1.0 | ||
werkzeug==2.2.3 |
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,106 @@ | ||
from flask import Flask, request, json, Response | ||
from flask_cors import CORS | ||
import requests | ||
import logging | ||
|
||
app = Flask(__name__) | ||
CORS(app) # Allow all origins | ||
|
||
# Configure logging | ||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@app.route('/proxy', methods=['GET', 'POST', 'PUT', 'DELETE']) | ||
def proxy_request(): | ||
target_url = request.headers.get('X-Proxy-URL') | ||
|
||
if not target_url: | ||
return Response( | ||
json.dumps({"error": "No target URL provided"}), | ||
status=400, | ||
mimetype='application/json' | ||
) | ||
|
||
try: | ||
# Log the incoming request details | ||
logger.info(f"Proxy request to: {target_url}") | ||
logger.info(f"Request method: {request.method}") | ||
logger.info(f"Request headers: {dict(request.headers)}") | ||
|
||
# Try to log request body | ||
try: | ||
request_body = request.get_json(silent=True) | ||
logger.info(f"Request body: {request_body}") | ||
except Exception as body_log_error: | ||
logger.error(f"Could not log request body: {body_log_error}") | ||
|
||
# Prepare headers, excluding Flask-specific ones | ||
headers = { | ||
key: value for (key, value) in request.headers | ||
if key not in ['Host', 'X-Proxy-URL', 'Content-Length'] | ||
} | ||
|
||
# Determine the method and make the request | ||
methods = { | ||
'GET': requests.get, | ||
'POST': requests.post, | ||
'PUT': requests.put, | ||
'DELETE': requests.delete | ||
} | ||
|
||
method = methods.get(request.method) | ||
if not method: | ||
return Response( | ||
json.dumps({"error": "Unsupported HTTP method"}), | ||
status=405, | ||
mimetype='application/json' | ||
) | ||
|
||
# Prepare request arguments | ||
kwargs = { | ||
'url': target_url, | ||
'headers': headers, | ||
'verify': False # Bypass SSL verification | ||
} | ||
|
||
# Add data for methods that support it | ||
if request.method in ['POST', 'PUT']: | ||
# Try to parse request data as JSON if possible | ||
request_json = request.get_json(silent=True) | ||
if request_json: | ||
kwargs['json'] = request_json | ||
else: | ||
kwargs['data'] = request.get_data() | ||
|
||
# Make the request | ||
try: | ||
response = method(**kwargs) | ||
except Exception as request_error: | ||
logger.error(f"Request error: {request_error}") | ||
return Response( | ||
json.dumps({ | ||
"error": "Failed to make request to target service", | ||
"details": str(request_error) | ||
}), | ||
status=500, | ||
mimetype='application/json' | ||
) | ||
|
||
return Response( | ||
response.text, | ||
status=response.status_code, | ||
mimetype='application/json' | ||
) | ||
|
||
except Exception as e: | ||
logger.error(f"Unexpected error: {e}") | ||
return Response( | ||
json.dumps({"error": str(e)}), | ||
status=500, | ||
mimetype='application/json' | ||
) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(host='0.0.0.0', port=51234) |
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,9 @@ | ||
#!/bin/bash | ||
set -xe | ||
|
||
cd proxy | ||
docker compose down | ||
docker compose up --remove-orphans -d | ||
|
||
cd ../boltz | ||
./start.sh |
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,8 @@ | ||
#!/bin/bash | ||
set -xe | ||
|
||
cd boltz | ||
./stop.sh | ||
|
||
cd ../proxy | ||
docker compose down --volumes |
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,6 @@ | ||
#!/bin/bash | ||
export LND_MACAROON_HEX=$(xxd -p regtest/boltz/data/lnd1/data/chain/bitcoin/regtest/admin.macaroon | tr -d '\n') | ||
export BITCOIND_COOKIE=$(<regtest/boltz/data/bitcoind/regtest/.cookie) | ||
|
||
echo "LND_MACAROON_HEX set to: $LND_MACAROON_HEX" | ||
echo "BITCOIND_COOKIE set to: $BITCOIND_COOKIE" |
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
Oops, something went wrong.