Compare commits

...

17 commits

Author SHA1 Message Date
pedro 1f0a9a60ce add file snapshot_pre-verifiable-credential 2025-01-30 13:26:47 +01:00
pedro 01b7267dd8 docker: add DEMO env var to idhub 2025-01-30 13:11:55 +01:00
pedro 91c03cb990 Merge pull request 'add did document link to device details page' (#44) from diddocument into main
Reviewed-on: #44
2025-01-30 08:50:38 +00:00
pedro 9dafc51210 disable devicehub demo by default (part 2) 2025-01-30 09:27:55 +01:00
pedro 7f16552762 disable devicehub demo by default
(right now is not working, we are waiting open service feature)
2025-01-30 09:19:37 +01:00
pedro 829fb6e2a1 devicehub: don't rush on the vc signing 2025-01-30 09:05:06 +01:00
pedro 02a69e6994 devicehub: add error handling when waiting idhub 2025-01-30 08:59:01 +01:00
pedro 2ff630f212 docker: attempt to fix docker image deployment 2025-01-30 08:46:27 +01:00
pedro d7d6fb7bc6 make devicehub autosign a vc using idhub 2025-01-30 08:39:22 +01:00
pedro 096704935d better error message on receiving snapshot 2025-01-30 08:09:20 +01:00
pedro 0485604512 rename credentials according to last meeting
we found a way with cayo to generate a real credential on demo time,
and that's going to be done on following commits in this branch

related ereuse/projectes#131
2025-01-29 20:20:23 +01:00
pedro 40b0617a72 docker: add the missing predefined token config 2025-01-29 19:25:26 +01:00
pedro b1c4a2cec9 add the right SUPPORTED_CREDENTIALS 2025-01-29 19:19:57 +01:00
Cayo Puigdefabregas 9503a9a8b4 add did document to details page 2025-01-29 19:07:11 +01:00
pedro 9247f11c27 Merge pull request 'docker-add-idhub' (#43) from docker-add-idhub into main
Reviewed-on: #43
2025-01-29 17:57:48 +00:00
pedro 56d8aadf83 docker: docker for devicehub and idhub as profile 2025-01-27 17:52:24 +01:00
pedro 601da538bf add idhub to dockercompose and its .env.example 2025-01-23 12:56:55 +01:00
15 changed files with 213 additions and 25 deletions

2
.dockerignore Normal file
View file

@ -0,0 +1,2 @@
db
.git

View file

@ -1,5 +1,15 @@
DH_DOMAIN=localhost ####
DH_PORT=8000 # DEV OPTIONS
####
DEV_DOCKER_ALWAYS_BUILD=false
####
# DEVICEHUB
####
DEVICEHUB_DOMAIN=localhost
DEVICEHUB_PORT=8001
DEMO=true DEMO=true
# note that with DEBUG=true, logs are more verbose (include tracebacks) # note that with DEBUG=true, logs are more verbose (include tracebacks)
DEBUG=true DEBUG=true
@ -16,7 +26,48 @@ EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
EMAIL_FILE_PATH="/tmp/app-messages" EMAIL_FILE_PATH="/tmp/app-messages"
ENABLE_EMAIL=false ENABLE_EMAIL=false
PREDEFINED_TOKEN='5018dd65-9abd-4a62-8896-80f34ac66150' PREDEFINED_TOKEN='5018dd65-9abd-4a62-8896-80f34ac66150'
DH_ALLOWED_HOSTS=${DH_DOMAIN},${DH_DOMAIN}:${DH_PORT},127.0.0.1,127.0.0.1:${DH_PORT} DEVICEHUB_ALLOWED_HOSTS=${DEVICEHUB_DOMAIN},${DEVICEHUB_DOMAIN}:${DEVICEHUB_PORT},127.0.0.1,127.0.0.1:${DEVICEHUB_PORT}
# TODO review these vars # TODO review these vars
#SNAPSHOTS_DIR=/path/to/TODO #SNAPSHOTS_DIR=/path/to/TODO
#EVIDENCES_DIR=/path/to/TODO #EVIDENCES_DIR=/path/to/TODO
#DEMO_IDHUB_DOMAIN='idhub.example.org'
####
# IDHUB
####
IDHUB_ENABLED=false
IDHUB_DOMAIN=localhost
IDHUB_PORT=9001
IDHUB_ALLOWED_HOSTS=${IDHUB_DOMAIN},${IDHUB_DOMAIN}:${IDHUB_PORT},127.0.0.1,127.0.0.1:${IDHUB_PORT}
IDHUB_TIME_ZONE='Europe/Madrid'
#IDHUB_SECRET_KEY='uncomment-it-and-fill-this'
# enable dev flags when DEVELOPMENT deployment
# adapt to your domain in a production/reverse proxy env
IDHUB_CSRF_TRUSTED_ORIGINS='https://idhub.example.org'
# fill this section with your email credentials
IDHUB_DEFAULT_FROM_EMAIL="user@example.org"
IDHUB_EMAIL_HOST="smtp.example.org"
IDHUB_EMAIL_HOST_USER="smtp_user"
IDHUB_EMAIL_HOST_PASSWORD="smtp_passwd"
IDHUB_EMAIL_PORT=25
IDHUB_EMAIL_USE_TLS=True
IDHUB_EMAIL_BACKEND="django.core.mail.backends.smtp.EmailBackend"
# replace with production data
# this is used when IDHUB_DEPLOYMENT is not equal to DEVELOPMENT
IDHUB_ADMIN_USER='admin'
IDHUB_ADMIN_PASSWD='admin'
IDHUB_ADMIN_EMAIL='admin@example.org'
# this option needs to be set to 'n' to be able to make work idhub in docker
# by default it is set to 'y' to facilitate idhub dev when outside docker
IDHUB_SYNC_ORG_DEV='n'
# TODO that is only for testing
IDHUB_ENABLE_EMAIL=false
IDHUB_ENABLE_2FACTOR_AUTH=false
IDHUB_ENABLE_DOMAIN_CHECKER=false
IDHUB_PREDEFINED_TOKEN='27f944ce-3d58-4f48-b068-e4aa95f97c95'

5
.gitignore vendored
View file

@ -1,4 +1,7 @@
db.sqlite3
env/ env/
__pycache__/ __pycache__/
.env .env
# the following could be autogenerated by devicehub
db.sqlite3
example/snapshots/snapshot_workbench-script_verifiable-credential.json

View file

@ -90,7 +90,7 @@ class NewSnapshotView(ApiMixing):
ev_uuid = data["credentialSubject"].get("uuid") ev_uuid = data["credentialSubject"].get("uuid")
if not ev_uuid: if not ev_uuid:
txt = "error: the snapshot not have uuid" txt = "error: the snapshot does not have an uuid"
logger.error("%s", txt) logger.error("%s", txt)
return JsonResponse({'status': txt}, status=500) return JsonResponse({'status': txt}, status=500)

View file

@ -315,3 +315,8 @@ class Device:
def components(self): def components(self):
self.get_last_evidence() self.get_last_evidence()
return self.last_evidence.get_components() return self.last_evidence.get_components()
@property
def did_document(self):
self.get_last_evidence()
return self.last_evidence.get_did_document()

View file

@ -228,17 +228,33 @@
<div class="tab-pane fade" id="evidences"> <div class="tab-pane fade" id="evidences">
<h5 class="card-title">{% trans 'List of evidences' %}</h5> <h5 class="card-title">{% trans 'List of evidences' %}</h5>
<div class="list-group col-6"> <div class="list-group col">
<table class="table">
<thead>
<tr>
<th scope="col">uuid</th>
<th scope="col">Did Document</th>
<th scope="col">{% trans "Date" %}</th>
</tr>
</thead>
<tbody>
{% for snap in object.evidences %} {% for snap in object.evidences %}
<div class="list-group-item"> <tr>
<div class="d-flex w-100 justify-content-between"> <td>
<small class="text-muted">{{ snap.created }}</small>
</div>
<p class="mb-1">
<a href="{% url 'evidence:details' snap.uuid %}">{{ snap.uuid }}</a> <a href="{% url 'evidence:details' snap.uuid %}">{{ snap.uuid }}</a>
</p> </td>
</div> <td>
{% if snap.did_document %}
<a href="{{ snap.did_document }}" target="_blank">DID</a>
{% endif %}
</td>
<td>
<small class="text-muted">{{ snap.created }}</small>
</td>
</tr>
{% endfor %} {% endfor %}
</tbody>
</table>
</div> </div>
</div> </div>

View file

@ -1,18 +1,59 @@
services: services:
devicehub-django: devicehub-django:
init: true init: true
image: farga.pangea.org/ereuse/devicehub-django/latest
build: build:
context: .
dockerfile: docker/devicehub-django.Dockerfile dockerfile: docker/devicehub-django.Dockerfile
environment: environment:
- DEBUG=${DEBUG:-false} - DEBUG=${DEBUG:-false}
- DOMAIN=${DH_DOMAIN:-localhost} - DOMAIN=${DEVICEHUB_DOMAIN:-localhost}
- PORT=${DH_PORT:-8000} - PORT=${DEVICEHUB_PORT:-8000}
- ALLOWED_HOSTS=${DH_ALLOWED_HOSTS:-$DH_DOMAIN} - ALLOWED_HOSTS=${DEVICEHUB_ALLOWED_HOSTS:-$DEVICEHUB_DOMAIN}
- DEMO=${DEMO:-false} - DEMO=${DEMO:-false}
- DEMO_IDHUB_DOMAIN=${DEMO_IDHUB_DOMAIN:-}
- DEMO_IDHUB_PREDEFINED_TOKEN=${IDHUB_PREDEFINED_TOKEN:-}
- PREDEFINED_TOKEN=${PREDEFINED_TOKEN:-} - PREDEFINED_TOKEN=${PREDEFINED_TOKEN:-}
- DPP=${DPP:-false} - DPP=${DPP:-false}
# TODO manage volumes dev vs prod
volumes: volumes:
- .:/opt/devicehub-django - .:/opt/devicehub-django
ports: ports:
- ${DH_PORT}:${DH_PORT} - ${DEVICEHUB_PORT:-8000}:${DEVICEHUB_PORT:-8000}
# TODO add database service for idhub, meanwhile sqlite
idhub:
# https://docs.docker.com/compose/how-tos/profiles/
profiles: [idhub]
init: true
image: farga.pangea.org/ereuse/idhub/latest
environment:
- DOMAIN=${IDHUB_DOMAIN:-localhost}
- ALLOWED_HOSTS=${IDHUB_ALLOWED_HOSTS:-$IDHUB_DOMAIN}
- DEBUG=true
- DEMO=${DEMO:-false}
- INITIAL_ADMIN_EMAIL=${IDHUB_ADMIN_EMAIL}
- INITIAL_ADMIN_PASSWORD=${IDHUB_ADMIN_PASSWD}
- CREATE_TEST_USERS=true
- ENABLE_EMAIL=${IDHUB_ENABLE_EMAIL:-true}
- ENABLE_2FACTOR_AUTH=${IDHUB_ENABLE_2FACTOR_AUTH:-true}
- ENABLE_DOMAIN_CHECKER=${IDHUB_ENABLE_DOMAIN_CHECKER:-true}
- PREDEFINED_TOKEN=${IDHUB_PREDEFINED_TOKEN:-}
- SECRET_KEY=${IDHUB_SECRET_KEY:-publicsecretisnotsecureVtmKBfxpVV47PpBCF2Nzz2H6qnbd}
- STATIC_ROOT=${IDHUB_STATIC_ROOT:-/static/}
- MEDIA_ROOT=${IDHUB_MEDIA_ROOT:-/media/}
- PORT=${IDHUB_PORT:-9001}
- DEFAULT_FROM_EMAIL=${IDHUB_DEFAULT_FROM_EMAIL}
- EMAIL_HOST=${IDHUB_EMAIL_HOST}
- EMAIL_HOST_USER=${IDHUB_EMAIL_HOST_USER}
- EMAIL_HOST_PASSWORD=${IDHUB_EMAIL_HOST_PASSWORD}
- EMAIL_PORT=${IDHUB_EMAIL_PORT}
- EMAIL_USE_TLS=${IDHUB_EMAIL_USE_TLS}
- EMAIL_BACKEND=${IDHUB_EMAIL_BACKEND}
- SUPPORTED_CREDENTIALS=['Snapshot']
- SYNC_ORG_DEV=${IDHUB_SYNC_ORG_DEV}
ports:
- 9001:9001
# TODO add database service for idhub, meanwhile sqlite

View file

@ -19,12 +19,24 @@ main() {
cp -v .env.example .env cp -v .env.example .env
echo "WARNING: .env was not there, .env.example was copied, this only happens once" echo "WARNING: .env was not there, .env.example was copied, this only happens once"
fi fi
# load vars
. ./.env
if [ "${IDHUB_ENABLED:-}" = 'true' ]; then
export COMPOSE_PROFILES='idhub'
fi
# remove old database # remove old database
rm -vfr ./db/* rm -vfr ./db/*
# deactivate configured flag # deactivate configured flag
rm -vfr ./already_configured rm -vfr ./already_configured
docker compose down -v docker compose down -v
if [ "${DEV_DOCKER_ALWAYS_BUILD:-}" = 'true' ]; then
docker compose pull --ignore-buildable
docker compose build docker compose build
else
docker compose pull
fi
docker compose up ${detach_arg:-} docker compose up ${detach_arg:-}
} }

View file

@ -6,6 +6,7 @@ RUN apt update && \
python3-xapian \ python3-xapian \
git \ git \
sqlite3 \ sqlite3 \
curl \
jq \ jq \
time \ time \
vim \ vim \
@ -37,6 +38,7 @@ RUN pip install -i https://test.pypi.org/simple/ ereuseapitest==0.0.14
# Set PYTHONPATH to include the directory with the xapian module # Set PYTHONPATH to include the directory with the xapian module
ENV PYTHONPATH="${PYTHONPATH}:/usr/lib/python3/dist-packages" ENV PYTHONPATH="${PYTHONPATH}:/usr/lib/python3/dist-packages"
COPY . .
COPY docker/devicehub-django.entrypoint.sh / COPY docker/devicehub-django.entrypoint.sh /
RUN chown -R app:app /opt/devicehub-django RUN chown -R app:app /opt/devicehub-django

View file

@ -118,6 +118,51 @@ END
./manage.py dlt_register_user "${DATASET_FILE}" ./manage.py dlt_register_user "${DATASET_FILE}"
} }
# wait until idhub api is prepared to received requests
wait_idhub() {
echo "Start waiting idhub API"
while true; do
result="$(curl -s "${url}" \
| jq -r .error \
|| echo "Reported errors, idhub API is still not ready")"
if [ "${result}" = "Invalid request method" ]; then
break
sleep 2
else
echo "Waiting idhub API"
sleep 3
fi
done
}
demo__send_to_sign_credential() {
filepath="${1}"
# hashlib.sha3_256 of PREDEFINED_TOKEN for idhub
DEMO_IDHUB_PREDEFINED_TOKEN="${DEMO_IDHUB_PREDEFINED_TOKEN:-}"
auth_header="Authorization: Bearer ${DEMO_IDHUB_PREDEFINED_TOKEN}"
json_header='Content-Type: application/json'
curl -s -X POST \
-H "${json_header}" \
-H "${auth_header}" \
-d @"${filepath}" \
"${url}" \
| jq -r .data
}
run_demo() {
if [ "${DEMO_IDHUB_DOMAIN:-}" ]; then
DEMO_IDHUB_DOMAIN="${DEMO_IDHUB_DOMAIN:-}"
# this demo only works with FQDN domain (with no ports)
url="https://${DEMO_IDHUB_DOMAIN}/webhook/sign/"
wait_idhub
demo__send_to_sign_credential \
'example/demo-snapshots-vc/snapshot_pre-verifiable-credential.json' \
> 'example/snapshots/snapshot_workbench-script_verifiable-credential.json'
fi
/usr/bin/time ./manage.py up_snapshots example/snapshots/ "${INIT_USER}"
}
config_phase() { config_phase() {
# TODO review this flag file # TODO review this flag file
init_flagfile="${program_dir}/already_configured" init_flagfile="${program_dir}/already_configured"
@ -132,7 +177,7 @@ config_phase() {
# 12, 13, 14 # 12, 13, 14
config_dpp_part1 config_dpp_part1
# cleanup other spnapshots and copy dlt/dpp snapshots # cleanup other snapshots and copy dlt/dpp snapshots
# TODO make this better # TODO make this better
rm example/snapshots/* rm example/snapshots/*
cp example/dpp-snapshots/*.json example/snapshots/ cp example/dpp-snapshots/*.json example/snapshots/
@ -140,7 +185,7 @@ config_phase() {
# # 15. Add inventory snapshots for user "${INIT_USER}". # # 15. Add inventory snapshots for user "${INIT_USER}".
if [ "${DEMO:-}" = 'true' ]; then if [ "${DEMO:-}" = 'true' ]; then
/usr/bin/time ./manage.py up_snapshots example/snapshots/ "${INIT_USER}" run_demo
fi fi
# remain next command as the last operation for this if conditional # remain next command as the last operation for this if conditional

View file

@ -206,3 +206,14 @@ class Evidence:
def is_web_snapshot(self): def is_web_snapshot(self):
return self.doc.get("type") == "WebSnapshot" return self.doc.get("type") == "WebSnapshot"
def did_document(self):
if not self.doc.get("credentialSubject"):
return ''
did = self.doc.get('issuer')
if not "did:web" in did:
return ''
return "https://{}/did.json".format(
did.split("did:web:")[1].replace(":", "/")
)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long