douyinWEB/scripts/_fix_s3_bucket_policy.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

62 lines
1.7 KiB
Python

# -*- coding: utf-8 -*-
import sys
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE = r"""
cd /opt/douyinWEB/backend
.venv/bin/python - <<'PY'
import json
import boto3
from botocore.client import Config
client = boto3.client(
's3',
endpoint_url='http://127.0.0.1:8333',
aws_access_key_id='douyin',
aws_secret_access_key='7a9b4d3c9f12bbe404aa2e506ad8e0a4b2ac',
region_name='us-east-1',
config=Config(signature_version='s3v4', s3={'addressing_style': 'path'}),
)
policy = {
'Version': '2012-10-17',
'Statement': [{
'Sid': 'PublicReadCovers',
'Effect': 'Allow',
'Principal': '*',
'Action': ['s3:GetObject'],
'Resource': ['arn:aws:s3:::douyin-covers/*'],
}],
}
try:
client.put_bucket_policy(Bucket='douyin-covers', Policy=json.dumps(policy))
print('put_bucket_policy OK')
except Exception as e:
print('put_bucket_policy FAIL', e)
# verify anonymous
import urllib.request
url = 'http://127.0.0.1:8333/douyin-covers/covers/5d3e14cd-8c13-4b7c-9522-e44dc1cad31e.jpg'
try:
with urllib.request.urlopen(url, timeout=10) as r:
print('anon GET', r.status, 'len', len(r.read()))
except Exception as e:
print('anon GET FAIL', e)
PY
systemctl restart douyinweb-api
sleep 4
systemctl is-active douyinweb-api
"""
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("108.174.50.68", 22, "root", "Xiao4669805", timeout=45, allow_agent=False, look_for_keys=False)
_i, o, e = c.exec_command(REMOTE, timeout=120)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace").strip()
if err:
print("ERR", err[:1500])
c.close()