Cette page a été traduite par une machine et n'a pas encore été révisée par une personne. L'anglais est la référence ; les corrections sont les bienvenues sur GitHub. GitHub
Cookwala / SDK et scénarios / 083
An insurer receives a device fault summary and nothing about the home
The insurer role may receive one constraint type, a summary of device faults by category, and only when the household names an insurer. The example household has no fault facet, so the insurer receives an empty list; a fault facet alone shows what the summary is derived from.
Lire d'abord: /docs/HOUSEHOLD-CONTEXT/ /trust/
Étapes
Over the example household an insurer receives no constraints; every one of the twelve facets is withheld with a reason.
deriveConstraintsHealth facets are withheld as not allowed for the role; the firmware facet as not consented. No reason ever says what the value was.
A device-issues facet on its own derives the one type an insurer may receive: counts of faults by category, no times, no household facts.
deriveConstraints
Résultat
You know the exact scope of what an insurer can be offered under this profile, and that RFC-0001 lists the role as the first to be removed if a privacy review objects. Next: 084, two roles that receive nothing.
Ligne de commande
cookwala constraints examples/household/context.json --role insurer
jq '.roles.insurer' profiles/household/recipient-roles.jsonSortie enregistrée
Statut: ok
[1] deriveConstraints: {"constraints": [], "disclosed": [], "withheld": [{"facet": "cw.facet.household.health.allergies", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.diets", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.health.medications", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.people.schedule", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.space.environment.foot_traffic", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.household.pets.animals", "reason": "not_allowed_for_role"}, {"facet": "cw.facet.commerce.receiving_rules", "r…
[3] deriveConstraints: {"constraints": [{"type": "device_fault_summary", "derivedFrom": ["cw.facet.devices.issues"]}], "disclosed": [], "withheld": []}Code
Exécuter: python scenarios/out/083-insurer-receives-fault-summary-only/python.py
# Scenario 083: An insurer receives a device fault summary and nothing about the home
# The insurer role may receive one constraint type, a summary of device faults by category, and only when the household names an insurer. The example household has no fault facet, so the insurer receives an empty list; a fault facet alone shows what the summary is derived from.
# Run a hub first: python hub/cookwala_hub.py --recipes examples
import json, os
from cookwala.client import CookwalaClient, CookwalaProblem
def load(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
def pick(obj, path):
for part in path.replace("]", "").replace("[", ".").split("."):
obj = obj[int(part)] if part.isdigit() else (len(obj) if part == "length" else obj.get(part))
return obj
c = CookwalaClient(os.environ.get("COOKWALA_HUB", "http://localhost:7878"))
# Step 1: Over the example household an insurer receives no constraints; every one of the twelve facets is withheld with a reason.
insurer = c.derive_constraints(pick(load("examples/household/context.json"), "facets"), "insurer")
assert pick(insurer, "constraints.length") == 0, pick(insurer, "constraints.length")
print("ok", "constraints.length", "=", 0)
assert pick(insurer, "disclosed.length") == 0, pick(insurer, "disclosed.length")
print("ok", "disclosed.length", "=", 0)
assert pick(insurer, "withheld.length") == 12, pick(insurer, "withheld.length")
print("ok", "withheld.length", "=", 12)
# Step 2: Health facets are withheld as not allowed for the role; the firmware facet as not consented. No reason ever says what the value was.
assert pick(insurer, "withheld[0].facet") == "cw.facet.household.health.allergies", pick(insurer, "withheld[0].facet")
print("ok", "withheld[0].facet", "=", "cw.facet.household.health.allergies")
assert pick(insurer, "withheld[0].reason") == "not_allowed_for_role", pick(insurer, "withheld[0].reason")
print("ok", "withheld[0].reason", "=", "not_allowed_for_role")
assert pick(insurer, "withheld[2].facet") == "cw.facet.household.health.medications", pick(insurer, "withheld[2].facet")
print("ok", "withheld[2].facet", "=", "cw.facet.household.health.medications")
assert pick(insurer, "withheld[2].reason") == "not_allowed_for_role", pick(insurer, "withheld[2].reason")
print("ok", "withheld[2].reason", "=", "not_allowed_for_role")
assert pick(insurer, "withheld[10].reason") == "no_consent", pick(insurer, "withheld[10].reason")
print("ok", "withheld[10].reason", "=", "no_consent")
# Step 3: A device-issues facet on its own derives the one type an insurer may receive: counts of faults by category, no times, no household facts.
faults = c.derive_constraints([{"facet": "cw.facet.devices.issues"}], "insurer")
assert pick(faults, "constraints.length") == 1, pick(faults, "constraints.length")
print("ok", "constraints.length", "=", 1)
assert pick(faults, "constraints[0].type") == "device_fault_summary", pick(faults, "constraints[0].type")
print("ok", "constraints[0].type", "=", "device_fault_summary")
assert pick(faults, "constraints[0].derivedFrom") == ["cw.facet.devices.issues"], pick(faults, "constraints[0].derivedFrom")
print("ok", "constraints[0].derivedFrom", "=", ["cw.facet.devices.issues"])
print("scenario complete")