Skip to content

Commit

Permalink
add S3DAEMON_HOST & S3DAEMON_PORT env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Sep 6, 2024
1 parent 0f0e90a commit 0ba633b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions python/s3daemon/s3daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
),
)

PORT = 15555
host = os.environ.get("S3DAEMON_HOST", "localhost")
port = int(os.environ.get("S3DAEMON_PORT", 15555))
endpoint_url = os.environ["S3_ENDPOINT_URL"]
access_key = os.environ["AWS_ACCESS_KEY_ID"]
secret_key = os.environ["AWS_SECRET_ACCESS_KEY"]
Expand Down Expand Up @@ -89,7 +90,7 @@ async def main():
async def client_cb(reader, writer):
await handle_client(client, reader, writer)

server = await asyncio.start_server(client_cb, "localhost", PORT)
server = await asyncio.start_server(client_cb, host, port)
log.info("Starting server")
async with server:
await server.serve_forever()
Expand Down
6 changes: 4 additions & 2 deletions python/s3daemon/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.

import os
import socket
import sys

PORT = 15555
host = os.environ.get("S3DAEMON_HOST", "localhost")
port = int(os.environ.get("S3DAEMON_PORT", 15555))


def send(filename, dest):
Expand All @@ -37,7 +39,7 @@ def send(filename, dest):
The key may contain slashes.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect(("localhost", PORT))
sock.connect((host, port))
sock.sendall(bytes(f"{filename} {dest}\n", "UTF-8"))
received = str(sock.recv(4096), "utf-8")
sock.close()
Expand Down

0 comments on commit 0ba633b

Please sign in to comment.