-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
79 lines (68 loc) · 3.4 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
RR_PORT := 9000
RR_HOST := localhost
RR_SCHEMA := http
RR_API := create_oracle.chain
#https://apiroom.net:443/api/W3CDID/create_sandbox_zenswarm_did.chain
SECRET ?= ./secrets
KEYS := keys.json
HOST ?= 0.0.0.0
PORT ?= 9000
help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' Makefile
##@ Oracle management
setup:
@[ ! -x zenroom ] && \
wget https://github.com/dyne/zenroom/releases/latest/download/zenroom -O zenroom && \
chmod +x zenroom || exit 0
keygen: setup
keygen: ## Generate a new oracle keyring [DESCRIPTION]
$(if $(value DESCRIPTION), ,$(error Enter the final description that will be present in yout DID doc as DESCRIPTION="<description>"))
@[ -d ${SECRET} ] || mkdir ${SECRET} ;\
if [ -f ${SECRET}/${KEYS} ]; then printf "Delete the old ${SECRET}/${KEYS} file\n"; exit 1; fi ;\
tmp=$$(mktemp) ;\
echo "{\"controller\": \"${DESCRIPTION}\"}" > $${tmp} ;\
./zenroom -z -k $${tmp} announce_contracts/create_keys_and_pks.zen | tee ${SECRET}/keys.json && \
rm -f $${tmp}
announce: ORACLE_KEYRING ?= ${SECRET}/keys.json
announce: ## Create and send a DID request for the oracle [ORACLE_KEYRING, URL]
$(if $(wildcard ${ORACLE_KEYRING}),,$(error Oracle keyring not found in ${ORACLE_KEYRING}, add the right path as ORACLE_KEYRING="<path>"))
$(if $(value URL), ,$(error Enter the Oracle url as URL="<url>"))
@tmp=$$(mktemp); \
tmp3=$$(mktemp); \
tmp2=$$(mktemp); \
jq '.url = "${URL}"' announce_contracts/create_did.keys | tee $${tmp}; \
./zenroom -z -k ${SECRET}/keys.json -a $${tmp} announce_contracts/create_did.zen | tee $${tmp3}; \
curl -s -X "POST" "${RR_SCHEMA}://${RR_HOST}:${RR_PORT}/api/${RR_API}" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"data": '$$(cat $${tmp3})',"keys": {}}' \
| tee $${tmp2}; \
jq '{DID: .DID}' $${tmp2} > ${SECRET}/DID.json; \
curl -s $$(jq -r '.resolve_DID' $${tmp2}) | jq | tee ${SECRET}/DID_document.json; \
rm -f $${tmp} $${tmp2} $${tmp3};
run: ORACLE_TYPE ?= common
run: ORACLE_NAME ?= zenswarm-oracle
run: ## Run the oracle container [ORACLE_NAME, ORACLE_TYPE]
@[ -d logger ] || mkdir logger
ORACLE_NAME=${ORACLE_NAME} PORT=${PORT} HTTP_PORT=${PORT} HOST=${HOST} ORACLE_TYPE=${ORACLE_TYPE} SECRETS=${SECRET} docker compose -p ${ORACLE_NAME} up
kill: ## Stop the oracle container
@docker compose down
goodbye: ORACLE_KEYRING ?= ${SECRET}/keys.json
goodbye: ## Oracle deannounce (deactivate DID) [ORACLE_KEYRING]
$(if $(wildcard ${ORACLE_KEYRING}),,$(error Oracle keyring not found in ${ORACLE_KEYRING}, add the right path as ORACLE_KEYRING="<path>"))
@tmp=$$(mktemp); \
./zenroom -z -a announce_contracts/deactivate_did.keys -k secrets/keys.json announce_contracts/deactivate_did.zen > $${tmp}; \
curl -s -X "POST" "https://did.dyne.org:443/api/v1/sandbox/pubkeys-deactivate.chain" \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"data": '$$(cat $${tmp})',"keys": {}}' \
| jq '{DID: .result.didDocument.id}' \
| tee ${SECRET}/last_did_deactivated.json ;\
rm -f $${tmp};
##@ Image management
build:
docker compose build
test_api:
$(if $(value ZENCODE), ,$(error Enter the zencode api as ZENCODE="<api name>"))
@if [ ! -z ${DATA} ]; then INPUT_DATA="-a $${DATA}"; fi; \
./restroom-test -p 3000 -u $${ZENCODE} $${INPUT_DATA}