Ingress module mounting the dev/random device to generate a SHA256 hash string
1.8K
| name | Dev Random Ingress |
| type | ingress |
| version | v1.0.0 |
| docker image | weevenetwork/dev-random |
| tags | Docker, Weeve, MVP |
| authors | Marcus Jones |
This module and project demonstrates a docker container mounting a device from the host, reading data, and processing data from that device.
The simple ingress module mounts the linux random device to generate and forward a random hash string.
The /dev/urandom device node in linux generates unlimited random bytes of data. The data is generated from the entropy pool.
Bytes can be collected in various ways, just as from any file;
The dd utility can read and convert data from a file. The following command would read 3 bytes of data.
random="$(dd if=/dev/urandom bs=3 count=1)"
The head utility can read lines of a file. The following command would read 4096 bytes of data.
random=$(head -n 4096 /dev/urandom)
The sha256sum utility hashes input. The utility outputs a - characture which can be cut for a clean output.
echo My data | sha256sum | cut -f 1 -d " "
The jq utility can be used to package data into a JSON structure. The following command would place a variable $randomstring into the key value pair.
JSON_STRING=$( jq -n -r --arg hs "$randomstring" '{"random hash": $hs}' )
The curl utility is used to send HTTP data as a POST request. To avoid escaping newline and space characters, the payload (-d) is piped in.
echo $JSON_STRING | curl -d @- -H "Content-Type: application/json" -X POST http://url:port
Recommend to install the docker-pushrm plugin to publish READEM.md files.
docker login
# In one terminal;
NETWORK_NAME=dtestnet
docker network create $NETWORK_NAME
docker run --network=$NETWORK_NAME --rm -e PORT=4000 -e LOG_HTTP_BODY=true -e LOG_HTTP_HEADERS=true --name echo jmalloc/echo-server
# In second terminal;
NETWORK_NAME=dtestnet
VOLUME_HOST=/dev/urandom
VOLUME_CONTAINER=/mnt/random
APP_NAME=dev-random
ACCOUNT_NAME=weevenetwork
EGRESS_URL=echo:4000
docker run --network=$NETWORK_NAME --rm --volume $VOLUME_HOST:$VOLUME_CONTAINER -e EGRESS_URL=$EGRESS_URL -e VOLUME_CONTAINER=/mnt/random $ACCOUNT_NAME/$APP_NAME --hash sha256 --interval=2
Content type
Image
Digest
sha256:7b8da2d07…
Size
6.9 MB
Last updated
about 4 years ago
docker pull weevenetwork/dev-random:v1.0.0