worker: Add env variable to change INFLUX, RNG and HASHER hosts
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
nemunaire 2021-11-19 12:16:18 +01:00
parent fa1ad86200
commit be67659532

View File

@ -6,6 +6,9 @@ import time
from influxdb import InfluxDBClient from influxdb import InfluxDBClient
DEBUG = os.environ.get("DEBUG", "").lower().startswith("y") DEBUG = os.environ.get("DEBUG", "").lower().startswith("y")
INFLUXDB_HOST = os.environ.get("INFLUXDB_HOST", "influxdb")
RNG_HOST = os.environ.get("RNG_HOST", "rng")
HASHER_HOST = os.environ.get("HASHER_HOST", "hasher")
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
if DEBUG: if DEBUG:
@ -14,15 +17,15 @@ else:
logging.basicConfig(level=logging.INFO) logging.basicConfig(level=logging.INFO)
logging.getLogger("requests").setLevel(logging.WARNING) logging.getLogger("requests").setLevel(logging.WARNING)
client = InfluxDBClient('influxdb', 8086, os.environ.get("INFLUXDB_USER", "chocominer"), os.environ.get("INFLUXDB_USER_PASSWORD", "chocominer"), os.environ.get("INFLUXDB_DB", "chocominer")) client = InfluxDBClient(INFLUXDB_HOST, 8086, os.environ.get("INFLUXDB_USER", "chocominer"), os.environ.get("INFLUXDB_USER_PASSWORD", "chocominer"), os.environ.get("INFLUXDB_DB", "chocominer"))
def get_random_bytes(): def get_random_bytes():
r = requests.get("http://rng/32") r = requests.get("http://" + RNG_HOST + "/32")
return r.content return r.content
def hash_bytes(data): def hash_bytes(data):
r = requests.post("http://hasher/", r = requests.post("http://" + HASHER_HOST + "/",
data=data, data=data,
headers={"Content-Type": "application/octet-stream"}) headers={"Content-Type": "application/octet-stream"})
hex_hash = r.text hex_hash = r.text